-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
39 lines (36 loc) · 967 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
33
34
35
36
37
38
39
const fs = require('fs');
const path = require('path');
const {version} = require('./package.json');
function getAllCases(dir = 'src') {
const ret = [];
fs.readdirSync(dir).forEach((filename) => {
if(filename.endsWith('.js')) {
ret.push(path.join(dir, filename));
}
});
return ret;
}
const options = {
entryPoints: getAllCases(),
outdir: 'dist',
bundle: true,
loader: {
'.md': 'text',
'.css': 'text',
},
define: {
VERSION: `"${version}"`,
},
};
if(process.env.mode === 'production') {
require('esbuild').buildSync({minify: true, ...options});
} else {
require('esbuild').serve({
servedir: '.',
}, options).then((server) => {
console.log(`Server is running at ${server.host}:${server.port}`);
const scriptURL = `http://localhost:${server.port}/${options.outdir}`;
console.log(`打开 https://code.juejin.cn
设置 ${scriptURL}/<case文件名> 到 script 依赖资源,进行调试。`);
});
}