Skip to content

Commit 84d8a5e

Browse files
committed
init code
0 parents  commit 84d8a5e

File tree

99 files changed

+32754
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+32754
-0
lines changed

.babelrc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
// 此项指明,转码的规则
3+
"presets": [
4+
[
5+
"@babel/preset-env",
6+
{
7+
"useBuiltIns": "entry"
8+
}
9+
]
10+
],
11+
// 下面这个选项是引用插件来处理代码的转换,transform-runtime用来处理全局函数和优化babel编译
12+
"plugins": [
13+
[
14+
"@babel/plugin-proposal-class-properties",
15+
{
16+
"loose": true
17+
}
18+
]
19+
],
20+
// 下面指的是在生成的文件中,不产生注释
21+
"comments": false,
22+
// 下面这段是在特定的环境中所执行的转码规则,当环境变量是下面的test就会覆盖上面的设置
23+
"env": {
24+
// test 是提前设置的环境变量,如果没有设置BABEL_ENV则使用NODE_ENV,如果都没有设置默认就是development
25+
"test": {
26+
"presets": ["env", "stage-2"],
27+
// instanbul是一个用来测试转码后代码的工具
28+
"plugins": ["istanbul"]
29+
}
30+
}
31+
}

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# See https://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
6+
# testing
7+
/coverage
8+
9+
# production
10+
/build
11+
12+
# misc
13+
.DS_Store
14+
.env.local
15+
.env.development.local
16+
.env.test.local
17+
.env.production.local
18+
19+
npm-debug.log*
20+
yarn-debug.log*
21+
yarn-error.log*

README.md

Lines changed: 2448 additions & 0 deletions
Large diffs are not rendered by default.

config/env.js

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

config/jest/cssTransform.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
// This is a custom Jest transformer turning style imports into empty objects.
4+
// http://facebook.github.io/jest/docs/en/webpack.html
5+
6+
module.exports = {
7+
process() {
8+
return 'module.exports = {};';
9+
},
10+
getCacheKey() {
11+
// The output is always the same.
12+
return 'cssTransform';
13+
},
14+
};

config/jest/fileTransform.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
5+
// This is a custom Jest transformer turning file imports into filenames.
6+
// http://facebook.github.io/jest/docs/en/webpack.html
7+
8+
module.exports = {
9+
process(src, filename) {
10+
return `module.exports = ${JSON.stringify(path.basename(filename))};`;
11+
},
12+
};

config/jest/typescriptTransform.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2004-present Facebook. All Rights Reserved.
2+
3+
'use strict';
4+
5+
const tsJestPreprocessor = require('ts-jest/preprocessor');
6+
7+
module.exports = tsJestPreprocessor;

config/paths.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'use strict';
2+
const path = require('path');
3+
const fs = require('fs');
4+
const url = require('url');
5+
// Make sure any symlinks in the project folder are resolved:
6+
// https://github.com/facebookincubator/create-react-app/issues/637
7+
const appDirectory = fs.realpathSync(process.cwd());
8+
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
9+
const envPublicUrl = process.env.PUBLIC_URL;
10+
function ensureSlash(path, needsSlash) {
11+
const hasSlash = path.endsWith('/');
12+
if (hasSlash && !needsSlash) {
13+
return path.substr(path, path.length - 1);
14+
} else if (!hasSlash && needsSlash) {
15+
return `${path}/`;
16+
} else {
17+
return path;
18+
}
19+
}
20+
const getPublicUrl = appPackageJson =>
21+
envPublicUrl || require(appPackageJson).homepage;
22+
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
23+
// "public path" at which the app is served.
24+
// Webpack needs to know it to put the right <script> hrefs into HTML even in
25+
// single-page apps that may serve index.html for nested URLs like /todos/42.
26+
// We can't use a relative path in HTML because we don't want to load something
27+
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
28+
function getServedPath(appPackageJson) {
29+
const publicUrl = getPublicUrl(appPackageJson);
30+
const servedUrl = envPublicUrl ||
31+
(publicUrl ? url.parse(publicUrl).pathname : '/');
32+
return ensureSlash(servedUrl, true);
33+
}
34+
// config after eject: we're in ./config/
35+
module.exports = {
36+
dotenv: resolveApp('.env'),
37+
appBuild: resolveApp('build'),
38+
appPublic: resolveApp('public'),
39+
appHtml: resolveApp('public/index.html'),
40+
appIndexJs: resolveApp('src/index.tsx'),
41+
appPackageJson: resolveApp('package.json'),
42+
appSrc: resolveApp('src'),
43+
yarnLockFile: resolveApp('yarn.lock'),
44+
testsSetup: resolveApp('src/setupTests.ts'),
45+
appNodeModules: resolveApp('node_modules'),
46+
appTsConfig: resolveApp('tsconfig.json'),
47+
appTsProdConfig: resolveApp('tsconfig.prod.json'),
48+
appTsLint: resolveApp('tslint.json'),
49+
publicUrl: getPublicUrl(resolveApp('package.json')),
50+
servedPath: getServedPath(resolveApp('package.json')),
51+
};

config/polyfills.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
require("@babel/polyfill");
3+
if (typeof Promise === 'undefined') {
4+
// Rejection tracking prevents a common issue where React gets into an
5+
// inconsistent state due to an error, but it gets swallowed by a Promise,
6+
// and the user has no idea what causes React's erratic future behavior.
7+
require('promise/lib/rejection-tracking').enable();
8+
window.Promise = require('promise/lib/es6-extensions.js');
9+
}
10+
Object.setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
11+
o.__proto__ = p;
12+
return o;
13+
};
14+
// fetch() polyfill for making API calls.
15+
require('whatwg-fetch');
16+
// Object.assign() is commonly used with React.
17+
// It will use the native implementation if it's present and isn't buggy.
18+
Object.assign = require('object-assign');
19+
// In tests, polyfill requestAnimationFrame since jsdom doesn't provide it yet.
20+
// We don't polyfill it in the browser--this is user's responsibility.
21+
if (process.env.NODE_ENV === 'test') {
22+
require('raf').polyfill(global);
23+
}

0 commit comments

Comments
 (0)