Skip to content

Commit

Permalink
Consolidate worker-targetting webpack config in common
Browse files Browse the repository at this point in the history
This changes the production config. Spooky scary!
  • Loading branch information
Matt Hughes authored and Dave St.Germain committed Dec 21, 2018
1 parent edd15f1 commit 658fd6c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 33 deletions.
28 changes: 27 additions & 1 deletion webpack.common.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var defineFooter = new RegExp('(' + defineCallFooter.source + ')|('
+ defineFancyFooter.source + ')', 'm');

module.exports = Merge.smart({
web: {
context: __dirname,

entry: {
Expand Down Expand Up @@ -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});

30 changes: 4 additions & 26 deletions webpack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
Expand Down Expand Up @@ -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'
]
}
}];
}}));
14 changes: 8 additions & 6 deletions webpack.prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
Expand All @@ -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
Expand All @@ -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'
},
Expand All @@ -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)];

0 comments on commit 658fd6c

Please sign in to comment.