-
Notifications
You must be signed in to change notification settings - Fork 42
/
esbuild.config.ts
78 lines (73 loc) · 1.9 KB
/
esbuild.config.ts
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
73
74
75
76
77
78
/* eslint-disable @typescript-eslint/ban-ts-comment */
import 'dotenv/config';
import fs from 'fs/promises';
import builtins from 'builtin-modules';
// @ts-ignore
import copyNewer from 'copy-newer';
import esbuild from 'esbuild';
import esbuildSvelte from 'esbuild-svelte';
import sveltePreprocess from 'svelte-preprocess';
const BANNER = `/*
- THIS IS A GENERATED/BUNDLED FILE BY ESBUILD -
Please visit the repository linked to view the source code:
https://github.com/noatpad/obsidian-banners
*/`;
const prod = (process.argv[2] === 'prod');
const outdir = 'dist';
const obsimove: esbuild.Plugin = {
name: 'obsimove',
setup(build) {
build.onEnd(async () => {
await fs.rename(`${outdir}/main.css`, `${outdir}/styles.css`);
await fs.copyFile('manifest.json', `${outdir}/manifest.json`);
await fs.writeFile(`${outdir}/.hotreload`, '');
// Copy to dev vault if needed
if (!prod && process.env.DEVDIR) {
copyNewer('{.*,**}', process.env.DEVDIR, { cwd: outdir });
}
});
}
};
// eslint-disable-next-line import/no-named-as-default-member
const context = await esbuild.context({
banner: { js: BANNER },
entryPoints: ['src/main.ts'],
bundle: true,
plugins: [
esbuildSvelte({
compilerOptions: { css: 'external' },
preprocess: sveltePreprocess()
}),
obsimove
],
external: [
'obsidian',
'electron',
'@codemirror/autocomplete',
'@codemirror/collab',
'@codemirror/commands',
'@codemirror/language',
'@codemirror/lint',
'@codemirror/search',
'@codemirror/state',
'@codemirror/view',
'@lezer/common',
'@lezer/highlight',
'@lezer/lr',
...builtins
],
format: 'cjs',
target: 'es2020',
treeShaking: true,
minify: prod,
sourcemap: prod ? false : 'inline',
color: true,
outdir,
logLevel: 'info'
});
if (prod) {
await context.rebuild();
process.exit(0);
} else {
await context.watch();
}