Skip to content

Commit 2b2628a

Browse files
author
苗园园
committed
fix(fix webpackconfig): fix webpackconfig
fix webpackconfig fix webpackconfig
1 parent c5ce477 commit 2b2628a

26 files changed

+2296
-305
lines changed

.babelrc

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
"stage-0",
66
"react-native-stage-0/decorator-support"
77
],
8-
"plugins": ["transform-decorators-legacy"]
8+
"plugins": [
9+
"transform-decorators-legacy",
10+
"transform-runtime", ["import",{"libraryName":"antd","style":true}]
11+
]
912
}

config/env.js

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// @remove-on-eject-begin
2+
/**
3+
* Copyright (c) 2015-present, Facebook, Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
// @remove-on-eject-end
9+
'use strict';
10+
11+
const fs = require('fs');
12+
const path = require('path');
13+
const paths = require('./paths');
14+
15+
// Make sure that including paths.js after env.js will read .env variables.
16+
delete require.cache[require.resolve('./paths')];
17+
18+
const NODE_ENV = process.env.NODE_ENV;
19+
if (!NODE_ENV) {
20+
throw new Error(
21+
'The NODE_ENV environment variable is required but was not specified.'
22+
);
23+
}
24+
25+
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
26+
var dotenvFiles = [
27+
`${paths.dotenv}.${NODE_ENV}.local`,
28+
`${paths.dotenv}.${NODE_ENV}`,
29+
// Don't include `.env.local` for `test` environment
30+
// since normally you expect tests to produce the same
31+
// results for everyone
32+
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
33+
paths.dotenv,
34+
].filter(Boolean);
35+
36+
// Load environment variables from .env* files. Suppress warnings using silent
37+
// if this file is missing. dotenv will never modify any environment variables
38+
// that have already been set. Variable expansion is supported in .env files.
39+
// https://github.com/motdotla/dotenv
40+
// https://github.com/motdotla/dotenv-expand
41+
dotenvFiles.forEach(dotenvFile => {
42+
if (fs.existsSync(dotenvFile)) {
43+
require('dotenv-expand')(
44+
require('dotenv').config({
45+
path: dotenvFile,
46+
})
47+
);
48+
}
49+
});
50+
51+
// We support resolving modules according to `NODE_PATH`.
52+
// This lets you use absolute paths in imports inside large monorepos:
53+
// https://github.com/facebookincubator/create-react-app/issues/253.
54+
// It works similar to `NODE_PATH` in Node itself:
55+
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
56+
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
57+
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
58+
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
59+
// We also resolve them to make sure all tools using them work consistently.
60+
const appDirectory = fs.realpathSync(process.cwd());
61+
process.env.NODE_PATH = (process.env.NODE_PATH || '')
62+
.split(path.delimiter)
63+
.filter(folder => folder && !path.isAbsolute(folder))
64+
.map(folder => path.resolve(appDirectory, folder))
65+
.join(path.delimiter);
66+
67+
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
68+
// injected into the application via DefinePlugin in Webpack configuration.
69+
const REACT_APP = /^REACT_APP_/i;
70+
71+
function getClientEnvironment(publicUrl) {
72+
const raw = Object.keys(process.env)
73+
.filter(key => REACT_APP.test(key))
74+
.reduce(
75+
(env, key) => {
76+
env[key] = process.env[key];
77+
return env;
78+
},
79+
{
80+
// Useful for determining whether we’re running in production mode.
81+
// Most importantly, it switches React into the correct mode.
82+
NODE_ENV: process.env.NODE_ENV || 'development',
83+
// Useful for resolving the correct path to static assets in `public`.
84+
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
85+
// This should only be used as an escape hatch. Normally you would put
86+
// images into the `src` and `import` them in code to get their paths.
87+
PUBLIC_URL: publicUrl,
88+
}
89+
);
90+
// Stringify all values so we can feed into Webpack DefinePlugin
91+
const stringified = {
92+
'process.env': Object.keys(raw).reduce((env, key) => {
93+
env[key] = JSON.stringify(raw[key]);
94+
return env;
95+
}, {}),
96+
};
97+
98+
return { raw, stringified };
99+
}
100+
101+
module.exports = getClientEnvironment;

config/jest/babelTransform.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @remove-file-on-eject
2+
/**
3+
* Copyright (c) 2014-present, Facebook, Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
'use strict';
9+
10+
const babelJest = require('babel-jest');
11+
12+
module.exports = babelJest.createTransformer({
13+
presets: [require.resolve('../presets')],
14+
babelrc: false,
15+
});

config/jest/cssTransform.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// @remove-on-eject-begin
2+
/**
3+
* Copyright (c) 2014-present, Facebook, Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
// @remove-on-eject-end
9+
'use strict';
10+
11+
// This is a custom Jest transformer turning style imports into empty objects.
12+
// http://facebook.github.io/jest/docs/en/webpack.html
13+
14+
module.exports = {
15+
process() {
16+
return 'module.exports = {};';
17+
},
18+
getCacheKey() {
19+
// The output is always the same.
20+
return 'cssTransform';
21+
},
22+
};

config/jest/fileTransform.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @remove-on-eject-begin
2+
/**
3+
* Copyright (c) 2014-present, Facebook, Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
// @remove-on-eject-end
9+
'use strict';
10+
11+
const path = require('path');
12+
13+
// This is a custom Jest transformer turning file imports into filenames.
14+
// http://facebook.github.io/jest/docs/en/webpack.html
15+
16+
module.exports = {
17+
process(src, filename) {
18+
return `module.exports = ${JSON.stringify(path.basename(filename))};`;
19+
},
20+
};

config/paths.js

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// @remove-on-eject-begin
2+
/**
3+
* Copyright (c) 2015-present, Facebook, Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
// @remove-on-eject-end
9+
'use strict';
10+
11+
const path = require('path');
12+
const fs = require('fs');
13+
const url = require('url');
14+
15+
// Make sure any symlinks in the project folder are resolved:
16+
// https://github.com/facebookincubator/create-react-app/issues/637
17+
const appDirectory = fs.realpathSync(process.cwd());
18+
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
19+
20+
const envPublicUrl = process.env.PUBLIC_URL;
21+
22+
function ensureSlash(path, needsSlash) {
23+
const hasSlash = path.endsWith('/');
24+
if (hasSlash && !needsSlash) {
25+
return path.substr(path, path.length - 1);
26+
} else if (!hasSlash && needsSlash) {
27+
return `${path}/`;
28+
} else {
29+
return path;
30+
}
31+
}
32+
33+
const getPublicUrl = appPackageJson =>
34+
envPublicUrl || require(appPackageJson).homepage;
35+
36+
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
37+
// "public path" at which the app is served.
38+
// Webpack needs to know it to put the right <script> hrefs into HTML even in
39+
// single-page apps that may serve index.html for nested URLs like /todos/42.
40+
// We can't use a relative path in HTML because we don't want to load something
41+
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
42+
function getServedPath(appPackageJson) {
43+
const publicUrl = getPublicUrl(appPackageJson);
44+
const servedUrl =
45+
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
46+
return ensureSlash(servedUrl, true);
47+
}
48+
49+
// config after eject: we're in ./config/
50+
module.exports = {
51+
dotenv: resolveApp('.env'),
52+
appBuild: resolveApp('build'),
53+
appPublic: resolveApp('public'),
54+
appHtml: resolveApp('public/index.html'),
55+
appIndexJs: resolveApp('src/index.js'),
56+
appPackageJson: resolveApp('package.json'),
57+
appSrc: resolveApp('src'),
58+
yarnLockFile: resolveApp('yarn.lock'),
59+
testsSetup: resolveApp('src/setupTests.js'),
60+
appNodeModules: resolveApp('node_modules'),
61+
publicUrl: getPublicUrl(resolveApp('package.json')),
62+
servedPath: getServedPath(resolveApp('package.json')),
63+
};
64+
65+
// @remove-on-eject-begin
66+
const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath);
67+
68+
// config before eject: we're in ./node_modules/react-scripts/config/
69+
module.exports = {
70+
dotenv: resolveApp('.env'),
71+
appPath: resolveApp('.'),
72+
appBuild: resolveApp('build'),
73+
appPublic: resolveApp('public'),
74+
appHtml: resolveApp('public/index.html'),
75+
appIndexJs: resolveApp('src/index.js'),
76+
appPackageJson: resolveApp('package.json'),
77+
appSrc: resolveApp('src'),
78+
yarnLockFile: resolveApp('yarn.lock'),
79+
testsSetup: resolveApp('src/setupTests.js'),
80+
appNodeModules: resolveApp('node_modules'),
81+
publicUrl: getPublicUrl(resolveApp('package.json')),
82+
servedPath: getServedPath(resolveApp('package.json')),
83+
// These properties only exist before ejecting:
84+
ownPath: resolveOwn('.'),
85+
ownNodeModules: resolveOwn('node_modules'), // This is empty on npm 3
86+
};
87+
88+
const ownPackageJson = require('../package.json');
89+
const reactScriptsPath = resolveApp(`node_modules/${ownPackageJson.name}`);
90+
const reactScriptsLinked =
91+
fs.existsSync(reactScriptsPath) &&
92+
fs.lstatSync(reactScriptsPath).isSymbolicLink();
93+
94+
// config before publish: we're in ./packages/react-scripts/config/
95+
if (
96+
!reactScriptsLinked &&
97+
__dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1
98+
) {
99+
module.exports = {
100+
dotenv: resolveOwn('template/.env'),
101+
appPath: resolveApp('.'),
102+
appBuild: resolveOwn('../../build'),
103+
appPublic: resolveOwn('template/public'),
104+
appHtml: resolveOwn('template/public/index.html'),
105+
appIndexJs: resolveOwn('template/src/index.js'),
106+
appPackageJson: resolveOwn('package.json'),
107+
appSrc: resolveOwn('template/src'),
108+
yarnLockFile: resolveOwn('template/yarn.lock'),
109+
testsSetup: resolveOwn('template/src/setupTests.js'),
110+
appNodeModules: resolveOwn('node_modules'),
111+
publicUrl: getPublicUrl(resolveOwn('package.json')),
112+
servedPath: getServedPath(resolveOwn('package.json')),
113+
// These properties only exist before ejecting:
114+
ownPath: resolveOwn('.'),
115+
ownNodeModules: resolveOwn('node_modules'),
116+
};
117+
}
118+
// @remove-on-eject-end

config/polyfills.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @remove-on-eject-begin
2+
/**
3+
* Copyright (c) 2015-present, Facebook, Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
// @remove-on-eject-end
9+
'use strict';
10+
11+
if (typeof Promise === 'undefined') {
12+
// Rejection tracking prevents a common issue where React gets into an
13+
// inconsistent state due to an error, but it gets swallowed by a Promise,
14+
// and the user has no idea what causes React's erratic future behavior.
15+
require('promise/lib/rejection-tracking').enable();
16+
window.Promise = require('promise/lib/es6-extensions.js');
17+
}
18+
19+
// fetch() polyfill for making API calls.
20+
require('whatwg-fetch');
21+
22+
// Object.assign() is commonly used with React.
23+
// It will use the native implementation if it's present and isn't buggy.
24+
Object.assign = require('object-assign');
25+
26+
// In tests, polyfill requestAnimationFrame since jsdom doesn't provide it yet.
27+
// We don't polyfill it in the browser--this is user's responsibility.
28+
if (process.env.NODE_ENV === 'test') {
29+
require('raf').polyfill(global);
30+
}

0 commit comments

Comments
 (0)