From 23a747e50a989697aa30d4f17fc45a007079dd63 Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Tue, 4 Oct 2016 08:37:46 +0300 Subject: [PATCH] #216: do not require dev config for production builds --- webpack.config.js | 78 +++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index dc153d1..f59186d 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,15 +1,15 @@ /* eslint-env node */ -var path = require('path'); +const path = require('path'); -var webpack = require('webpack'); -var loaderUtils = require('loader-utils'); -var ExtractTextPlugin = require('extract-text-webpack-plugin'); -var HtmlWebpackPlugin = require('html-webpack-plugin'); -var cssUrl = require('webpack-utils/cssUrl'); -var cssImport = require('postcss-import'); +const webpack = require('webpack'); +const loaderUtils = require('loader-utils'); +const ExtractTextPlugin = require('extract-text-webpack-plugin'); +const HtmlWebpackPlugin = require('html-webpack-plugin'); +const cssUrl = require('webpack-utils/cssUrl'); +const cssImport = require('postcss-import'); -var vendor = Object.keys(require('./package.json').dependencies); +const vendor = Object.keys(require('./package.json').dependencies); const rootPath = path.resolve('./src'); @@ -39,16 +39,8 @@ if (isTest) { const CSS_CLASS_TEMPLATE = isProduction ? '[hash:base64:5]' : '[path][name]-[local]'; -var config; -try { - config = require('./config/dev.json'); -} catch (err) { - console.error('\n\n===\nPlease create dev.json config under ./config based on template.dev.json\n===\n\n'); - throw err; -} const fileCache = {}; - const cssLoaderQuery = { modules: true, importLoaders: 2, @@ -99,22 +91,6 @@ var webpackConfig = { 'react/addons': true } : {}, - devServer: { - host: 'localhost', - port: 8080, - proxy: { - '/api*': { - headers: { - host: config.apiHost.replace(/https?:|\//g, '') - }, - target: config.apiHost - } - }, - hot: true, - inline: true, - historyApiFallback: true - }, - devtool: isTest ? 'inline-source-map' : 'eval', plugins: [ @@ -238,13 +214,6 @@ var webpackConfig = { } }; -if (isDockerized) { - webpackConfig.watchOptions = { - poll: 2000 - }; - webpackConfig.devServer.host = '0.0.0.0'; -} - if (isProduction) { webpackConfig.module.loaders.forEach((loader) => { if (loader.extractInProduction) { @@ -268,10 +237,41 @@ if (isProduction) { } if (!isProduction && !isTest) { + var config; + try { + config = require('./config/dev.json'); + } catch (err) { + console.error('\n\n===\nPlease create dev.json config under ./config based on template.dev.json\n===\n\n'); + throw err; + } + webpackConfig.plugins.push( new webpack.HotModuleReplacementPlugin(), new webpack.NoErrorsPlugin() ); + + webpackConfig.devServer = { + host: 'localhost', + port: 8080, + proxy: { + '/api*': { + headers: { + host: config.apiHost.replace(/https?:|\//g, '') + }, + target: config.apiHost + } + }, + hot: true, + inline: true, + historyApiFallback: true + }; +} + +if (isDockerized) { + webpackConfig.watchOptions = { + poll: 2000 + }; + webpackConfig.devServer.host = '0.0.0.0'; } module.exports = webpackConfig;