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

feat(babel-preset-gatsby): add babel-plugin-transform-react-remove-prop-types for production builds #14987

Merged
merged 12 commits into from Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from 10 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
1 change: 1 addition & 0 deletions packages/babel-preset-gatsby/README.md
Expand Up @@ -12,6 +12,7 @@ For more information on how to customize the Babel configuration of your Gatsby
- [`@babel/plugin-syntax-dynamic-import`](https://babeljs.io/docs/en/babel-plugin-syntax-dynamic-import)
- [`@babel/plugin-transform-runtime`](https://babeljs.io/docs/en/babel-plugin-transform-runtime#docsNav)
- [`babel-plugin-macros`](https://github.com/kentcdodds/babel-plugin-macros)
- [`babel-plugin-transform-react-remove-prop-types`](https://github.com/oliviertassinari/babel-plugin-transform-react-remove-prop-types)

## Usage

Expand Down
3 changes: 2 additions & 1 deletion packages/babel-preset-gatsby/package.json
Expand Up @@ -16,7 +16,8 @@
"@babel/preset-react": "^7.0.0",
"@babel/runtime": "^7.4.5",
"babel-plugin-dynamic-import-node": "^1.2.0",
"babel-plugin-macros": "^2.4.2"
"babel-plugin-macros": "^2.4.2",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24"
},
"peerDependencies": {
"@babel/core": "^7.0.0"
Expand Down
21 changes: 21 additions & 0 deletions packages/babel-preset-gatsby/src/__tests__/index.js
Expand Up @@ -146,3 +146,24 @@ it(`Allows to configure browser targets`, () => {
},
])
})

describe(`in production mode`, () => {
it(`adds babel-plugin-transform-react-remove-prop-types`, () => {
process.env.GATSBY_BUILD_STAGE = `build-javascript`

const { plugins } = preset()

expect(plugins).toEqual(
expect.arrayContaining([
[
expect.stringContaining(
path.join(`babel-plugin-transform-react-remove-prop-types`)
),
{
removeImport: true,
},
],
])
)
})
})
19 changes: 19 additions & 0 deletions packages/babel-preset-gatsby/src/index.js
Expand Up @@ -45,6 +45,18 @@ module.exports = function preset(_, options = {}) {
}
}

const plugins = []
pieh marked this conversation as resolved.
Show resolved Hide resolved

if (stage === `build-javascript`) {
plugins.push([
// Remove PropTypes from production build
resolve(`babel-plugin-transform-react-remove-prop-types`),
{
removeImport: true,
},
])
}

return {
presets: [
[
Expand Down Expand Up @@ -94,6 +106,13 @@ module.exports = function preset(_, options = {}) {
},
],
IS_TEST && resolve(`babel-plugin-dynamic-import-node`),
stage === `build-javascript` && [
// Remove PropTypes from production build
resolve(`babel-plugin-transform-react-remove-prop-types`),
{
removeImport: true,
},
],
].filter(Boolean),
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -4687,6 +4687,11 @@ babel-plugin-transform-object-rest-spread@^6.22.0, babel-plugin-transform-object
babel-plugin-syntax-object-rest-spread "^6.8.0"
babel-runtime "^6.26.0"

babel-plugin-transform-react-remove-prop-types@^0.4.24:
version "0.4.24"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-react-remove-prop-types/-/babel-plugin-transform-react-remove-prop-types-0.4.24.tgz#f2edaf9b4c6a5fbe5c1d678bfb531078c1555f3a"
integrity sha512-eqj0hVcJUR57/Ug2zE1Yswsw4LhuqqHhD+8v120T1cl3kjg76QwtyBrdIk4WVwK+lAhBJVYCd/v+4nc4y+8JsA==

babel-plugin-transform-regenerator@^6.24.1:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-regenerator/-/babel-plugin-transform-regenerator-6.26.0.tgz#e0703696fbde27f0a3efcacf8b4dca2f7b3a8f2f"
Expand Down