-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (37 loc) · 1.04 KB
/
app.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
import { spawn } from 'node:child_process';
import webpack from 'webpack';
import config from './webpack.config.cjs';
/**
* 针对 Serverless 服务的入口文件
* 1. 通过 Webpack 打包 `production` 环境的代码
* 2. 运行 `dist-serverless/main.cjs`
*/
async function main() {
process.env.WEBPACK_BUILD_ENV = 'serverless';
const compiler = webpack(config());
compiler.run((err, stats) => {
if (err) {
console.error(err);
return;
}
console.log(
stats.toString({
colors: true,
modules: false,
children: false,
chunks: false,
chunkModules: false,
entrypoints: false,
}),
);
const child = spawn('node', ['dist-serverless/main.cjs'], {
stdio: 'inherit',
});
child.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
});
}
main().catch((err) => {
console.error(err);
});