From 900dac850ebd48b8228b3d9c660d7231a8a6f5a8 Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Fri, 8 Jan 2016 15:14:11 +0200 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BA=D0=BB=D1=8E=D1=87=D0=B8=D0=BB=20HM?= =?UTF-8?q?R?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + webpack.config.js | 31 ++++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 321f5dc..3376cfd 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "babel-plugin-transform-runtime": "^6.3.13", "babel-preset-es2015": "^6.3.13", "babel-preset-react": "^6.3.13", + "babel-preset-react-hmre": "^1.0.1", "babel-preset-stage-0": "^6.3.13", "babel-runtime": "^5.6.15", "chai": "^3.0.0", diff --git a/webpack.config.js b/webpack.config.js index 6ad1215..0cde667 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -10,10 +10,15 @@ var iconfontImporter = require('./webpack/node-sass-iconfont-importer'); const API_HOST = 'http://account.l'; -// TODO: https://babeljs.io/docs/plugins/ -// TODO: отдельные конфиги для env (аля https://github.com/davezuko/react-redux-starter-kit) -// https://github.com/glenjamin/ultimate-hot-reloading-example ( обратить внимание на плагины babel ) -// https://github.com/gajus/react-css-modules ( + BrowserSync) +/** + * TODO: https://babeljs.io/docs/plugins/ + * TODO: отдельные конфиги для env (аля https://github.com/davezuko/react-redux-starter-kit) + * https://github.com/glenjamin/ultimate-hot-reloading-example ( обратить внимание на плагины babel ) + * https://github.com/gajus/react-css-modules ( + BrowserSync) + * + * Inspiration projects: + * https://github.com/davezuko/react-redux-starter-kit + */ var isProduction = process.argv.some(function(arg) { return arg === '-p'; @@ -69,7 +74,7 @@ var webpackConfig = { new iconfontImporter.Plugin(), new webpack.DefinePlugin({ 'process.env': { - NODE_ENV: JSON.stringify(isProduction ? 'production' : 'dev') + NODE_ENV: JSON.stringify(isProduction ? 'production' : 'development') }, __DEV__: !isProduction, __TEST__: isTest, @@ -105,7 +110,12 @@ var webpackConfig = { loader: 'babel', query: { presets: ['react', 'es2015', 'stage-0'], - plugins: ['transform-runtime', ['react-intl', {messagesDir: './dist/messages/'}]] + plugins: ['transform-runtime', ['react-intl', {messagesDir: './dist/messages/'}]], + env: { + development: { + presets: ['react-hmre'] + } + } } } ] @@ -136,7 +146,7 @@ var webpackConfig = { if (isProduction) { - webpackConfig.module.loaders.forEach(function(loader) { + webpackConfig.module.loaders.forEach((loader) => { if (loader.extractInProduction) { var parts = loader.loader.split('!'); loader.loader = ExtractTextPlugin.extract(parts[0], parts.slice(1).join('!')); @@ -150,4 +160,11 @@ if (isProduction) { webpackConfig.devtool = false; } +if (!isProduction && !isTest) { + webpackConfig.plugins.push( + new webpack.HotModuleReplacementPlugin(), + new webpack.NoErrorsPlugin() + ); +} + module.exports = webpackConfig;