-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
32 lines (30 loc) · 795 Bytes
/
build.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
import esbuild from 'esbuild';
import { readFile } from 'fs/promises';
const plugin = {
name: 'css import assertions',
setup(build) {
build.onLoad({ filter: /\.css$/ }, async (args) => {
const css = await readFile(args.path, 'utf8');
const contents = `
const css = \`${css.replaceAll(/[`$]/gm, '\\$&')}\`;
let styles;
if ('adoptedStyleSheets' in document) {
styles = new CSSStyleSheet();
styles.replaceSync(css);
}
else {
styles = css;
}
export default styles;`;
return { contents };
});
}
}
esbuild.build({
entryPoints: ['src/index.js'],
sourcemap: true,
bundle: true,
minify: true,
plugins: [plugin],
outfile: 'public/index.js'
}).catch(() => process.exit(1));