-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathesbuild.config.js
77 lines (68 loc) · 1.95 KB
/
esbuild.config.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
73
74
75
const esbuild = require('esbuild');
const {generateManifestPlugin} = require("./config/esbuild/plugins/generateManifestPlugin");
const {cleanDirectoryPlugin} = require("./config/esbuild/plugins/cleanDirectoryPlugin");
const {watchStatic} = require("./config/esbuild/watchStatic");
const pugPlugin = require('./config/esbuild/plugins/pugPlugin');
const {copy} = require('esbuild-plugin-copy');
const outdir = 'dist';
const targetBrowser = process.env.TARGET || 'chrome';
const appMode = process.env.APP_MODE || 'dev';
const appVersion = require('./package.json').version.toString();
const watchMode = process.env.WATCH_MODE || false; // Flag for watch mode
const staticAssetsConfig = [
{
from: 'public/**/*',
to: './',
},
{
from: ['./LICENSE'],
to: ['./'],
}
];
const options = {
entryPoints: ['src/entrypoints/background.ts', "src/entrypoints/tab.ts", 'src/entrypoints/pages.ts', 'src/entrypoints/options.html'],
bundle: true,
outdir: outdir,
minify: false,
sourcemap: false,
platform: 'browser',
target: ['chrome89', 'firefox89'],
format: 'iife',
logLevel: 'info',
loader: {
'.ts': 'ts',
'.html': 'copy'
},
entryNames: '[name]',
define: {
'APP_MODE': `"${appMode}"`,
'APP_TARGET': `"${targetBrowser}"`,
'APP_VERSION': `"${appVersion}"`,
},
plugins: [
cleanDirectoryPlugin(outdir),
generateManifestPlugin(targetBrowser),
copy({
assets: staticAssetsConfig,
watch: true,
}),
pugPlugin,
],
};
const job = watchMode ? watch : build;
job().catch((error) => {
console.error('Build failed:', error);
console.error('Stack Trace:', error.stack);
process.exit(1);
});
async function build() {
await esbuild.build(options);
console.log('Build completed successfully');
}
async function watch() {
const ctx = await esbuild.context(options);
await ctx.watch();
console.log('Watching for file changes...');
// Watch for changes in the 'public' folder
watchStatic(ctx);
}