Skip to content

Commit

Permalink
add hmr in webpack config for client
Browse files Browse the repository at this point in the history
  • Loading branch information
bdefore committed Dec 21, 2015
1 parent 2e2901b commit b7dbf12
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
14 changes: 9 additions & 5 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
"stage-0",
"react"
],
"plugins": [
[ "transform-runtime" ],
[ "typecheck" ],
[ "transform-decorators-legacy" ]
],
"env": {
"development": {
"plugins": [
[ "transform-runtime" ],
[ "typecheck" ],
[ "transform-decorators-legacy" ]
]
"plugins": []
},
"production": {
"plugins": []
}
}
}
34 changes: 31 additions & 3 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,39 @@ var CleanPlugin = require('clean-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var strip = require('strip-loader');

var babelConfig = 'babel-loader?presets[]=es2015,presets[]=stage-0,presets[]=react,plugins[]=transform-runtime,plugins[]=transform-decorators-legacy'
var babelrc = fs.readFileSync(path.resolve(__dirname, '..', './.babelrc'));
var babelrcObject = {};

try {
babelrcObject = JSON.parse(babelrc);
} catch (err) {
console.error('==> ERROR: Error parsing your .babelrc.');
console.error(err);
}

if (process.env.NODE_ENV !== 'production') {
var jsLoaders = [babelConfig];

var hmrConfig = [
"react-transform", {
"transforms": [
{
"transform": "react-transform-hmr",
"imports": ["react"],
"locals": ["module"]
},
{
"transform": "react-transform-catch-errors",
"imports": ["react", "redbox-react"]
}
]
}
]

babelrcObject.env.development.plugins.unshift(hmrConfig);

var jsLoaders = ['babel-loader?' + JSON.stringify(babelrcObject)];
} else {
var jsLoaders = [strip.loader('debug'), babelConfig];
var jsLoaders = [strip.loader('debug'), 'babel-loader?' + JSON.stringify(babelrcObject)];
}

module.exports = {
Expand Down

0 comments on commit b7dbf12

Please sign in to comment.