-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathesbuild.js
More file actions
56 lines (52 loc) · 1.5 KB
/
Copy pathesbuild.js
File metadata and controls
56 lines (52 loc) · 1.5 KB
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 fs = require('fs');
const path = require('path');
const { build } = require('esbuild');
const objectHasOwnPolyfill = require.resolve('core-js/actual/object/has-own');
!(async () => {
const pkg = JSON.parse(
await fs.promises.readFile(
'./src/sub/backend/package.json',
'utf8'
)
);
const version = pkg.version;
const mainVersion = JSON.parse(
fs.readFileSync(path.join(__dirname, 'package.json'), 'utf-8'),
).version.trim();
const dist = 'dist/_worker.js'
const artifacts = [
{ src: 'src/worker.js', dest: dist },
];
for await (const artifact of artifacts) {
await build({
entryPoints: [artifact.src],
bundle: true,
minify: true,
sourcemap: false,
platform: 'browser',
format: 'esm',
outfile: artifact.dest,
inject: [objectHasOwnPolyfill],
define: {
__VERSION__: `"${version}"`
}
});
fs.writeFileSync(
path.join(__dirname, dist),
`// SUB_STORE_NODE_VERSION: ${mainVersion}
${fs.readFileSync(path.join(__dirname, dist), {
encoding: 'utf8',
})}`,
{
encoding: 'utf8',
},
);
console.log(`✔️ 打包完成: ${artifact.src} → ${artifact.dest}`);
}
})()
.catch((e) => {
console.log(e);
})
.finally(() => {
console.log('done');
});