Skip to content

Commit 0748c2a

Browse files
authored
Refactor babel config (bvaughn#1019)
Refactor babel config
1 parent 8b6b911 commit 0748c2a

File tree

4 files changed

+64
-359
lines changed

4 files changed

+64
-359
lines changed

.babelrc

Lines changed: 0 additions & 102 deletions
This file was deleted.

.babelrc.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const env = process.env.NODE_ENV;
2+
3+
if (env === 'commonjs' || env === 'es') {
4+
module.exports = {
5+
ignore: [
6+
'*.jest.js',
7+
'*.e2e.js',
8+
'*.ssr.js',
9+
'*.example.js',
10+
'source/demo',
11+
'source/jest-*.js',
12+
'source/TestUtils.js',
13+
],
14+
plugins: [
15+
'transform-runtime',
16+
['flow-react-proptypes', {deadCode: true}],
17+
['transform-react-remove-prop-types', {mode: 'wrap'}],
18+
],
19+
presets: [['env', {modules: false}], 'react', 'flow', 'stage-2'],
20+
};
21+
22+
if (env === 'commonjs') {
23+
module.exports.plugins.push('transform-es2015-modules-commonjs');
24+
}
25+
}
26+
27+
if (env === 'development') {
28+
module.exports = {
29+
presets: ['react', 'flow', 'stage-2'],
30+
};
31+
}
32+
33+
if (env === 'production') {
34+
module.exports = {
35+
comments: false,
36+
plugins: ['transform-runtime'],
37+
presets: ['env', 'react', 'flow', 'stage-2'],
38+
};
39+
}
40+
41+
if (env === 'test') {
42+
module.exports = {
43+
comments: false,
44+
plugins: ['transform-es2015-modules-commonjs'],
45+
presets: ['react', 'flow', 'stage-2'],
46+
};
47+
}

package.json

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
"scripts": {
1313
"build:types": "flow-copy-source --ignore \"**/*.{jest,e2e,ssr,example}.js\" source/WindowScroller dist/es/WindowScroller && flow-copy-source --ignore \"**/*.{jest,e2e,ssr,example}.js\" source/AutoSizer dist/es/AutoSizer ",
1414
"build": "npm run build:commonjs && npm run build:css && npm run build:es && npm run build:demo && npm run build:umd",
15-
"build:commonjs": "npm run clean:commonjs && cross-env NODE_ENV=production cross-env BABEL_ENV=commonjs babel source --out-dir dist/commonjs",
15+
"build:commonjs": "npm run clean:commonjs && cross-env NODE_ENV=commonjs babel source --out-dir dist/commonjs",
1616
"build:css": "postcss source/styles.css -o styles.css --use autoprefixer",
1717
"build:demo": "npm run clean:demo && cross-env NODE_ENV=production webpack --config webpack.config.demo.js -p --bail",
18-
"build:es": "npm run clean:es && npm run build:types && cross-env NODE_ENV=production cross-env BABEL_ENV=es babel source --out-dir dist/es",
18+
"build:es": "npm run clean:es && npm run build:types && cross-env NODE_ENV=es babel source --out-dir dist/es",
1919
"build:umd": "npm run clean:umd && cross-env NODE_ENV=production webpack --config webpack.config.umd.js --bail",
2020
"check-all": "yarn prettier && yarn lint && yarn flow",
2121
"ci-check": "yarn prettier:diff && yarn lint && yarn flow",
@@ -32,13 +32,18 @@
3232
"prettier:diff": "prettier --list-different '{playground,source}/**/*.js'",
3333
"postpublish": "npm run deploy",
3434
"prepublish": "npm run build",
35-
"start": "webpack-dev-server --hot --config webpack.config.dev.js",
35+
"start": "cross-env NODE_ENV=development webpack-dev-server --hot --config webpack.config.dev.js",
3636
"test": "npm run test:jest",
3737
"test:jest": "jest --no-watchman --runInBand",
3838
"test:ci": "jest --no-watchman --maxWorkers 2 --coverage && codecov",
3939
"watch": "watch 'clear && npm run test -s' source",
4040
"watch:jest": "jest --no-watchman --watch"
4141
},
42+
"babel": {
43+
"presets": [
44+
"./.babelrc.js"
45+
]
46+
},
4247
"files": [
4348
"dist",
4449
"styles.css"
@@ -98,15 +103,14 @@
98103
"babel-jest": "^22.0.4",
99104
"babel-loader": "7.1.2",
100105
"babel-plugin-flow-react-proptypes": "^13.0.0",
101-
"babel-plugin-react-transform": "^3.0.0",
106+
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
102107
"babel-plugin-transform-react-remove-prop-types": "^0.4.12",
103108
"babel-plugin-transform-runtime": "^6.23.0",
104109
"babel-polyfill": "^6.26.0",
105110
"babel-preset-env": "^1.6.1",
106111
"babel-preset-flow": "^6.23.0",
107112
"babel-preset-react": "^6.24.1",
108-
"babel-preset-stage-1": "^6.24.1",
109-
"bluebird": "^3.0.5",
113+
"babel-preset-stage-2": "^6.24.1",
110114
"codecov": "^2.2.0",
111115
"codemirror": "^5.18.0",
112116
"cross-env": "^5.0.1",
@@ -121,12 +125,10 @@
121125
"eslint-plugin-prettier": "^2.4.0",
122126
"eslint-plugin-react": "^7.5.1",
123127
"eslint-plugin-relay": "^0.0.20",
124-
"express": "^4.13.3",
125128
"extract-text-webpack-plugin": "^3.0.2",
126129
"file-loader": "^1.1.6",
127130
"flow-bin": "^0.63.1",
128131
"flow-copy-source": "^1.2.1",
129-
"fs-extra": "^4.0.0",
130132
"gh-pages": "^1.0.0",
131133
"html-webpack-plugin": "^2.30.1",
132134
"husky": "^0.14.3",
@@ -144,9 +146,6 @@
144146
"react-dom": "^16.0.0",
145147
"react-router": "^4.1.1",
146148
"react-router-dom": "^4.1.1",
147-
"react-transform-catch-errors": "^1.0.2",
148-
"react-transform-hmr": "^1.0.2",
149-
"redbox-react": "^1.4.3",
150149
"rimraf": "^2.4.3",
151150
"style-loader": "^0.19.1",
152151
"watch": "^1.0.2",

0 commit comments

Comments
 (0)