-
Notifications
You must be signed in to change notification settings - Fork 4
/
esbuild.watch.config.js
47 lines (43 loc) · 1.29 KB
/
esbuild.watch.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
import path from 'path';
import fs from 'fs';
import solid from 'babel-preset-solid';
import { context } from 'esbuild';
import { transformAsync } from '@babel/core';
function solidPlugin() {
return {
name: 'esbuild:solid',
setup(build) {
build.onLoad({ filter: /\.(t|j)sx$/ }, async (args) => {
const source = await fs.readFileSync(args.path, { encoding: 'utf-8' });
const filename = args.path.split('/').pop();
const result = await transformAsync(source, {
presets: [
[solid, {}]
],
filename,
sourceMaps: 'inline',
...{}
});
if (!result || result.code === void 0 || result.code === null) {
throw new Error('No result was provided from Babel');
}
return { contents: result.code, loader: 'js' };
});
}
}
}
async function build() {
let ctx = await context({
entryPoints: [path.join(process.cwd(), 'app/javascript/application.jsx')],
bundle: true,
minify: true,
sourcemap: true,
outdir: path.join(process.cwd(), 'app/assets/builds'),
absWorkingDir: path.join(process.cwd(), 'app/javascript'),
target: 'es2016',
plugins: [solidPlugin()],
}).catch(() => process.exit(1))
await ctx.watch()
console.log('watching...')
}
build();