UNPKG

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