Skip to content

Commit

Permalink
feat(babel-preset-gatsby): add babel-plugin-transform-react-remove-pr…
Browse files Browse the repository at this point in the history
…op-types for production builds (#14987)

* feat(babel-preset-gatsby): Add babel-plugin-transform-react-remove-prop-types to babel-preset-gatsby

Remove PropTypes from production build

re #14814

* docs(babel-preset-gatsby): Add babel-plugin-transform-react-remove-prop-types link to README in #pac

re #14814

* test(babel-preset-gatsby): Add test - in production mode specifies proper presets

#14814

* fix(babel-preset-gatsby): Remove core-js package from package.json installed when developing but nev

#14814

* refactor(babel-preset-gatsby): Use GATSBY_BUILD_STAGE in place of BABEL_ENV || NODE_ENV

#14814

* test(babel-preset-gatsby): Remove beforeEach in tests on production env

#14814

* update lock file

* update tests

* fixup after merge conflict resolution/small refactor
  • Loading branch information
luisFilipePT authored and GatsbyJS Bot committed Jul 12, 2019
1 parent 147dae5 commit 633e9ea
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
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,
},
],
])
)
})
})
7 changes: 7 additions & 0 deletions packages/babel-preset-gatsby/src/index.js
Expand Up @@ -94,6 +94,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

0 comments on commit 633e9ea

Please sign in to comment.