Skip to content

Commit

Permalink
chore: revert extra package changes to publish babel-preset-gatsby fi…
Browse files Browse the repository at this point in the history
…rst (#9322)

* Revert "Add babel-preset-gatsby (#8724)"

This reverts commit 69faca0.

* chore: add these packages _first_ then use them in a future PR
  • Loading branch information
DSchau committed Oct 23, 2018
1 parent 69faca0 commit a392fb4
Show file tree
Hide file tree
Showing 98 changed files with 353 additions and 113 deletions.
50 changes: 50 additions & 0 deletions .babel-preset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const r = m => require.resolve(m)

function preset(context, options = {}) {
const { browser = false, debug = false } = options
const { NODE_ENV, BABEL_ENV } = process.env

const PRODUCTION = (BABEL_ENV || NODE_ENV) === "production"

const browserConfig = {
useBuiltIns: false,
targets: {
browsers: PRODUCTION
? [`last 4 versions`, `safari >= 7`, "ie >= 9"]
: [`last 2 versions`, `not ie <= 11`, `not android 4.4.3`],
},
}

const nodeConfig = {
targets: {
node: PRODUCTION ? 6.0 : "current",
},
}

return {
presets: [
[
r("@babel/preset-env"),
Object.assign(
{
loose: true,
debug: !!debug,
useBuiltIns: "entry",
shippedProposals: true,
modules: "commonjs",
},
browser ? browserConfig : nodeConfig
),
],
[r("@babel/preset-react"), { development: !PRODUCTION }],
r("@babel/preset-flow"),
],
plugins: [
r("@babel/plugin-proposal-class-properties"),
r("@babel/plugin-proposal-optional-chaining"),
r("@babel/plugin-transform-runtime"),
],
}
}

module.exports = preset
4 changes: 3 additions & 1 deletion .babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ if (process.env.NODE_ENV !== `test`) {
ignore.push(`**/__tests__`)
}

const presetAbsPath = require(`path`).join(__dirname, '.babel-preset.js')

module.exports = {
sourceMaps: true,
presets: ["babel-preset-gatsby-package"],
presets: [presetAbsPath],
ignore,
}
39 changes: 31 additions & 8 deletions docs/docs/babel.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,48 @@ browsers.
## How to use a custom .babelrc file

Gatsby ships with a default .babelrc setup that should work for most sites. If you'd like
to add custom Babel presets or plugins, you can create your own `.babelrc` at the root of your site, import [`babel-preset-gatsby`](https://github.com/gatsbyjs/gatsby/tree/master/packages/babel-preset-gatsby), and overwrite the `target` option.

```bash
npm install --save babel-preset-gatsby
```
to add custom Babel presets or plugins, we recommend copying our default .babelrc below
to the root of your site and modifying it per your needs.

```json5:title=.babelrc
{
presets: [
[
"babel-preset-gatsby",
"@babel/preset-env",
{
loose: true,
modules: false,
useBuiltIns: "usage",
shippedProposals: true,
targets: {
browsers: [">0.25%", "not dead"],
},
},
],
[
"@babel/preset-react",
{
useBuiltIns: true,
pragma: "React.createElement",
},
],
],
plugins: [
[
"@babel/plugin-proposal-class-properties",
{
loose: true,
},
],
"@babel/plugin-syntax-dynamic-import",
"babel-plugin-macros",
[
"@babel/plugin-transform-runtime",
{
helpers: true,
regenerator: true,
},
],
],
}
```

For more advanced configurations, you can also copy the defaults from [`babel-preset-gatsby`](https://github.com/gatsbyjs/gatsby/tree/master/packages/babel-preset-gatsby) and customize them to suit your needs.
8 changes: 5 additions & 3 deletions docs/docs/testing-css-in-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ If you followed along with the [Unit testing guide](/docs/unit-testing) you'll h

```diff:title=jest-preprocess.js
const babelOptions = {
presets: ["babel-preset-gatsby"],
+ plugins: [
presets: ["@babel/react", "@babel/env"],
plugins: [
+ "emotion",
+ ],
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-class-properties",
],
}

module.exports = require("babel-jest").createTransformer(babelOptions)
Expand Down
8 changes: 6 additions & 2 deletions docs/docs/unit-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ First you need to install Jest and some more required packages. You need to
install Babel 7 as it's required by Jest.

```sh
npm install --save-dev jest babel-jest react-test-renderer identity-obj-proxy 'babel-core@^7.0.0-0' @babel/core babel-preset-gatsby
npm install --save-dev jest babel-jest react-test-renderer identity-obj-proxy 'babel-core@^7.0.0-0' @babel/core @babel/preset-env @babel/preset-react @babel/plugin-proposal-class-properties @babel/plugin-proposal-optional-chaining
```

Because Gatsby handles its own Babel configuration, you will need to manually
Expand Down Expand Up @@ -61,7 +61,11 @@ with a minimal config.

```js:title=jest-preprocess.js
const babelOptions = {
presets: ["babel-preset-gatsby"],
presets: ["@babel/react", "@babel/env"],
plugins: [
"@babel/plugin-proposal-optional-chaining",
"@babel/plugin-proposal-class-properties",
],
}

module.exports = require("babel-jest").createTransformer(babelOptions)
Expand Down
3 changes: 2 additions & 1 deletion jest-transformer.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
const babelPreset = require(`babel-preset-gatsby-package`)()
const presetAbsPath = require(`path`).join(__dirname, `.babel-preset.js`)
const babelPreset = require(presetAbsPath)()
module.exports = require(`babel-jest`).createTransformer(babelPreset)
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/node": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-flow": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@babel/runtime": "^7.0.0",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "8.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-remove-graphql-queries/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["babel-preset-gatsby-package"]
["../../.babel-preset.js"]
]
}
2 changes: 1 addition & 1 deletion packages/gatsby-cli/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["babel-preset-gatsby-package"]
["../../.babel-preset.js"]
]
}
2 changes: 1 addition & 1 deletion packages/gatsby-codemods/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["babel-preset-gatsby-package"]
["../../.babel-preset.js"]
]
}
2 changes: 1 addition & 1 deletion packages/gatsby-dev-cli/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["babel-preset-gatsby-package"]
["../../.babel-preset.js"]
]
}
2 changes: 1 addition & 1 deletion packages/gatsby-image/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["babel-preset-gatsby-package", { "browser": true }]
["../../.babel-preset.js", { "browser": true }]
]
}
2 changes: 1 addition & 1 deletion packages/gatsby-link/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["babel-preset-gatsby-package", { "browser": true }]
["../../.babel-preset.js", { "browser": true }]
]
}

2 changes: 1 addition & 1 deletion packages/gatsby-plugin-canonical-urls/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["babel-preset-gatsby-package", { "browser": true }]
["../../.babel-preset.js", { "browser": true }]
]
}

2 changes: 1 addition & 1 deletion packages/gatsby-plugin-catch-links/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["babel-preset-gatsby-package", { "browser": true }]
["../../.babel-preset.js", { "browser": true }]
]
}

2 changes: 1 addition & 1 deletion packages/gatsby-plugin-coffeescript/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["babel-preset-gatsby-package"]
["../../.babel-preset.js"]
]
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-create-client-paths/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["babel-preset-gatsby-package"]
["../../.babel-preset.js"]
]
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-emotion/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["babel-preset-gatsby-package", { "browser": true }]
["../../.babel-preset.js", { "browser": true }]
]
}

2 changes: 1 addition & 1 deletion packages/gatsby-plugin-facebook-analytics/.babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": [["babel-preset-gatsby-package", { "browser": true }]]
"presets": [["../../.babel-preset.js", { "browser": true }]]
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-feed/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["babel-preset-gatsby-package", { "browser": true }]
["../../.babel-preset.js", { "browser": true }]
]
}

2 changes: 1 addition & 1 deletion packages/gatsby-plugin-fullstory/.babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": [["babel-preset-gatsby-package", { "browser": true }]]
"presets": [["../../.babel-preset.js", { "browser": true }]]
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-glamor/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["babel-preset-gatsby-package", { "browser": true }]
["../../.babel-preset.js", { "browser": true }]
]
}

2 changes: 1 addition & 1 deletion packages/gatsby-plugin-google-analytics/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["babel-preset-gatsby-package", { "browser": true }]
["../../.babel-preset.js", { "browser": true }]
]
}

2 changes: 1 addition & 1 deletion packages/gatsby-plugin-google-tagmanager/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["babel-preset-gatsby-package", { "browser": true }]
["../../.babel-preset.js", { "browser": true }]
]
}

2 changes: 1 addition & 1 deletion packages/gatsby-plugin-guess-js/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["babel-preset-gatsby-package", { "browser": true }]
["../../.babel-preset.js", { "browser": true }]
]
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-jss/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["babel-preset-gatsby-package", { "browser": true }]
["../../.babel-preset.js", { "browser": true }]
]
}

2 changes: 1 addition & 1 deletion packages/gatsby-plugin-layout/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["babel-preset-gatsby-package", { "browser": true }]
["../../.babel-preset.js", { "browser": true }]
]
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-less/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["babel-preset-gatsby-package"]
["../../.babel-preset.js"]
]
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-lodash/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["babel-preset-gatsby-package"]
["../../.babel-preset.js"]
]
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-manifest/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["babel-preset-gatsby-package", { "browser": true }]
["../../.babel-preset.js", { "browser": true }]
]
}

2 changes: 1 addition & 1 deletion packages/gatsby-plugin-netlify-cms/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["babel-preset-gatsby-package", { "browser": true }]
["../../.babel-preset.js", { "browser": true }]
]
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-netlify/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["babel-preset-gatsby-package"]
["../../.babel-preset.js"]
]
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-nprogress/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["babel-preset-gatsby-package", { "browser": true }]
["../../.babel-preset.js", { "browser": true }]
]
}

2 changes: 1 addition & 1 deletion packages/gatsby-plugin-offline/.babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["babel-preset-gatsby-package", { "browser": true }]
["../../.babel-preset.js", { "browser": true }]
]
}

2 changes: 1 addition & 1 deletion packages/gatsby-plugin-page-creator/.babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
presets: [["babel-preset-gatsby-package", { browser: true }]],
presets: [["../../.babel-preset.js", { browser: true }]],
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-postcss/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["babel-preset-gatsby-package"]
["../../.babel-preset.js"]
]
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-preact/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["babel-preset-gatsby-package", { "browser": true }]
["../../.babel-preset.js", { "browser": true }]
]
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-react-css-modules/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"presets": [
["babel-preset-gatsby-package"]
["../../.babel-preset.js"]
]
}

0 comments on commit a392fb4

Please sign in to comment.