From 658fd6c13911b1f1f4e6a97ce59790ac66bc3cf0 Mon Sep 17 00:00:00 2001 From: Matt Hughes Date: Thu, 15 Nov 2018 16:48:32 -0500 Subject: [PATCH] Consolidate worker-targetting webpack config in common This changes the production config. Spooky scary! --- webpack.common.config.js | 28 +++++++++++++++++++++++++++- webpack.dev.config.js | 30 ++++-------------------------- webpack.prod.config.js | 14 ++++++++------ 3 files changed, 39 insertions(+), 33 deletions(-) diff --git a/webpack.common.config.js b/webpack.common.config.js index 0cc46249265c..7563f6e54f2a 100644 --- a/webpack.common.config.js +++ b/webpack.common.config.js @@ -27,6 +27,7 @@ var defineFooter = new RegExp('(' + defineCallFooter.source + ')|(' + defineFancyFooter.source + ')', 'm'); module.exports = Merge.smart({ + web: { context: __dirname, entry: { @@ -384,4 +385,29 @@ module.exports = Merge.smart({ fs: 'empty' } -}, xmoduleJS); + }, + webworker: { + target: "webworker", + context: __dirname, + entry: { + mockprock: './node_modules/edx-proctoring/edx_proctoring/static/proctoring/js/plugin/mockprock-provider.js', + }, + output: { + filename: '[name].js', + path: path.resolve(__dirname, 'common/static/bundles'), + }, + plugins: [ + new BundleTracker({ + path: process.env.STATIC_ROOT_LMS, + filename: 'webpack-worker-stats.json' + }) + ], + resolve: { + extensions: ['.js'], + modules: [ + 'node_modules', + 'node_modules/edx-proctoring/node_modules' + ] + } + }}, {web: xmoduleJS}); + diff --git a/webpack.dev.config.js b/webpack.dev.config.js index 150c2ef6ba73..227dc431e35c 100644 --- a/webpack.dev.config.js +++ b/webpack.dev.config.js @@ -7,10 +7,12 @@ var path = require('path'); var webpack = require('webpack'); // TODO: remove once common worker settings moved into common var BundleTracker = require('webpack-bundle-tracker'); +var _ = require('underscore'); var commonConfig = require('./webpack.common.config.js'); -module.exports = [Merge.smart(commonConfig, { +module.exports = _.values(Merge.smart(commonConfig, { + web: { output: { filename: '[name].js' }, @@ -59,28 +61,4 @@ module.exports = [Merge.smart(commonConfig, { watchOptions: { ignored: [/node_modules/, /\.git/] } -}), -{ - target: "webworker", - context: __dirname, - entry: { - mockprock: './node_modules/edx-proctoring/edx_proctoring/static/proctoring/js/plugin/mockprock-provider.js', - }, - output: { - filename: '[name].js', - path: path.resolve(__dirname, 'common/static/bundles'), - }, - plugins: [ - new BundleTracker({ - path: process.env.STATIC_ROOT_LMS, - filename: 'webpack-worker-stats.json' - }) - ], - resolve: { - extensions: ['.js'], - modules: [ - 'node_modules', - 'node_modules/edx-proctoring/node_modules' - ] - } -}]; +}})); diff --git a/webpack.prod.config.js b/webpack.prod.config.js index 97570626b266..360ab56d4d01 100644 --- a/webpack.prod.config.js +++ b/webpack.prod.config.js @@ -4,10 +4,13 @@ var Merge = require('webpack-merge'); var webpack = require('webpack'); +var BundleTracker = require('webpack-bundle-tracker'); +var _ = require('underscore'); var commonConfig = require('./webpack.common.config.js'); var optimizedConfig = Merge.smart(commonConfig, { + web: { output: { filename: '[name].[chunkhash].js' }, @@ -28,7 +31,7 @@ var optimizedConfig = Merge.smart(commonConfig, { minChunks: 3 }) ] -}); +}}); // requireCompatConfig only exists so that you can use RequireJS to require a // Webpack bundle (but try not to do that if you can help it). RequireJS knows @@ -44,6 +47,7 @@ var optimizedConfig = Merge.smart(commonConfig, { // Step 1: Alter the bundle output names to omit the chunkhash. var requireCompatConfig = Merge.smart(optimizedConfig, { + web: { output: { filename: '[name].js' }, @@ -56,14 +60,12 @@ var requireCompatConfig = Merge.smart(optimizedConfig, { minChunks: 3 }) ] -}); +}}); // Step 2: Remove the plugin entries that generate the webpack-stats.json files // that Django needs to look up resources. We never want to accidentally // overwrite those because it means that we'll be serving assets with shorter // cache times. RequireJS never looks at the webpack-stats.json file. -requireCompatConfig.plugins = requireCompatConfig.plugins.filter( - function(plugin) { return !plugin.options || (plugin.options && plugin.options.filename !== 'webpack-stats.json'); } -); +requireCompatConfig.web.plugins = requireCompatConfig.web.plugins.filter((plugin) => !(plugin instanceof BundleTracker)); -module.exports = [optimizedConfig, requireCompatConfig]; +module.exports = [..._.values(optimizedConfig), ..._.values(requireCompatConfig)];