forked from platers/obsidian-linter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.config.mjs
72 lines (63 loc) · 2.03 KB
/
esbuild.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import esbuild from 'esbuild';
import process from 'process';
import builtins from 'builtin-modules';
import importGlobPlugin from 'esbuild-plugin-import-glob';
import {replace} from 'esbuild-plugin-replace';
const banner =
`/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;
const dummyMocksForDocs = `
document = {
createElement: function() {},
};
`;
const prod = (process.argv[2] === 'production');
const mockedBanner = banner + dummyMocksForDocs;
const mockedPlugins = [replace({
values: {
// update usage of moment from obsidian to the node implementation of moment we have
'import {moment} from \'obsidian\';': 'import moment from \'moment\';',
// remove the use of obsidian in the options to allow for docs.js to run
'import {Setting} from \'obsidian\';': '',
// remove the use of obsidian in settings helper to allow for docs.js to run
'import {Component, MarkdownRenderer} from \'obsidian\';': '',
},
delimiters: ['', ''],
})];
const createEsbuildArgs = function(banner, entryPoint, outfile, extraPlugins) {
return {
banner: {
js: banner,
},
entryPoints: [entryPoint],
plugins: [
importGlobPlugin.default(),
...extraPlugins,
],
bundle: true,
external: [
'obsidian',
...builtins],
format: 'cjs',
target: 'es2020',
sourcemap: prod ? false : 'inline',
minify: prod,
treeShaking: true,
outfile: outfile,
};
};
esbuild.build(
createEsbuildArgs(banner, 'src/main.ts', 'main.js', []),
).catch(() => process.exit(1));
esbuild.build(
createEsbuildArgs(mockedBanner, 'src/docs.ts', 'docs.js', mockedPlugins),
).catch(() => process.exit(1));
esbuild.build(
createEsbuildArgs(mockedBanner, 'src/translation-helper.ts', 'translation-helper.js', mockedPlugins),
).catch(() => process.exit(1));
esbuild.build(
createEsbuildArgs(banner, '__integration__/main.test.ts', 'test-vault/.obsidian/plugins/obsidian-linter/main.js', []),
).catch(() => process.exit(1));