1 Star 0 Fork 246

yiane / xuanxuan

forked from easysoft / xuanxuan 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
server.js 1.62 KB
一键复制 编辑 原始数据 按行查看 历史
Catouse 提交于 2017-09-28 09:37 . * support build for browser.
/* eslint-disable no-console */
/**
* Setup and run the development server for Hot-Module-Replacement
* https://webpack.github.io/docs/hot-module-replacement-with-webpack.html
*/
import express from 'express';
import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import { spawn } from 'child_process';
import electronConfig from './webpack.config.development';
import browserConfig from './webpack.config.browser.development';
const argv = require('minimist')(process.argv.slice(2));
const isBrowserTarget = argv['target'] === 'browser';
if(isBrowserTarget) {
console.log('Server for browser target.');
}
const config = isBrowserTarget ? browserConfig : electronConfig;
const app = express();
const compiler = webpack(config);
const PORT = process.env.PORT || 3000;
const wdm = webpackDevMiddleware(compiler, {
publicPath: config.output.publicPath,
stats: {
colors: true
}
});
app.use(wdm);
app.use(webpackHotMiddleware(compiler));
const server = app.listen(PORT, 'localhost', serverError => {
if (serverError) {
return console.error(serverError);
}
if (argv['start-hot']) {
spawn('npm', ['run', 'start-hot'], { shell: true, env: process.env, stdio: 'inherit' })
.on('close', code => process.exit(code))
.on('error', spawnError => console.error(spawnError));
}
console.log(`Listening at http://localhost:${PORT}`);
});
process.on('SIGTERM', () => {
console.log('Stopping dev server');
wdm.close();
server.close(() => {
process.exit(0);
});
});
NodeJS
1
https://gitee.com/yiane/xuanxuan.git
git@gitee.com:yiane/xuanxuan.git
yiane
xuanxuan
xuanxuan
master

搜索帮助