Skip to content

Commit

Permalink
Clean up package compilation (gatsbyjs#1776)
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense authored and KyleAMathews committed Aug 11, 2017
1 parent 562d58e commit 5a2e035
Show file tree
Hide file tree
Showing 23 changed files with 177 additions and 73 deletions.
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"sourceMaps": true,
"ignore": ["__tests__", "dist"],
"presets": [
"./.babelrc.js"
]
Expand Down
45 changes: 33 additions & 12 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
const r = m => require.resolve(m)

function preset(_, options = {}) {
const PRODUCTION = process.env.NODE_ENV === "production"
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`],
uglify: PRODUCTION,
},
}

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

return {
presets: [
[
r("babel-preset-env"),
{
loose: true,
debug: !!options.debug,
modules: "commonjs",
useBuiltIns: true,
targets: {
node: PRODUCTION ? 4.0 : "current",
uglify: PRODUCTION ? true : false,
Object.assign({
loose: true,
debug: !!debug,
useBuiltIns: true,
modules: "commonjs",
},
},
browser ?
browserConfig :
nodeConfig
)
],
r("babel-preset-react"),
r("babel-preset-flow"),
Expand All @@ -26,7 +45,9 @@ function preset(_, options = {}) {
[
r("babel-plugin-transform-runtime"),
{
polyfill: false,
// we are only polyfilling the node environment
// so we need to enable the runtime replacements for the browser preset
polyfill: !!browser,
},
],
r(`babel-plugin-transform-flow-strip-types`),
Expand Down
12 changes: 2 additions & 10 deletions packages/gatsby-link/.babelrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
{
"presets": [
["env", {
"targets": {
"browsers": ["last 2 versions", "safari >= 7"]
}
}],
"react"
],
"plugins": [
"transform-object-rest-spread",
"transform-flow-strip-types"
["../../.babelrc.js", { "browser": true }]
]
}

6 changes: 6 additions & 0 deletions packages/gatsby-plugin-canonical-urls/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
["../../.babelrc.js", { "browser": true }]
]
}

6 changes: 6 additions & 0 deletions packages/gatsby-plugin-catch-links/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
["../../.babelrc.js", { "browser": true }]
]
}

6 changes: 6 additions & 0 deletions packages/gatsby-plugin-emotion/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
["../../.babelrc.js", { "browser": true }]
]
}

6 changes: 6 additions & 0 deletions packages/gatsby-plugin-feed/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
["../../.babelrc.js", { "browser": true }]
]
}

6 changes: 6 additions & 0 deletions packages/gatsby-plugin-glamor/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
["../../.babelrc.js", { "browser": true }]
]
}

12 changes: 2 additions & 10 deletions packages/gatsby-plugin-google-analytics/.babelrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
{
"presets": [
["env", {
"targets": {
"browsers": ["last 2 versions", "safari >= 7"]
}
}],
"react"
],
"plugins": [
"transform-object-rest-spread",
"transform-flow-strip-types"
["../../.babelrc.js", { "browser": true }]
]
}

12 changes: 2 additions & 10 deletions packages/gatsby-plugin-google-tagmanager/.babelrc
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
{
"presets": [
["env", {
"targets": {
"browsers": ["last 2 versions", "safari >= 7"]
}
}],
"react"
],
"plugins": [
"transform-object-rest-spread",
"transform-flow-strip-types"
["../../.babelrc.js", { "browser": true }]
]
}

6 changes: 6 additions & 0 deletions packages/gatsby-plugin-jss/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
["../../.babelrc.js", { "browser": true }]
]
}

6 changes: 6 additions & 0 deletions packages/gatsby-plugin-manifest/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
["../../.babelrc.js", { "browser": true }]
]
}

6 changes: 6 additions & 0 deletions packages/gatsby-plugin-nprogress/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
["../../.babelrc.js", { "browser": true }]
]
}

6 changes: 6 additions & 0 deletions packages/gatsby-plugin-offline/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
["../../.babelrc.js", { "browser": true }]
]
}

6 changes: 6 additions & 0 deletions packages/gatsby-plugin-react-helmet/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
["../../.babelrc.js", { "browser": true }]
]
}

6 changes: 6 additions & 0 deletions packages/gatsby-plugin-sitemap/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
["../../.babelrc.js", { "browser": true }]
]
}

6 changes: 6 additions & 0 deletions packages/gatsby-plugin-styled-components/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
["../../.babelrc.js", { "browser": true }]
]
}

6 changes: 6 additions & 0 deletions packages/gatsby-plugin-twitter/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
["../../.babelrc.js", { "browser": true }]
]
}

4 changes: 2 additions & 2 deletions packages/gatsby-plugin-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"license": "MIT",
"main": "index.js",
"scripts": {
"build": "babel src --out-dir . --ignore __tests__",
"watch": "babel -w src --out-dir . --ignore __tests__"
"build": "babel src --out-dir .",
"watch": "babel -w src --out-dir ."
}
}
6 changes: 6 additions & 0 deletions packages/gatsby-plugin-typography/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
["../../.babelrc.js", { "browser": true }]
]
}

6 changes: 6 additions & 0 deletions packages/gatsby-remark-autolink-headers/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
["../../.babelrc.js", { "browser": true }]
]
}

5 changes: 5 additions & 0 deletions plop-templates/package/.babelrc.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
["../../.babelrc.js", { "browser": true }]
]
}
69 changes: 40 additions & 29 deletions plopfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,49 @@ module.exports = function(plop) {
name: `author`,
message: `Your name/email for putting in the package.json of the new package`,
},
],
actions: [
{
type: `add`,
path: `packages/{{kebabCase name}}/package.json`,
templateFile: `plop-templates/package/package.json.hbs`,
},
{
type: `add`,
path: `packages/{{kebabCase name}}/index.js`,
templateFile: `plop-templates/package/index.js.hbs`,
},
{
type: `add`,
path: `packages/{{kebabCase name}}/README.md`,
templateFile: `plop-templates/package/README.md.hbs`,
},
{
type: `add`,
path: `packages/{{kebabCase name}}/.gitignore`,
templateFile: `plop-templates/package/.gitignore.hbs`,
},
{
type: `add`,
path: `packages/{{kebabCase name}}/.npmignore`,
templateFile: `plop-templates/package/.npmignore.hbs`,
},
{
type: `add`,
path: `packages/{{kebabCase name}}/src/.gitkeep`,
type: `confirm`,
name: `isBrowser`,
message: `Will this package contain code that runs in a browser, e.g. have a gatsby-browser.js or gatsby-ssr.js file?`,
},
],
actions: (data) =>
[
{
type: `add`,
path: `packages/{{kebabCase name}}/package.json`,
templateFile: `plop-templates/package/package.json.hbs`,
},
{
type: `add`,
path: `packages/{{kebabCase name}}/index.js`,
templateFile: `plop-templates/package/index.js.hbs`,
},
{
type: `add`,
path: `packages/{{kebabCase name}}/README.md`,
templateFile: `plop-templates/package/README.md.hbs`,
},
data.isBrowser && {
type: `add`,
path: `packages/{{kebabCase name}}/.babelrc`,
templateFile: `plop-templates/package/.babelrc.hbs`,
},
{
type: `add`,
path: `packages/{{kebabCase name}}/.gitignore`,
templateFile: `plop-templates/package/.gitignore.hbs`,
},
{
type: `add`,
path: `packages/{{kebabCase name}}/.npmignore`,
templateFile: `plop-templates/package/.npmignore.hbs`,
},
{
type: `add`,
path: `packages/{{kebabCase name}}/src/.gitkeep`,
},
].filter(Boolean),
})
// Add new example site
plop.setGenerator(`example`, {
Expand Down

0 comments on commit 5a2e035

Please sign in to comment.