forked from noatpad/obsidian-banners
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.config.ts
87 lines (82 loc) · 2.34 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
79
80
81
82
83
84
85
86
87
/* 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 { sassPlugin } from 'esbuild-sass-plugin';
import esbuildSvelte from 'esbuild-svelte';
// @ts-ignore
import mergeFiles from 'merge-files';
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 () => {
// Merge Svelte stylesheets and styles.scss
await mergeFiles([`${outdir}/styles.css`, `${outdir}/main.css`], `${outdir}/merged.css`);
await fs.rename(`${outdir}/merged.css`, `${outdir}/styles.css`);
await fs.rm(`${outdir}/main.css`, { force: true });
await fs.rm(`${outdir}/merged.css`, { force: true });
// Move static files to output folder
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', 'src/styles.scss'],
bundle: true,
plugins: [
esbuildSvelte({
compilerOptions: { css: 'external' },
preprocess: sveltePreprocess()
}),
sassPlugin(),
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();
}