diff options
author | Mike Greiling <mike@pixelcog.com> | 2018-03-03 00:12:49 +0300 |
---|---|---|
committer | Mike Greiling <mike@pixelcog.com> | 2018-05-01 23:14:58 +0300 |
commit | 50889179df671a29175ea69b9187a2eb67e652f0 (patch) | |
tree | 4c2473a1757693a6d682f24c2e040786a3d51ce0 | |
parent | a6c6e29c97a3736862eb690fe2c46927907751ab (diff) |
adjust webpack config
-rw-r--r-- | config/karma.config.js | 21 | ||||
-rw-r--r-- | config/webpack.config.js | 56 |
2 files changed, 40 insertions, 37 deletions
diff --git a/config/karma.config.js b/config/karma.config.js index 3eb220eed99..28a688797d9 100644 --- a/config/karma.config.js +++ b/config/karma.config.js @@ -12,16 +12,14 @@ function fatalError(message) { process.exit(1); } -// remove problematic plugins -if (webpackConfig.plugins) { - webpackConfig.plugins = webpackConfig.plugins.filter(function(plugin) { - return !( - plugin instanceof webpack.optimize.CommonsChunkPlugin || - plugin instanceof webpack.optimize.ModuleConcatenationPlugin || - plugin instanceof webpack.DefinePlugin - ); - }); -} +// disable problematic options +webpackConfig.entry = undefined; +webpackConfig.mode = 'development'; +webpackConfig.optimization.runtimeChunk = false; +webpackConfig.optimization.splitChunks = false; + +// use quicker sourcemap option +webpackConfig.devtool = 'cheap-inline-source-map'; const specFilters = argumentsParser .option( @@ -77,9 +75,6 @@ if (specFilters.length) { ); } -webpackConfig.entry = undefined; -webpackConfig.devtool = 'cheap-inline-source-map'; - // Karma configuration module.exports = function(config) { process.env.TZ = 'Etc/UTC'; diff --git a/config/webpack.config.js b/config/webpack.config.js index b9d098ff9b9..577f1656e3b 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -21,6 +21,7 @@ const NO_COMPRESSION = process.env.NO_COMPRESSION; let autoEntriesCount = 0; let watchAutoEntries = []; +const defaultEntries = ['./webpack', './commons', './main']; function generateEntries() { // generate automatic entry points @@ -33,7 +34,7 @@ function generateEntries() { function generateAutoEntries(path, prefix = '.') { const chunkPath = path.replace(/\/index\.js$/, ''); const chunkName = chunkPath.replace(/\//g, '.'); - autoEntries[chunkName] = `${prefix}/${path}`; + autoEntries[chunkName] = defaultEntries.concat(`${prefix}/${path}`); } pageEntries.forEach(path => generateAutoEntries(path)); @@ -41,10 +42,7 @@ function generateEntries() { autoEntriesCount = Object.keys(autoEntries).length; const manualEntries = { - common: './commons/index.js', - main: './main.js', raven: './raven/index.js', - webpack_runtime: './webpack.js', ide: './ide/index.js', }; @@ -52,6 +50,8 @@ function generateEntries() { } const config = { + mode: IS_PRODUCTION ? 'production' : 'development', + context: path.join(ROOT_PATH, 'app/assets/javascripts'), entry: generateEntries, @@ -63,6 +63,33 @@ const config = { chunkFilename: IS_PRODUCTION ? '[name].[chunkhash].chunk.js' : '[name].chunk.js', }, + optimization: { + nodeEnv: false, + runtimeChunk: 'single', + splitChunks: { + maxInitialRequests: 4, + cacheGroups: { + default: false, + common: () => ({ + priority: 20, + name: 'main', + chunks: 'initial', + minChunks: autoEntriesCount * 0.9, + }), + vendors: { + priority: 10, + chunks: 'async', + test: /[\\/](node_modules|vendor[\\/]assets[\\/]javascripts)[\\/]/, + }, + commons: { + chunks: 'all', + minChunks: 2, + reuseExistingChunk: true, + }, + }, + }, + }, + module: { rules: [ { @@ -209,11 +236,6 @@ const config = { return `${moduleNames[0]}-${hash.substr(0, 6)}`; }), - // create cacheable common library bundles - new webpack.optimize.CommonsChunkPlugin({ - names: ['main', 'common', 'webpack_runtime'], - }), - // copy pre-compiled vendor libraries verbatim new CopyWebpackPlugin([ { @@ -260,20 +282,6 @@ const config = { if (IS_PRODUCTION) { config.devtool = 'source-map'; - config.plugins.push( - new webpack.NoEmitOnErrorsPlugin(), - new webpack.LoaderOptionsPlugin({ - minimize: true, - debug: false, - }), - new webpack.optimize.ModuleConcatenationPlugin(), - new webpack.optimize.UglifyJsPlugin({ - sourceMap: true, - }), - new webpack.DefinePlugin({ - 'process.env': { NODE_ENV: JSON.stringify('production') }, - }) - ); // compression can require a lot of compute time and is disabled in CI if (!NO_COMPRESSION) { @@ -294,7 +302,7 @@ if (IS_DEV_SERVER) { }; config.plugins.push( // watch node_modules for changes if we encounter a missing module compile error - new WatchMissingNodeModulesPlugin(path.join(ROOT_PATH, 'node_modules')), + // new WatchMissingNodeModulesPlugin(path.join(ROOT_PATH, 'node_modules')), // watch for changes to our automatic entry point modules { |