-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.js
47 lines (41 loc) · 1.34 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
/* eslint-disable */
import { spawnSync } from 'child_process';
import { writeFileSync, readFileSync } from 'fs'
import esbuild from "esbuild";
import esbuildSvelte from "esbuild-svelte";
import sveltePreprocess from "svelte-preprocess";
import { extheader } from './extheader.js';
let res = spawnSync("git", ["rev-list", "--count", "HEAD"]);
let rev = +res.stdout;
(async () => {
let res;
res = await esbuild
.build({
entryPoints: ["src/main.ts"],
bundle: true,
treeShaking: true,
outfile: "./dist/main.js",
define: {
global: 'window',
execution_mode: JSON.stringify(process.argv[2] || 'userscript'),
isBackground: JSON.stringify('false'),
BUILD_VERSION: JSON.stringify([0, rev])
},
inject: ['./esbuild.inject.js'],
plugins: [
esbuildSvelte({
compilerOptions: { css: true, accessors: true },
preprocess: sveltePreprocess(),
})
],
loader: {
'.css': 'text',
'.png': 'binary'
},
metafile: true
})
console.log(res.metafile.inputs);
console.log(Object.entries(res.metafile.inputs).sort((a, b) => a[1].bytes - b[1].bytes).map(e => `${e[0]} -> ${e[1].bytes}`).join('\n'));
writeFileSync('./main.user.js', extheader + readFileSync('./dist/main.js'));
writeFileSync('./main.meta.js', extheader);
})();