Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby-plugin-gatsby-cloud): only load indicator code when enabled (#31506) #31575

Merged
merged 1 commit into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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