-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-ui.js
104 lines (93 loc) · 2.55 KB
/
build-ui.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// noinspection JSUnusedLocalSymbols
const esbuild = require("esbuild");
const vuePlugin = require("esbuild-plugin-vue3");
const {copy} = require("esbuild-plugin-copy");
const commandLineArgs = require('command-line-args');
const {sassPlugin} = require("esbuild-sass-plugin");
const fs = require('fs');
const path = require('path');
const SVGSpriter = require('svg-sprite');
const {glob} = require('glob');
/**
* @typedef {{
* watch: boolean,
* }} BuildOptions
*/
/**
* @type {BuildOptions}
*/
const options = commandLineArgs([
{name: 'watch', alias: 'w', type: Boolean, defaultOption: false},
{name: 'buildver', type: String, defaultValue: 'latest'},
]);
(async () => {
const ctx = await esbuild.context({
entryPoints: [
"ui/app.ts",
],
bundle: true,
outdir: "ui-public",
external: ["assets"],
plugins: [
vuePlugin({
generateHTML: "ui/index.html",
}),
copy({
resolveFrom: 'cwd',
assets: {
from: ['./ui/static/*'],
to: ['./ui-public'],
},
watch: true,
}),
copy({
resolveFrom: 'cwd',
assets: {
from: ['./ui/assets/**/*'],
to: ['./ui-public/assets'],
},
watch: true,
}),
sassPlugin({
filter: /\.scss$/,
quietDeps: true,
silenceDeprecations: ["legacy-js-api", "import"],
}),
],
loader: {
'.woff': 'file',
'.woff2': 'file',
},
define: {},
});
const spriter = new SVGSpriter({
log: false,
mode: {
symbol: {
inline: true
}
}
});
const svgs = await glob(__dirname + '/ui/svgs/**/*.svg');
svgs.forEach((svgPath) => {
spriter.add(
svgPath,
null,
fs.readFileSync(svgPath, 'utf-8')
);
});
const {result} = await spriter.compileAsync();
for (const mode in result) {
for (const resource in result[mode]) {
fs.mkdirSync('ui/assets/svg-sprite', {recursive: true});
fs.writeFileSync('ui/assets/svg-sprite/symbol.svg', result[mode][resource].contents);
}
}
if (options.watch) {
console.log('Watching...');
await ctx.watch();
} else {
await ctx.rebuild();
process.exit();
}
})();