-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathesbuild.config.js
79 lines (69 loc) · 2.58 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
76
77
const esbuild = require('esbuild');
const {generateManifestPlugin} = require("./config/esbuild/plugins/generateManifestPlugin");
const {copyStaticFilesPlugin} = require("./config/esbuild/plugins/copyStaticFilesPlugin");
const {cleanDirectoryPlugin} = require("./config/esbuild/plugins/cleanDirectoryPlugin");
const {watchStatic} = require("./config/esbuild/watchStatic");
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 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),
copyStaticFilesPlugin(['public', 'LICENSE']),
],
};
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);
// --- No way to list the output files from `watch` mode ---
// await ctx.rebuild().then(result => {
// if (result.errors.length > 0) {
// console.error('Build failed with errors:');
// console.error(result.errors);
// } else {
// console.log('Build succeeded:');
// // Comme `result.outputFiles` n'est pas disponible, vous pouvez simplement afficher un message ou d'autres informations.
// // Pour obtenir les fichiers générés, vous devrez le faire manuellement car `result` ne contient pas directement `outputFiles`.
// // Par exemple, vous pouvez afficher les fichiers sortis de `outdir`.
// console.log('Output files:');
// result.outputFiles?.forEach(file => {
// console.log(` ${file.path} ${file.contents.length} bytes`);
// });
// }
// });
}