From e1279b2b98355f656d338d83e2dacec1ca272ffb Mon Sep 17 00:00:00 2001 From: Mael Date: Thu, 1 Mar 2018 19:39:36 +0100 Subject: [PATCH] :sparkles: Nettoyage de la configuration Webpack --- package.json | 7 +-- source/server.js | 2 +- .../{webpack.config.js => webpack.common.js} | 46 +++---------------- source/webpack.dev.js | 28 +++++++++++ source/webpack.prod.js | 14 ++++++ 5 files changed, 52 insertions(+), 45 deletions(-) rename source/{webpack.config.js => webpack.common.js} (53%) create mode 100644 source/webpack.dev.js create mode 100644 source/webpack.prod.js diff --git a/package.json b/package.json index 36f66d77e..ed223b7f3 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,7 @@ "engines": { "node": ">=6.2.0 <10.0.0" }, - "browserslist": [ - "> 1% in FR", - "not ie < 11" - ], + "browserslist": ["> 1% in FR", "not ie < 11"], "dependencies": { "@babel/polyfill": "^7.0.0-beta.34", "classnames": "^2.2.5", @@ -105,7 +102,7 @@ "scripts": { "start": "node source/server.js", "externalize": "node source/externalize.js", - "compile": "NODE_ENV='production' webpack --config source/webpack.config.js", + "compile": "NODE_ENV='production' webpack --config source/webpack.prod.js", "test": "mocha-webpack --webpack-config source/webpack.test.config.js --require source-map-support/register --require test/helpers/browser.js \"test/**/*.test.js\"", "test-watch": "mocha-webpack --webpack-config source/webpack.test.config.js --require source-map-support/register --require test/helpers/browser.js \"test/**/*.test.js\" --watch", "test-meca": "mocha-webpack --webpack-config source/webpack.test.config.js --require source-map-support/register --require test/helpers/browser.js test/mecanisms.test.js --watch", diff --git a/source/server.js b/source/server.js index 64bf1014d..6110cf040 100644 --- a/source/server.js +++ b/source/server.js @@ -1,6 +1,6 @@ var webpack = require('webpack') var WebpackDevServer = require('webpack-dev-server') -var config = require('./webpack.config') +var config = require('./webpack.dev') const PORT = process.env.PORT || 3000 diff --git a/source/webpack.config.js b/source/webpack.common.js similarity index 53% rename from source/webpack.config.js rename to source/webpack.common.js index eec6c6527..43292dcaa 100644 --- a/source/webpack.config.js +++ b/source/webpack.common.js @@ -1,29 +1,5 @@ -var webpack = require('webpack'), - path = require('path'), - prodEnv = process.env.NODE_ENV == 'production', // eslint-disable-line no-undef - HardSourceWebpackPlugin = require('hard-source-webpack-plugin') - +var path = require('path') module.exports = { - devtool: 'cheap-module-source-map', - entry: { - bundle: prodEnv - ? ['@babel/polyfill', 'whatwg-fetch', './source/entry.js'] - : [ - 'webpack-dev-server/client?http://0.0.0.0:3000/', - 'webpack/hot/only-dev-server', - '@babel/polyfill', - 'react-hot-loader/patch', - './source/entry.js' - ], - // le nom "simulateur" est là pour des raisons historiques - simulateur: './source/iframe-script.js', - 'colour-chooser': ['@babel/polyfill', './source/entry-colour-chooser.js'] - }, - output: { - path: path.resolve('./dist/'), - filename: '[name].js', - publicPath: '/dist/' - }, resolve: { alias: { Engine: path.resolve('source/engine/'), @@ -32,6 +8,11 @@ module.exports = { Images: path.resolve('source/images/') } }, + output: { + path: path.resolve('./dist/'), + filename: '[name].js', + publicPath: '/dist/' + }, module: { loaders: [ { @@ -88,18 +69,5 @@ module.exports = { loader: 'babel-loader!nearley-loader' } ] - }, - plugins: [ - new webpack.EnvironmentPlugin({ NODE_ENV: 'development' }), - new webpack.NoEmitOnErrorsPlugin() - ] - .concat( - !prodEnv - ? [ - new webpack.HotModuleReplacementPlugin(), - new HardSourceWebpackPlugin() - ] - : [] - ) - .concat(prodEnv ? [new webpack.optimize.UglifyJsPlugin()] : []) + } } diff --git a/source/webpack.dev.js b/source/webpack.dev.js new file mode 100644 index 000000000..0e6f24ecf --- /dev/null +++ b/source/webpack.dev.js @@ -0,0 +1,28 @@ +var webpack = require('webpack'), + path = require('path'), + HardSourceWebpackPlugin = require('hard-source-webpack-plugin'), + common = require('./webpack.common.js') + +module.exports = { + ...common, + entry: { + bundle: [ + 'webpack-dev-server/client?http://0.0.0.0:3000/', + 'webpack/hot/only-dev-server', + '@babel/polyfill', + 'react-hot-loader/patch', + './source/entry.js' + ] + // entrées désactivées pour accélérer la compilation au dev + // + // le nom "simulateur" est là pour des raisons historiques + // + // simulateur: './source/iframe-script.js', + // 'colour-chooser': ['@babel/polyfill', './source/entry-colour-chooser.js'] + }, + plugins: [ + new webpack.EnvironmentPlugin({ NODE_ENV: 'development' }), + new webpack.HotModuleReplacementPlugin(), + new HardSourceWebpackPlugin() + ] +} diff --git a/source/webpack.prod.js b/source/webpack.prod.js new file mode 100644 index 000000000..cdcce1240 --- /dev/null +++ b/source/webpack.prod.js @@ -0,0 +1,14 @@ +var webpack = require('webpack'), + common = require('./webpack.common.js') + +module.exports = { + ...common, + entry: { + bundle: ['@babel/polyfill', 'whatwg-fetch', './source/entry.js'], + // le nom "simulateur" est là pour des raisons historiques + // + simulateur: './source/iframe-script.js', + 'colour-chooser': ['@babel/polyfill', './source/entry-colour-chooser.js'] + }, + plugins: [new webpack.optimize.UglifyJsPlugin()] +}