UNPKG

1.16 kBJavaScriptView Raw
1// Do this as the first thing so that any code reading it knows the right env.
2process.env.BABEL_ENV = 'production';
3process.env.NODE_ENV = 'production';
4process.env.BROWSERSLIST_CONFIG = process.env.BROWSERSLIST_CONFIG || require.resolve('../../configs/.browserslistrc');
5
6/* eslint import/no-extraneous-dependencies: 0 */
7/* eslint no-console: 0 */
8const { spawn } = require('child_process');
9const fs = require('fs-extra');
10const path = require('path');
11
12const checkRequiredFiles = require('../util/check-required-files');
13const configs = require('../../configs/app-configs');
14
15if (!checkRequiredFiles()) {
16 process.exit(1);
17}
18
19if (fs.pathExistsSync(configs.serverOutputPath)) {
20 fs.removeSync(configs.serverOutputPath);
21}
22
23const compileServer = spawn('node', [path.join(__dirname, './server')], { stdio: 'inherit' });
24const compileClient = spawn('node', [path.join(__dirname, './client')], { stdio: 'inherit' });
25
26const onProcessExit = (code) => {
27 if (code !== 0) {
28 compileServer.kill();
29 compileClient.kill();
30 process.exit(code);
31 }
32};
33
34
35compileServer.on('close', onProcessExit);
36compileClient.on('close', onProcessExit);