fix: prevent duplication of Monaco webpack plugin (#38131)

It seems that adding it during the 'build-html' stage meant it was
creating new, unminified, versions of the scripts and overwriting the
existing, minified, ones.
This commit is contained in:
Oliver Eyton-Williams
2020-02-06 12:24:00 +01:00
committed by GitHub
parent f3a386982a
commit c76978bdfe

View File

@ -161,12 +161,8 @@ exports.createPages = function createPages({ graphql, actions, reporter }) {
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin'); const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
exports.onCreateWebpackConfig = ({ plugins, actions }) => { exports.onCreateWebpackConfig = ({ stage, plugins, actions }) => {
actions.setWebpackConfig({ const newPlugins = [
node: {
fs: 'empty'
},
plugins: [
plugins.define({ plugins.define({
HOME_PATH: JSON.stringify( HOME_PATH: JSON.stringify(
process.env.HOME_PATH || 'http://localhost:3000' process.env.HOME_PATH || 'http://localhost:3000'
@ -177,9 +173,19 @@ exports.onCreateWebpackConfig = ({ plugins, actions }) => {
process.env.FREECODECAMP_NODE_ENV || 'development' process.env.FREECODECAMP_NODE_ENV || 'development'
), ),
PAYPAL_SUPPORTERS: JSON.stringify(process.env.PAYPAL_SUPPORTERS || 404) PAYPAL_SUPPORTERS: JSON.stringify(process.env.PAYPAL_SUPPORTERS || 404)
}), })
new MonacoWebpackPlugin() ];
] // The monaco editor relies on some browser only globals so should not be
// involved in SSR. Also, if the plugin is used during the 'build-html' stage
// it overwrites the minfied files with ordinary ones.
if (stage !== 'build-html') {
newPlugins.push(new MonacoWebpackPlugin());
}
actions.setWebpackConfig({
node: {
fs: 'empty'
},
plugins: newPlugins
}); });
}; };