-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.config.js
53 lines (46 loc) · 1.8 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
import esbuild from 'esbuild';
import { sassPlugin } from 'esbuild-sass-plugin';
import fs from 'fs';
const isProduction = process.env.ENVIRONMENT === 'production';
const build = async (shouldWatch) => {
const buildOptions = {
plugins: [
sassPlugin({
quietDeps: true,
}),
],
entryPoints: [
'app/static/src/js/app-bundle.js',
'app/static/src/scss/styles.scss',
],
bundle: true,
entryNames: '[name]-[hash].min', // Output filenames with hashed names
outdir: 'app/static/dist', // Output directory
format: 'esm', // Outputs as ES Module
minify: true, // Minify JS and CSS
sourcemap: true, // Generates source maps
external: ['/assets/*'], // External paths
logLevel: 'info', // Logging level
metafile: true, // Enables output metadata
};
try {
const result = await esbuild.build(buildOptions);
// Generate manifest.json mapping original names to hashed names
const manifest = {};
for (const [outputPath, outputInfo] of Object.entries(result.metafile.outputs)) {
const fileName = outputPath.split('/').pop();
if (outputInfo.entryPoint) {
const originalName = outputInfo.entryPoint.split('/').pop();
manifest[originalName] = fileName;
}
}
// Write the manifest.json to the output directory
fs.writeFileSync('app/static/dist/manifest.json', JSON.stringify(manifest, null, 2));
console.log('Manifest generated:', manifest);
} catch (error) {
console.error('Build failed:', error);
process.exit(1); // Exit with failure code
}
};
const shouldWatch = process.argv.includes('--watch');
build(shouldWatch);