Add hot-middleware

This commit is contained in:
afc163 2016-02-03 13:34:18 +08:00
parent 949f6f1a12
commit 4c21a1ac56
3 changed files with 32 additions and 20 deletions

39
nico.js
View File

@ -6,6 +6,7 @@ var inspect = require('util').inspect;
var Busboy = require('busboy');
var chalk = require('chalk');
var webpackMiddleware = require('webpack-dev-middleware');
var webpackHotMiddleware = require('webpack-hot-middleware');
var webpackConfig = require('./webpack.config');
var webpackCompiler = webpack(webpackConfig);
var handler;
@ -89,23 +90,29 @@ exports.middlewares = [
}
},
{
name: 'webpackDevMiddleware',
filter: /\.(js|css)(\.map)?(\?.*)?$/,
handle: function(req, res, next) {
handler = handler || webpackMiddleware(webpackCompiler, {
publicPath: '/dist/',
lazy: false,
watchOptions: {
aggregateTimeout: 300,
poll: false
},
noInfo: true
});
try {
return handler(req, res, next);
} catch(e) {}
name: 'webpackDevMiddleware',
filter: /\.(js|css|json)(\.map)?(\?.*)?$/,
handle: function(req, res, next) {
handler = handler || webpackMiddleware(webpackCompiler, {
publicPath: webpackConfig.output.publicPath,
lazy: false,
watchOptions: {
aggregateTimeout: 300,
poll: false
},
noInfo: true
});
try {
return handler(req, res, next);
} catch(e) {}
}
},
{
name: 'webpackHotMiddleware',
filter: /.*/,
handle: webpackHotMiddleware(webpackCompiler)
}
}];
];
exports.writers = [
'nico-jsx.PageWriter',

View File

@ -117,11 +117,12 @@
"values.js": "^1.0.3",
"webpack": "^1.10.1",
"webpack-babel-jest": "^1.0.0",
"webpack-dev-middleware": "^1.5.1"
"webpack-dev-middleware": "^1.5.1",
"webpack-hot-middleware": "^2.6.4"
},
"scripts": {
"babel": "babel components index.js --out-dir lib",
"start": "npm run clean && nico server --watch",
"start": "npm run clean && nico server",
"clean": "rm -rf _site dist",
"site": "npm run clean && webpack --config webpack.deploy.config.js && webpack --config webpack.antd.config.js && NODE_ENV=PRODUCTION nico build",
"deploy": "rm -rf node_modules && node scripts/install.js && npm run just-deploy",

View File

@ -4,7 +4,7 @@ var path = require('path');
var pkg = require('./package');
var entry = {};
entry['demo'] = './scripts/demo.js';
entry['demo'] = ['./scripts/demo.js', 'webpack-hot-middleware/client'];
module.exports = {
entry: entry,
@ -20,6 +20,7 @@ module.exports = {
output: {
path: path.join(process.cwd(), 'dist'),
publicPath: '/dist/',
filename: '[name].js'
},
@ -57,7 +58,10 @@ module.exports = {
},
plugins: [
new ExtractTextPlugin('[name].css')
new ExtractTextPlugin('[name].css'),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
devtool: 'source-map'