-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
69 lines (64 loc) · 1.51 KB
/
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
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
const esbuild = require('esbuild');
const contents = `
const head = document.head || document.getElementsByTagName('head')[0];
const style = document.createElement('style');
style.type = 'text/css';
head.appendChild(style);
`;
async function build_path() {
await esbuild.build({
entryPoints: ['./index.js'],
bundle: true,
outfile: 'dist/resolve-with-path.js',
plugins: [{
name: 'plugin',
setup(build) {
build.onResolve({ filter: /.*/ }, args => {
const id = require.resolve(args.path, args.resolveDir || __dirname);
return {
path: id,
sideEffects: false,
}
});
build.onLoad({ filter: /.*/ }, args => {
if (/\.css/.test(args.path)) {
return {
contents,
loader: 'js'
}
}
})
}
}]
});
}
async function build_without_path() {
await esbuild.build({
entryPoints: ['./index.js'],
bundle: true,
outfile: 'dist/resolve-without-path.js',
plugins: [{
name: 'plugin',
setup(build) {
build.onResolve({ filter: /.*/ }, args => {
return {
sideEffects: false,
}
});
build.onLoad({ filter: /.*/ }, args => {
if (/\.css/.test(args.path)) {
return {
contents,
loader: 'js'
}
}
})
}
}]
});
}
async function main() {
await build_path();
await build_without_path();
}
main();