1 | #! /usr/bin/env node
|
2 | const webpack = require('webpack')
|
3 | const defaultConfig = require('../config/webpack.config')
|
4 | const path = require('path')
|
5 | const fs = require('fs')
|
6 |
|
7 | process.on('SIGINT', process.exit)
|
8 |
|
9 | const options = {
|
10 | env: 'production'
|
11 | }
|
12 |
|
13 | const configPath = path.resolve('backpack.config.js')
|
14 | let userConfig = {}
|
15 |
|
16 | if (fs.existsSync(configPath)) {
|
17 | const userConfigModule = require(configPath)
|
18 | userConfig = userConfigModule.default || userConfigModule
|
19 | }
|
20 |
|
21 | const serverConfig = userConfig.webpack
|
22 | ? userConfig.webpack(defaultConfig(options), options, webpack)
|
23 | : defaultConfig(options)
|
24 |
|
25 | process.on('SIGINT', process.exit)
|
26 |
|
27 | const serverCompiler = webpack(serverConfig)
|
28 |
|
29 | serverCompiler.run((error, stats) => {
|
30 | if (error || stats.hasErrors()) {
|
31 | process.exitCode = 1;
|
32 | }
|
33 | })
|