Skip to content

Commit

Permalink
fix(gatsby-plugin-gatsby-cloud): only load indicator code when enabled (
Browse files Browse the repository at this point in the history
#31506) (#31575)

Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>
(cherry picked from commit cb654cd)

Co-authored-by: Ward Peeters <ward@coding-tech.com>
  • Loading branch information
GatsbyJS Bot and wardpeet committed May 25, 2021
1 parent 1231e17 commit ae5f270
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
Expand Up @@ -5,6 +5,7 @@ Array [
Array [
"@babel/preset-env",
Object {
"bugfixes": false,
"debug": false,
"loose": true,
"modules": "commonjs",
Expand All @@ -31,6 +32,7 @@ Array [
Array [
"@babel/preset-env",
Object {
"bugfixes": false,
"debug": true,
"loose": true,
"modules": "commonjs",
Expand Down Expand Up @@ -67,6 +69,7 @@ Array [
Array [
"@babel/preset-env",
Object {
"bugfixes": false,
"corejs": 3,
"debug": false,
"loose": true,
Expand All @@ -90,6 +93,7 @@ Array [
Array [
"@babel/preset-env",
Object {
"bugfixes": false,
"corejs": 3,
"debug": true,
"loose": true,
Expand Down
20 changes: 15 additions & 5 deletions 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 = {
Expand All @@ -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
),
Expand Down
8 changes: 7 additions & 1 deletion 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 }]]
}
]
}
3 changes: 3 additions & 0 deletions packages/gatsby-plugin-gatsby-cloud/src/gatsby-node.js
Expand Up @@ -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) {
Expand Down

0 comments on commit ae5f270

Please sign in to comment.