-
Notifications
You must be signed in to change notification settings - Fork 1
/
esbuild.js
72 lines (67 loc) · 1.5 KB
/
esbuild.js
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 path from 'node:path';
import dotenv from 'dotenv';
import { build, context } from 'esbuild';
import clear from 'esbuild-plugin-clear';
import { copy } from 'esbuild-plugin-copy';
import stylePlugin from 'esbuild-style-plugin';
import sveltePlugin from 'esbuild-svelte';
import { sveltePreprocess } from 'svelte-preprocess';
import yargs from 'yargs';
const { dev } = yargs(process.argv.slice(2)).argv;
dotenv.config();
const options = {
bundle: true,
entryPoints: [
'src/content/main.ts',
'src/devtools.ts',
'src/newtab/main.ts',
'src/panel/main.ts',
'src/popup/main.ts',
'src/widget/main.ts',
'src/worker.ts',
],
format: 'iife',
target: ['esnext'],
loader: {
'.gif': 'dataurl',
'.png': 'dataurl',
'.svg': 'text',
},
plugins: [
sveltePlugin({
preprocess: sveltePreprocess(),
}),
stylePlugin({
postcssConfigFile: path.resolve('./postcss.config.js'),
}),
copy({
assets: [
{
from: ['./src/static/*'],
to: ['./'],
},
],
}),
],
define: {
'process.env': JSON.stringify({
...process.env,
NODE_ENV: process.env.NODE_ENV ?? dev ? 'development' : 'production',
}),
},
logLevel: 'info',
outdir: 'dist',
treeShaking: true,
legalComments: 'none',
minify: !dev,
sourcemap: dev,
};
if (dev) {
const ctx = await context(options);
await ctx.watch();
} else {
await build({
...options,
plugins: options.plugins.concat(clear('./dist')),
});
}