diff --git a/templates/common/Gruntfile.js b/templates/common/Gruntfile.js index add91c7..36e9817 100644 --- a/templates/common/Gruntfile.js +++ b/templates/common/Gruntfile.js @@ -27,6 +27,7 @@ module.exports = function (grunt) { 'webpack-dev-server': { options: { + hot: true, port: 8000, webpack: webpackDevConfig, publicPath: '/assets/', diff --git a/templates/common/_package.json b/templates/common/_package.json index 587c1fa..3b8c387 100644 --- a/templates/common/_package.json +++ b/templates/common/_package.json @@ -35,6 +35,7 @@ "grunt-open": "~0.2.3", "jshint-loader": "~0.8.0", "grunt-contrib-copy": "~0.5.0", - "grunt-contrib-clean": "~0.6.0" + "grunt-contrib-clean": "~0.6.0", + "react-hot-loader": "^0.4.5" } } diff --git a/templates/common/root/webpack.config.js b/templates/common/root/webpack.config.js index 1235f53..4c69e48 100644 --- a/templates/common/root/webpack.config.js +++ b/templates/common/root/webpack.config.js @@ -6,6 +6,7 @@ */ 'use strict'; +var webpack = require('webpack'); module.exports = { @@ -17,7 +18,10 @@ module.exports = { cache: true, debug: true, devtool: false, - entry: './src/scripts/components/<%= pkg.mainInput %>.jsx', + entry: [ + 'webpack/hot/only-dev-server', + './src/scripts/components/<%= pkg.mainInput %>.jsx' + ], stats: { colors: true, @@ -37,7 +41,7 @@ module.exports = { loaders: [{ test: /\.jsx$/, - loader: 'jsx-loader?harmony' + loader: 'react-hot!jsx-loader?harmony' }, { test: /\.css$/, loader: 'style-loader!css-loader' @@ -45,6 +49,11 @@ module.exports = { test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192' }] - } + }, + + plugins: [ + new webpack.HotModuleReplacementPlugin(), + new webpack.NoErrorsPlugin() + ] }; diff --git a/test/test-creation.js b/test/test-creation.js index e9e589b..b006aa5 100644 --- a/test/test-creation.js +++ b/test/test-creation.js @@ -3,6 +3,7 @@ var path = require('path'); var helpers = require('yeoman-generator').test; +var assert = require('yeoman-generator').assert; var _ = require('underscore.string'); describe('react-webpack generator', function() { @@ -93,6 +94,20 @@ describe('react-webpack generator', function() { }); }); + it('should use HMR webpack API inside of configs', function (done) { + react.run({}, function() { + assert.fileContent([ + ['package.json', /react-hot-loader/], + ['Gruntfile.js', /hot:\s*true/], + ['webpack.config.js', /react-hot/], + ['webpack.config.js', /webpack\.HotModuleReplacementPlugin/], + ['webpack.config.js', /webpack\.NoErrorsPlugin/], + ['webpack.config.js', /webpack\/hot\/only-dev-server/] + ]); + done(); + }); + }); + }); describe('Subgenerators', function() {