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.
pull/38174/head
Oliver Eyton-Williams 2020-02-06 12:24:00 +01:00 committed by GitHub
parent f3a386982a
commit c76978bdfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 15 deletions

View File

@ -161,25 +161,31 @@ exports.createPages = function createPages({ graphql, actions, reporter }) {
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
exports.onCreateWebpackConfig = ({ plugins, actions }) => {
exports.onCreateWebpackConfig = ({ stage, plugins, actions }) => {
const newPlugins = [
plugins.define({
HOME_PATH: JSON.stringify(
process.env.HOME_PATH || 'http://localhost:3000'
),
STRIPE_PUBLIC_KEY: JSON.stringify(process.env.STRIPE_PUBLIC_KEY || ''),
ROLLBAR_CLIENT_ID: JSON.stringify(process.env.ROLLBAR_CLIENT_ID || ''),
ENVIRONMENT: JSON.stringify(
process.env.FREECODECAMP_NODE_ENV || 'development'
),
PAYPAL_SUPPORTERS: JSON.stringify(process.env.PAYPAL_SUPPORTERS || 404)
})
];
// 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: [
plugins.define({
HOME_PATH: JSON.stringify(
process.env.HOME_PATH || 'http://localhost:3000'
),
STRIPE_PUBLIC_KEY: JSON.stringify(process.env.STRIPE_PUBLIC_KEY || ''),
ROLLBAR_CLIENT_ID: JSON.stringify(process.env.ROLLBAR_CLIENT_ID || ''),
ENVIRONMENT: JSON.stringify(
process.env.FREECODECAMP_NODE_ENV || 'development'
),
PAYPAL_SUPPORTERS: JSON.stringify(process.env.PAYPAL_SUPPORTERS || 404)
}),
new MonacoWebpackPlugin()
]
plugins: newPlugins
});
};