babel-preset-react-app 3.0.2 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -16,6 +16,12 @@ If you want to use this Babel preset in a project not built with Create React Ap
16
16
 
17
17
  First, [install Babel](https://babeljs.io/docs/setup/).
18
18
 
19
+ Then install babel-preset-react-app.
20
+
21
+ ```sh
22
+ npm install babel-preset-react-app --save-dev
23
+ ```
24
+
19
25
  Then create a file named `.babelrc` with following contents in the root folder of your project:
20
26
 
21
27
  ```js
package/create.js ADDED
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ 'use strict';
8
+
9
+ module.exports = function create(env) {
10
+ if (env !== 'development' && env !== 'test' && env !== 'production') {
11
+ throw new Error(
12
+ 'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' +
13
+ '`BABEL_ENV` environment variables. Valid values are "development", ' +
14
+ '"test", and "production". Instead, received: ' +
15
+ JSON.stringify(env) +
16
+ '.'
17
+ );
18
+ }
19
+
20
+ const plugins = [
21
+ // Necessary to include regardless of the environment because
22
+ // in practice some other transforms (such as object-rest-spread)
23
+ // don't work without it: https://github.com/babel/babel/issues/7215
24
+ require.resolve('babel-plugin-transform-es2015-destructuring'),
25
+ // class { handleClick = () => { } }
26
+ require.resolve('babel-plugin-transform-class-properties'),
27
+ // The following two plugins use Object.assign directly, instead of Babel's
28
+ // extends helper. Note that this assumes `Object.assign` is available.
29
+ // { ...todo, completed: true }
30
+ [
31
+ require.resolve('babel-plugin-transform-object-rest-spread'),
32
+ {
33
+ useBuiltIns: true,
34
+ },
35
+ ],
36
+ // Transforms JSX
37
+ [
38
+ require.resolve('babel-plugin-transform-react-jsx'),
39
+ {
40
+ useBuiltIns: true,
41
+ },
42
+ ],
43
+ // Polyfills the runtime needed for async/await and generators
44
+ [
45
+ require.resolve('babel-plugin-transform-runtime'),
46
+ {
47
+ helpers: false,
48
+ polyfill: false,
49
+ regenerator: true,
50
+ },
51
+ ],
52
+ ];
53
+
54
+ if (env === 'development' || env === 'test') {
55
+ // The following two plugins are currently necessary to make React warnings
56
+ // include more valuable information. They are included here because they are
57
+ // currently not enabled in babel-preset-react. See the below threads for more info:
58
+ // https://github.com/babel/babel/issues/4702
59
+ // https://github.com/babel/babel/pull/3540#issuecomment-228673661
60
+ // https://github.com/facebookincubator/create-react-app/issues/989
61
+ plugins.push.apply(plugins, [
62
+ // Adds component stack to warning messages
63
+ require.resolve('babel-plugin-transform-react-jsx-source'),
64
+ // Adds __self attribute to JSX which React will use for some warnings
65
+ require.resolve('babel-plugin-transform-react-jsx-self'),
66
+ ]);
67
+ }
68
+
69
+ if (env === 'test') {
70
+ return {
71
+ presets: [
72
+ // ES features necessary for user's Node version
73
+ [
74
+ require('babel-preset-env').default,
75
+ {
76
+ targets: {
77
+ node: 'current',
78
+ },
79
+ },
80
+ ],
81
+ // JSX, Flow
82
+ require.resolve('babel-preset-react'),
83
+ ],
84
+ plugins: plugins.concat([
85
+ // Compiles import() to a deferred require()
86
+ require.resolve('babel-plugin-dynamic-import-node'),
87
+ ]),
88
+ };
89
+ } else {
90
+ return {
91
+ presets: [
92
+ // Latest stable ECMAScript features
93
+ [
94
+ require.resolve('babel-preset-env'),
95
+ {
96
+ targets: {
97
+ // React parses on ie 9, so we should too
98
+ ie: 9,
99
+ // We currently minify with uglify
100
+ // Remove after https://github.com/mishoo/UglifyJS2/issues/448
101
+ uglify: true,
102
+ },
103
+ // Disable polyfill transforms
104
+ useBuiltIns: false,
105
+ // Do not transform modules to CJS
106
+ modules: false,
107
+ },
108
+ ],
109
+ // JSX, Flow
110
+ require.resolve('babel-preset-react'),
111
+ ],
112
+ plugins: plugins.concat([
113
+ // function* () { yield 42; yield 43; }
114
+ [
115
+ require.resolve('babel-plugin-transform-regenerator'),
116
+ {
117
+ // Async functions are converted to generators by babel-preset-env
118
+ async: false,
119
+ },
120
+ ],
121
+ // Adds syntax support for import()
122
+ require.resolve('babel-plugin-syntax-dynamic-import'),
123
+ ]),
124
+ };
125
+
126
+ if (env === 'production') {
127
+ // Optimization: hoist JSX that never changes out of render()
128
+ // Disabled because of issues: https://github.com/facebookincubator/create-react-app/issues/553
129
+ // TODO: Enable again when these issues are resolved.
130
+ // plugins.push.apply(plugins, [
131
+ // require.resolve('babel-plugin-transform-react-constant-elements')
132
+ // ]);
133
+ }
134
+ }
135
+ };
package/dev.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ 'use strict';
8
+
9
+ const create = require('./create');
10
+
11
+ module.exports = create('development');
package/index.js CHANGED
@@ -1,42 +1,12 @@
1
1
  /**
2
2
  * Copyright (c) 2015-present, Facebook, Inc.
3
- * All rights reserved.
4
3
  *
5
- * This source code is licensed under the BSD-style license found in the
6
- * LICENSE file in the root directory of this source tree. An additional grant
7
- * of patent rights can be found in the PATENTS file in the same directory.
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
8
6
  */
9
7
  'use strict';
10
8
 
11
- const plugins = [
12
- // class { handleClick = () => { } }
13
- require.resolve('babel-plugin-transform-class-properties'),
14
- // The following two plugins use Object.assign directly, instead of Babel's
15
- // extends helper. Note that this assumes `Object.assign` is available.
16
- // { ...todo, completed: true }
17
- [
18
- require.resolve('babel-plugin-transform-object-rest-spread'),
19
- {
20
- useBuiltIns: true,
21
- },
22
- ],
23
- // Transforms JSX
24
- [
25
- require.resolve('babel-plugin-transform-react-jsx'),
26
- {
27
- useBuiltIns: true,
28
- },
29
- ],
30
- // Polyfills the runtime needed for async/await and generators
31
- [
32
- require.resolve('babel-plugin-transform-runtime'),
33
- {
34
- helpers: false,
35
- polyfill: false,
36
- regenerator: true,
37
- },
38
- ],
39
- ];
9
+ const create = require('./create');
40
10
 
41
11
  // This is similar to how `env` works in Babel:
42
12
  // https://babeljs.io/docs/usage/babelrc/#env-option
@@ -45,94 +15,5 @@ const plugins = [
45
15
  // https://github.com/facebookincubator/create-react-app/issues/720
46
16
  // It’s also nice that we can enforce `NODE_ENV` being specified.
47
17
  var env = process.env.BABEL_ENV || process.env.NODE_ENV;
48
- if (env !== 'development' && env !== 'test' && env !== 'production') {
49
- throw new Error(
50
- 'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' +
51
- '`BABEL_ENV` environment variables. Valid values are "development", ' +
52
- '"test", and "production". Instead, received: ' +
53
- JSON.stringify(env) +
54
- '.'
55
- );
56
- }
57
18
 
58
- if (env === 'development' || env === 'test') {
59
- // The following two plugins are currently necessary to make React warnings
60
- // include more valuable information. They are included here because they are
61
- // currently not enabled in babel-preset-react. See the below threads for more info:
62
- // https://github.com/babel/babel/issues/4702
63
- // https://github.com/babel/babel/pull/3540#issuecomment-228673661
64
- // https://github.com/facebookincubator/create-react-app/issues/989
65
- plugins.push.apply(plugins, [
66
- // Adds component stack to warning messages
67
- require.resolve('babel-plugin-transform-react-jsx-source'),
68
- // Adds __self attribute to JSX which React will use for some warnings
69
- require.resolve('babel-plugin-transform-react-jsx-self'),
70
- ]);
71
- }
72
-
73
- if (env === 'test') {
74
- module.exports = {
75
- presets: [
76
- // ES features necessary for user's Node version
77
- [
78
- require('babel-preset-env').default,
79
- {
80
- targets: {
81
- node: 'current',
82
- },
83
- },
84
- ],
85
- // JSX, Flow
86
- require.resolve('babel-preset-react'),
87
- ],
88
- plugins: plugins.concat([
89
- // Compiles import() to a deferred require()
90
- require.resolve('babel-plugin-dynamic-import-node'),
91
- ]),
92
- };
93
- } else {
94
- module.exports = {
95
- presets: [
96
- // Latest stable ECMAScript features
97
- [
98
- require.resolve('babel-preset-env'),
99
- {
100
- targets: {
101
- // React parses on ie 9, so we should too
102
- ie: 9,
103
- // We currently minify with uglify
104
- // Remove after https://github.com/mishoo/UglifyJS2/issues/448
105
- uglify: true,
106
- },
107
- // Disable polyfill transforms
108
- useBuiltIns: false,
109
- // Do not transform modules to CJS
110
- modules: false,
111
- },
112
- ],
113
- // JSX, Flow
114
- require.resolve('babel-preset-react'),
115
- ],
116
- plugins: plugins.concat([
117
- // function* () { yield 42; yield 43; }
118
- [
119
- require.resolve('babel-plugin-transform-regenerator'),
120
- {
121
- // Async functions are converted to generators by babel-preset-env
122
- async: false,
123
- },
124
- ],
125
- // Adds syntax support for import()
126
- require.resolve('babel-plugin-syntax-dynamic-import'),
127
- ]),
128
- };
129
-
130
- if (env === 'production') {
131
- // Optimization: hoist JSX that never changes out of render()
132
- // Disabled because of issues: https://github.com/facebookincubator/create-react-app/issues/553
133
- // TODO: Enable again when these issues are resolved.
134
- // plugins.push.apply(plugins, [
135
- // require.resolve('babel-plugin-transform-react-constant-elements')
136
- // ]);
137
- }
138
- }
19
+ module.exports = create(env);
package/package.json CHANGED
@@ -1,27 +1,32 @@
1
1
  {
2
2
  "name": "babel-preset-react-app",
3
- "version": "3.0.2",
3
+ "version": "3.1.2",
4
4
  "description": "Babel preset used by Create React App",
5
5
  "repository": "facebookincubator/create-react-app",
6
- "license": "BSD-3-Clause",
6
+ "license": "MIT",
7
7
  "bugs": {
8
8
  "url": "https://github.com/facebookincubator/create-react-app/issues"
9
9
  },
10
10
  "files": [
11
- "index.js"
11
+ "index.js",
12
+ "create.js",
13
+ "dev.js",
14
+ "prod.js",
15
+ "test.js"
12
16
  ],
13
17
  "dependencies": {
14
- "babel-plugin-dynamic-import-node": "1.0.2",
18
+ "babel-plugin-dynamic-import-node": "1.1.0",
15
19
  "babel-plugin-syntax-dynamic-import": "6.18.0",
16
20
  "babel-plugin-transform-class-properties": "6.24.1",
17
- "babel-plugin-transform-object-rest-spread": "6.23.0",
21
+ "babel-plugin-transform-es2015-destructuring": "6.23.0",
22
+ "babel-plugin-transform-object-rest-spread": "6.26.0",
18
23
  "babel-plugin-transform-react-constant-elements": "6.23.0",
19
24
  "babel-plugin-transform-react-jsx": "6.24.1",
20
25
  "babel-plugin-transform-react-jsx-self": "6.22.0",
21
26
  "babel-plugin-transform-react-jsx-source": "6.22.0",
22
- "babel-plugin-transform-regenerator": "6.24.1",
27
+ "babel-plugin-transform-regenerator": "6.26.0",
23
28
  "babel-plugin-transform-runtime": "6.23.0",
24
- "babel-preset-env": "1.5.2",
29
+ "babel-preset-env": "1.6.1",
25
30
  "babel-preset-react": "6.24.1"
26
31
  },
27
32
  "peerDependencies": {
package/prod.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ 'use strict';
8
+
9
+ const create = require('./create');
10
+
11
+ module.exports = create('production');
package/test.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ 'use strict';
8
+
9
+ const create = require('./create');
10
+
11
+ module.exports = create('test');