From cb654cd7dd3a42f5e557736d18b0f7530d4a710e Mon Sep 17 00:00:00 2001 From: Ward Peeters Date: Fri, 21 May 2021 15:34:15 +0200 Subject: [PATCH] fix(gatsby-plugin-gatsby-cloud): only load indicator code when enabled (#31506) Co-authored-by: Vladimir Razuvaev --- .../__tests__/__snapshots__/index.js.snap | 4 ++++ packages/babel-preset-gatsby-package/index.js | 20 ++++++++++++++----- packages/gatsby-plugin-gatsby-cloud/.babelrc | 8 +++++++- .../src/gatsby-node.js | 3 +++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/packages/babel-preset-gatsby-package/__tests__/__snapshots__/index.js.snap b/packages/babel-preset-gatsby-package/__tests__/__snapshots__/index.js.snap index f714defcca2d0..61f2ee2760747 100644 --- a/packages/babel-preset-gatsby-package/__tests__/__snapshots__/index.js.snap +++ b/packages/babel-preset-gatsby-package/__tests__/__snapshots__/index.js.snap @@ -5,6 +5,7 @@ Array [ Array [ "@babel/preset-env", Object { + "bugfixes": false, "debug": false, "loose": true, "modules": "commonjs", @@ -31,6 +32,7 @@ Array [ Array [ "@babel/preset-env", Object { + "bugfixes": false, "debug": true, "loose": true, "modules": "commonjs", @@ -67,6 +69,7 @@ Array [ Array [ "@babel/preset-env", Object { + "bugfixes": false, "corejs": 3, "debug": false, "loose": true, @@ -90,6 +93,7 @@ Array [ Array [ "@babel/preset-env", Object { + "bugfixes": false, "corejs": 3, "debug": true, "loose": true, diff --git a/packages/babel-preset-gatsby-package/index.js b/packages/babel-preset-gatsby-package/index.js index d7c6f300d973e..689a77fcea864 100644 --- a/packages/babel-preset-gatsby-package/index.js +++ b/packages/babel-preset-gatsby-package/index.js @@ -1,16 +1,25 @@ const r = require(`./resolver`) function preset(context, options = {}) { - const { browser = false, debug = false, nodeVersion = `12.13.0` } = options + const { browser = false, debug = false, nodeVersion = `12.13.0`, esm = false } = options const { NODE_ENV, BABEL_ENV } = process.env const IS_TEST = (BABEL_ENV || NODE_ENV) === `test` const browserConfig = { useBuiltIns: false, - targets: { - browsers: [`last 2 versions`, `not ie <= 11`, `not android 4.4.3`], - }, + } + + if (browser) { + if (esm) { + browserConfig.targets = { + esmodules: true + } + } else { + browserConfig.targets = { + browsers: [`last 2 versions`, `not ie <= 11`, `not android 4.4.3`] + } + } } const nodeConfig = { @@ -30,7 +39,8 @@ function preset(context, options = {}) { loose: true, debug: !!debug, shippedProposals: true, - modules: `commonjs`, + modules: esm ? false : `commonjs`, + bugfixes: esm, }, browser ? browserConfig : nodeConfig ), diff --git a/packages/gatsby-plugin-gatsby-cloud/.babelrc b/packages/gatsby-plugin-gatsby-cloud/.babelrc index ac0ad292bb087..7094b00b614c2 100644 --- a/packages/gatsby-plugin-gatsby-cloud/.babelrc +++ b/packages/gatsby-plugin-gatsby-cloud/.babelrc @@ -1,3 +1,9 @@ { - "presets": [["babel-preset-gatsby-package"]] + "presets": [["babel-preset-gatsby-package"]], + "overrides": [ + { + "test": ["**/gatsby-browser.js"], + "presets": [["babel-preset-gatsby-package", { "browser": true, "esm": true }]] + } + ] } diff --git a/packages/gatsby-plugin-gatsby-cloud/src/gatsby-node.js b/packages/gatsby-plugin-gatsby-cloud/src/gatsby-node.js index 225eb894058f1..06f558ea21d78 100644 --- a/packages/gatsby-plugin-gatsby-cloud/src/gatsby-node.js +++ b/packages/gatsby-plugin-gatsby-cloud/src/gatsby-node.js @@ -10,6 +10,9 @@ import { DEFAULT_OPTIONS, BUILD_HTML_STAGE, BUILD_CSS_STAGE } from "./constants" const assetsManifest = {} +process.env.GATSBY_PREVIEW_INDICATOR_ENABLED = + process.env.GATSBY_PREVIEW_INDICATOR_ENABLED || `false` + // Inject a webpack plugin to get the file manifests so we can translate all link headers exports.onCreateWebpackConfig = ({ actions, stage }) => { if (stage !== BUILD_HTML_STAGE && stage !== BUILD_CSS_STAGE) {