Skip to content

Commit

Permalink
Add hot-middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Feb 11, 2016
1 parent 949f6f1 commit 4c21a1a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
39 changes: 23 additions & 16 deletions nico.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 6 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -20,6 +20,7 @@ module.exports = {

output: {
path: path.join(process.cwd(), 'dist'),
publicPath: '/dist/',
filename: '[name].js'
},

Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 4c21a1a

Please sign in to comment.