UNPKG

igroot-builder

Version:

白山——zeus系统前端打包工具

39 lines (31 loc) 1.31 kB
const webpack = require('webpack') const webpackDevServer = require('webpack-dev-server') const chalk = require('chalk') const serverConfig = require('../config/webpack-dev-server.config') const { options: { port, host, domain } } = require('../bsy') const notify = require('../notify') const { IPv4 } = require('../utils') const getUrl = host => `http://${host}:${port}/` const url = getUrl(domain) module.exports = function(args, collect = () => {}) { collect({}, true) process.env.NODE_ENV = 'development' notify.info('Dev server starting...') const config = require('../config/webpack.dev') const compiler = webpack(config) const devServer = new webpackDevServer(compiler, serverConfig) devServer.listen(port, host, err => { if (err) return console.log(err) notify.success('Starting the development server...') console.log('> You can now open it in the browser.\n') console.log(chalk.bold(' Local:\t') + chalk.cyan(url)) IPv4.forEach((ip, i) => console.log(` ${ chalk.bold(i === 0 ? 'Your Network:' : '\t') }\t${ chalk.cyan(getUrl(ip))}`)) // 绝对不能配置 webpack() 的 callback!!! 亲历有巨坑!! }); ['SIGINT', 'SIGTERM'].forEach(function(sig) { process.on(sig, function() { devServer.close() process.exit() }) }) }