From c76978bdfe233b3842aeb5f29f9f936578894b74 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Thu, 6 Feb 2020 12:24:00 +0100 Subject: [PATCH] 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. --- client/gatsby-node.js | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/client/gatsby-node.js b/client/gatsby-node.js index 9ae1e655068..989519d79be 100644 --- a/client/gatsby-node.js +++ b/client/gatsby-node.js @@ -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 }); };