mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-01-12 22:46:30 +08:00
Remove runtime alias hack (#5142)
* Remove runtime alias hack * Pass absolute path to preset * Change comment * Give a relative path to absolute runtime * Clean up config * Tweak again * Make absolute runtime the default * Remove runtime package from error overlay
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
const validateBoolOption = (name, value, defaultValue) => {
|
||||
if (typeof value === 'undefined') {
|
||||
value = defaultValue;
|
||||
@@ -26,8 +28,21 @@ module.exports = function(api, opts, env) {
|
||||
var isEnvDevelopment = env === 'development';
|
||||
var isEnvProduction = env === 'production';
|
||||
var isEnvTest = env === 'test';
|
||||
|
||||
var isFlowEnabled = validateBoolOption('flow', opts.flow, true);
|
||||
var areHelpersEnabled = validateBoolOption('helpers', opts.helpers, true);
|
||||
var useAbsoluteRuntime = validateBoolOption(
|
||||
'absoluteRuntime',
|
||||
opts.absoluteRuntime,
|
||||
true
|
||||
);
|
||||
|
||||
var absoluteRuntimePath = undefined;
|
||||
if (useAbsoluteRuntime) {
|
||||
absoluteRuntimePath = path.dirname(
|
||||
require.resolve('@babel/runtime/package.json')
|
||||
);
|
||||
}
|
||||
|
||||
if (!isEnvDevelopment && !isEnvProduction && !isEnvTest) {
|
||||
throw new Error(
|
||||
@@ -120,6 +135,10 @@ module.exports = function(api, opts, env) {
|
||||
// We should turn this on once the lowest version of Node LTS
|
||||
// supports ES Modules.
|
||||
useESModules: isEnvDevelopment || isEnvProduction,
|
||||
// Undocumented option that lets us encapsulate our runtime, ensuring
|
||||
// the correct version is used
|
||||
// https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42
|
||||
absoluteRuntime: absoluteRuntimePath,
|
||||
},
|
||||
],
|
||||
isEnvProduction && [
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
const validateBoolOption = (name, value, defaultValue) => {
|
||||
if (typeof value === 'undefined') {
|
||||
value = defaultValue;
|
||||
@@ -33,7 +35,21 @@ module.exports = function(api, opts) {
|
||||
var isEnvDevelopment = env === 'development';
|
||||
var isEnvProduction = env === 'production';
|
||||
var isEnvTest = env === 'test';
|
||||
|
||||
var areHelpersEnabled = validateBoolOption('helpers', opts.helpers, false);
|
||||
var useAbsoluteRuntime = validateBoolOption(
|
||||
'absoluteRuntime',
|
||||
opts.absoluteRuntime,
|
||||
true
|
||||
);
|
||||
|
||||
var absoluteRuntimePath = undefined;
|
||||
if (useAbsoluteRuntime) {
|
||||
absoluteRuntimePath = path.dirname(
|
||||
require.resolve('@babel/runtime/package.json')
|
||||
);
|
||||
}
|
||||
|
||||
if (!isEnvDevelopment && !isEnvProduction && !isEnvTest) {
|
||||
throw new Error(
|
||||
'Using `babel-preset-react-app` requires that you specify `NODE_ENV` or ' +
|
||||
@@ -95,6 +111,10 @@ module.exports = function(api, opts) {
|
||||
// We should turn this on once the lowest version of Node LTS
|
||||
// supports ES Modules.
|
||||
useESModules: isEnvDevelopment || isEnvProduction,
|
||||
// Undocumented option that lets us encapsulate our runtime, ensuring
|
||||
// the correct version is used
|
||||
// https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42
|
||||
absoluteRuntime: absoluteRuntimePath,
|
||||
},
|
||||
],
|
||||
// Adds syntax support for import()
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
"@babel/preset-env": "7.1.0",
|
||||
"@babel/preset-flow": "7.0.0",
|
||||
"@babel/preset-react": "7.0.0",
|
||||
"@babel/runtime": "7.0.0",
|
||||
"babel-loader": "8.0.2",
|
||||
"babel-plugin-macros": "2.4.2",
|
||||
"babel-plugin-transform-dynamic-import": "2.1.0",
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
"devDependencies": {
|
||||
"@babel/code-frame": "7.0.0",
|
||||
"@babel/core": "7.1.0",
|
||||
"@babel/runtime": "7.0.0",
|
||||
"anser": "1.4.7",
|
||||
"babel-core": "7.0.0-bridge.0",
|
||||
"babel-eslint": "9.0.0",
|
||||
|
||||
@@ -144,15 +144,6 @@ module.exports = {
|
||||
// for React Native Web.
|
||||
extensions: ['.web.js', '.js', '.json', '.web.jsx', '.jsx'],
|
||||
alias: {
|
||||
// @remove-on-eject-begin
|
||||
// Resolve Babel runtime relative to react-scripts.
|
||||
// It usually still works on npm 3 without this but it would be
|
||||
// unfortunate to rely on, as react-scripts could be symlinked,
|
||||
// and thus @babel/runtime might not be resolvable from the source.
|
||||
'@babel/runtime': path.dirname(
|
||||
require.resolve('@babel/runtime/package.json')
|
||||
),
|
||||
// @remove-on-eject-end
|
||||
// Support React Native Web
|
||||
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
||||
'react-native': 'react-native-web',
|
||||
|
||||
@@ -199,15 +199,6 @@ module.exports = {
|
||||
// for React Native Web.
|
||||
extensions: ['.web.js', '.js', '.json', '.web.jsx', '.jsx'],
|
||||
alias: {
|
||||
// @remove-on-eject-begin
|
||||
// Resolve Babel runtime relative to react-scripts.
|
||||
// It usually still works on npm 3 without this but it would be
|
||||
// unfortunate to rely on, as react-scripts could be symlinked,
|
||||
// and thus @babel/runtime might not be resolvable from the source.
|
||||
'@babel/runtime': path.dirname(
|
||||
require.resolve('@babel/runtime/package.json')
|
||||
),
|
||||
// @remove-on-eject-end
|
||||
// Support React Native Web
|
||||
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
||||
'react-native': 'react-native-web',
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/core": "7.1.0",
|
||||
"@babel/runtime": "7.0.0",
|
||||
"@svgr/webpack": "2.4.1",
|
||||
"babel-core": "7.0.0-bridge.0",
|
||||
"babel-eslint": "9.0.0",
|
||||
|
||||
Reference in New Issue
Block a user