forked from CircuitVerse/CircuitVerse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.config.js
56 lines (50 loc) · 1.7 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
const path = require('path');
const esbuild = require('esbuild');
const rails = require('esbuild-rails');
const sassPlugin = require('esbuild-plugin-sass');
const watchDirectories = [
'./app/javascript/**/*.js',
'./app/views/**/*.html.erb',
'./app/assets/stylesheets/**/*',
];
const watch = process.argv.includes('--watch');
const watchPlugin = {
name: 'watchPlugin',
setup(build) {
build.onStart(() => {
// eslint-disable-next-line no-console
console.log(`Build starting: ${new Date(Date.now()).toLocaleString()}`);
});
build.onEnd((result) => {
if (result.errors.length > 0) {
// eslint-disable-next-line no-console
console.error(`Build finished, with errors: ${new Date(Date.now()).toLocaleString()}`);
} else {
// eslint-disable-next-line no-console
console.log(`Build finished successfully: ${new Date(Date.now()).toLocaleString()}`);
}
});
},
};
async function run() {
const context = await esbuild.context({
entryPoints: ['application.js', 'simulator.js', 'testbench.js'],
bundle: true,
outdir: path.join(process.cwd(), 'app/assets/builds'),
absWorkingDir: path.join(process.cwd(), 'app/javascript'),
sourcemap: 'inline',
loader: {
'.png': 'file', '.svg': 'file', '.ttf': 'file', '.woff': 'file', '.woff2': 'file', '.eot': 'file',
},
plugins: [rails(), sassPlugin(), watchPlugin],
});
if (watch) {
await context.watch();
} else {
await context.rebuild();
context.dispose();
}
}
run().catch(() => {
process.exit(1);
});