Skip to content

Commit 14074f9

Browse files
committed
build(*): init
1 parent 68c11f0 commit 14074f9

17 files changed

+5068
-0
lines changed

.eslintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
lib/*
2+
types/*
3+
dist/*
4+
es/*
5+
public/*

.eslintrc.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
module.exports = {
2+
root: true,
3+
parserOptions: {
4+
ecmaVersion: 12,
5+
sourceType: 'module',
6+
ecmaFeatures: {
7+
jsx: true,
8+
legacyDecorators: true,
9+
},
10+
},
11+
env: {
12+
node: true,
13+
browser: true,
14+
es6: true,
15+
amd: false,
16+
},
17+
globals: {
18+
require: true,
19+
Promise: true,
20+
process: true,
21+
},
22+
rules: {
23+
'prefer-object-spread': [0],
24+
'prefer-destructuring': [1],
25+
'arrow-spacing': 0,
26+
'prefer-promise-reject-errors': [0],
27+
'no-script-url': [0],
28+
'no-alert': [0],
29+
'no-floating-decimal': [1],
30+
'no-mixed-operators': [1],
31+
'no-negated-condition': [0],
32+
'padding-line-between-statements': [0],
33+
'operator-linebreak': [1, 'before'],
34+
'capitalized-comments': [0],
35+
'space-unary-ops': [0],
36+
'import/no-unresolved': [0, 'nerver'],
37+
'import/no-unassigned-import': [0, 'nerver'],
38+
'import/order': [0, 'nerver'],
39+
'no-console': [0],
40+
'new-cap': [
41+
1,
42+
{
43+
newIsCap: true,
44+
capIsNew: false,
45+
},
46+
],
47+
'no-implicit-coercion': [0],
48+
'no-new': [0],
49+
'one-var': [0],
50+
'array-element-newline': [0],
51+
'array-callback-return': [0],
52+
'no-return-assign': [2, 'except-parens'],
53+
'curly': [2, 'multi-line'],
54+
'semi': [0, 'never'],
55+
'no-global-assign': [0],
56+
'eqeqeq': [2],
57+
'no-eval': [2],
58+
'prefer-const': [1],
59+
'no-constant-condition': [1],
60+
'no-unused-expressions': [
61+
1,
62+
{
63+
allowShortCircuit: true,
64+
},
65+
],
66+
'quotes': [2, 'single'],
67+
'quote-props': [2, 'consistent'],
68+
'eol-last': [2, 'always'],
69+
'indent': [
70+
1,
71+
2,
72+
{
73+
SwitchCase: 1,
74+
},
75+
],
76+
'no-cond-assign': [1, 'except-parens'],
77+
'comma-dangle': [2, 'always-multiline'],
78+
'space-infix-ops': [
79+
1,
80+
{
81+
int32Hint: true,
82+
},
83+
],
84+
'object-curly-spacing': [1, 'always'],
85+
'keyword-spacing': [
86+
1,
87+
{
88+
before: true,
89+
after: true,
90+
},
91+
],
92+
},
93+
};

.gitignore

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

babel.config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const babelConfig = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
useBuiltIns: 'entry',
7+
corejs: 2,
8+
},
9+
],
10+
'@babel/preset-react',
11+
],
12+
plugins: [
13+
'@babel/plugin-syntax-dynamic-import',
14+
'@babel/plugin-transform-runtime', // 避免多次编译出helper函数,解决@babel/polyfill提供的类或者实例方法污染全局作用域的情况
15+
'@babel/plugin-proposal-class-properties', // 处理class里面写箭头函数或者装饰器
16+
],
17+
};
18+
19+
module.exports = babelConfig;

mock/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Mock from 'mockjs';
2+
3+
Mock.mock('/api/user', {
4+
'name': '@cname',
5+
'intro': '@word(20)',
6+
});

package.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "react-cli",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "webpack server --config ./webpack.config.js",
8+
"build": "webpack --config ./webpack.config.js"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"devDependencies": {
14+
"@babel/core": "^7.15.0",
15+
"@babel/plugin-proposal-class-properties": "^7.14.5",
16+
"@babel/plugin-transform-runtime": "^7.15.0",
17+
"@babel/preset-env": "^7.15.0",
18+
"@babel/preset-react": "^7.14.5",
19+
"@types/react": "^17.0.19",
20+
"@types/react-dom": "^17.0.9",
21+
"@types/react-router-dom": "^5.1.8",
22+
"autoprefixer": "^10.3.3",
23+
"babel-loader": "^8.2.2",
24+
"core-js": "2.6.5",
25+
"css-loader": "^6.2.0",
26+
"eslint": "^7.32.0",
27+
"file-loader": "^6.2.0",
28+
"html-webpack-plugin": "^5.3.2",
29+
"mini-css-extract-plugin": "^2.2.2",
30+
"mockjs": "^1.1.0",
31+
"postcss": "^8.3.6",
32+
"postcss-loader": "^6.1.1",
33+
"sass-loader": "^12.1.0",
34+
"style-loader": "^3.2.1",
35+
"ts-loader": "^9.2.5",
36+
"typescript": "^4.4.2",
37+
"url-loader": "^4.1.1",
38+
"webpack": "^5.51.1",
39+
"webpack-cli": "^4.8.0",
40+
"webpack-dev-server": "^4.1.0",
41+
"webpack-merge": "^5.8.0"
42+
},
43+
"dependencies": {
44+
"@babel/polyfill": "^7.12.1",
45+
"@babel/runtime-corejs2": "^7.15.3",
46+
"axios": "^0.21.1",
47+
"react": "^17.0.2",
48+
"react-dom": "^17.0.2",
49+
"react-router-dom": "^5.2.1"
50+
},
51+
"browserslist": [
52+
"> 1%",
53+
"last 2 versions"
54+
]
55+
}

postcss.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
plugins: {
3+
plugins: [require('autoprefixer')],
4+
},
5+
}

public/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Document</title>
8+
<script crossorigin src="https://unpkg.com/react@17/umd/react.production.min.js"></script>
9+
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>
10+
</head>
11+
<body>
12+
<div id="app"></div>
13+
</body>
14+
</html>

src/app.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react'
2+
import { Link } from 'react-router-dom'
3+
4+
export default function app() {
5+
return (
6+
<div>
7+
<ul>
8+
<li><Link to="/">首页</Link></li>
9+
<li><Link to="/page">Page</Link></li>
10+
</ul>
11+
</div>
12+
)
13+
}

src/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
import ReactDom from 'react-dom';
3+
import { BrowserRouter as Router } from 'react-router-dom';
4+
import App from './app.js';
5+
import getRouter from './router';
6+
7+
ReactDom.render(
8+
<Router>
9+
<App />
10+
{getRouter()}
11+
</Router>,
12+
document.getElementById('app'),
13+
);

src/pages/a.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
3+
export default function a() {
4+
return <div>a</div>;
5+
}

src/pages/b.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
3+
export default function b() {
4+
return <div>b</div>;
5+
}

src/pages/notfound/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import React from 'react';
2+
3+
export default function index() {
4+
return <div>404</div>;
5+
}

src/router/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React, { lazy, Suspense } from 'react';
2+
import { Route, Switch } from 'react-router';
3+
4+
export default function index() {
5+
const Home = lazy(() => import('../pages/a'));
6+
const Page = lazy(() => import('../pages/b'));
7+
const Notfound = lazy(() => import('../pages/notfound'));
8+
9+
return (
10+
<Suspense fallback={<h1>正在联网获取用户名...</h1>}>
11+
<Switch>
12+
<Route exact path="/" component={Home} />
13+
<Route path="/page" component={Page} />
14+
<Route component={Notfound} />
15+
</Switch>
16+
</Suspense>
17+
);
18+
}

tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "./dist",
4+
"module": "es6",
5+
"target": "es5",
6+
"allowJs": true,
7+
"allowSyntheticDefaultImports": true
8+
}
9+
}

0 commit comments

Comments
 (0)