Skip to content

Commit cf8bcb2

Browse files
author
邝华
committed
init commit
0 parents  commit cf8bcb2

File tree

156 files changed

+5694
-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.

156 files changed

+5694
-0
lines changed

.env.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VITE_APP_ENV='serve'
2+
VITE_APP_BASE_URL='http://8.135.1.141/micro-service-api'

.env.serve-dev

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VITE_APP_ENV='serve'
2+
VITE_APP_BASE_URL='http://8.135.1.141/micro-service-api'

.env.serve.prod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
REACT_APP_BASE_URL=https://xxxxx
2+
REACT_APP_BASE_URL2=https://xxxxx
3+
REACT_APP_ENV=prod

.eslintignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public
2+
node_modules
3+
.history
4+
.husky
5+
dist
6+
*.d.ts

.eslintrc.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
commonjs: true,
5+
es6: true
6+
},
7+
extends: ['prettier'],
8+
globals: {
9+
$: true,
10+
process: true,
11+
__dirname: true
12+
},
13+
parser: 'babel-eslint',
14+
parserOptions: {
15+
ecmaFeatures: {
16+
experimentalObjectRestSpread: true,
17+
jsx: true
18+
},
19+
sourceType: 'module',
20+
ecmaVersion: 7
21+
},
22+
plugins: ['react'],
23+
rules: {
24+
quotes: [2, 'single'], //单引号
25+
'no-console': 0, //不禁用console
26+
'no-debugger': 2, //禁用debugger
27+
'no-var': 0, //对var警告
28+
semi: 0, //不强制使用分号
29+
30+
'no-irregular-whitespace': 0, //不规则的空白不允许
31+
'no-trailing-spaces': 1, //一行结束后面有空格就发出警告
32+
'eol-last': 0, //文件以单一的换行符结束
33+
'no-unused-vars': 0,
34+
//'no-unused-vars': [2, { vars: 'all', args: 'after-used' }], //不能有声明后未被使用的变量或参数
35+
'no-underscore-dangle': 0, //标识符不能以_开头或结尾
36+
'no-alert': 2, //禁止使用alert confirm prompt
37+
'no-lone-blocks': 0, //禁止不必要的嵌套块
38+
'no-class-assign': 2, //禁止给类赋值
39+
'no-cond-assign': 2, //禁止在条件表达式中使用赋值语句
40+
'no-const-assign': 2, //禁止修改const声明的变量
41+
'no-delete-var': 2, //不能对var声明的变量使用delete操作符
42+
'no-dupe-keys': 2, //在创建对象字面量时不允许键重复
43+
'no-duplicate-case': 2, //switch中的case标签不能重复
44+
'no-dupe-args': 2, //函数参数不能重复
45+
'no-empty': 2, //块语句中的内容不能为空
46+
'no-func-assign': 2, //禁止重复的函数声明
47+
'no-invalid-this': 0, //禁止无效的this,只能用在构造器,类,对象字面量
48+
'no-redeclare': 2, //禁止重复声明变量
49+
'no-spaced-func': 2, //函数调用时 函数名与()之间不能有空格
50+
'no-this-before-super': 0, //在调用super()之前不能使用this或super
51+
'no-undef': 2, //不能有未定义的变量
52+
'no-use-before-define': 2, //未定义前不能使用
53+
camelcase: 0, //强制驼峰法命名
54+
'jsx-quotes': [2, 'prefer-double'], //强制在JSX属性(jsx-quotes)中一致使用双引号
55+
'react/display-name': 0, //防止在React组件定义中丢失displayName
56+
'react/forbid-prop-types': [2, { forbid: ['any'] }], //禁止某些propTypes
57+
'react/jsx-boolean-value': 2, //在JSX中强制布尔属性符号
58+
'react/jsx-closing-bracket-location': 1, //在JSX中验证右括号位置
59+
'react/jsx-curly-spacing': [2, { when: 'never', children: true }], //在JSX属性和表达式中加强或禁止大括号内的空格。
60+
'react/jsx-indent-props': [2, 4], //验证JSX中的props缩进
61+
'react/jsx-key': 2, //在数组或迭代器中验证JSX具有key属性
62+
'react/jsx-max-props-per-line': [1, { maximum: 1 }], // 限制JSX中单行上的props的最大数量
63+
'react/jsx-no-bind': 0, //JSX中不允许使用箭头函数和bind
64+
'react/jsx-no-duplicate-props': 2, //防止在JSX中重复的props
65+
'react/jsx-no-literals': 0, //防止使用未包装的JSX字符串
66+
'react/jsx-no-undef': 1, //在JSX中禁止未声明的变量
67+
'react/jsx-pascal-case': 0, //为用户定义的JSX组件强制使用PascalCase
68+
'react/jsx-sort-props': 2, //强化props按字母排序
69+
'react/jsx-uses-react': 1, //防止反应被错误地标记为未使用
70+
'react/jsx-uses-vars': 2, //防止在JSX中使用的变量被错误地标记为未使用
71+
'react/no-danger': 0, //防止使用危险的JSX属性
72+
'react/no-did-mount-set-state': 0, //防止在componentDidMount中使用setState
73+
'react/no-did-update-set-state': 1, //防止在componentDidUpdate中使用setState
74+
'react/no-direct-mutation-state': 2, //防止this.state的直接变异
75+
'react/no-multi-comp': 2, //防止每个文件有多个组件定义
76+
'react/no-set-state': 0, //防止使用setState
77+
'react/no-unknown-property': 2, //防止使用未知的DOM属性
78+
'react/prefer-es6-class': 2, //为React组件强制执行ES5或ES6类
79+
'react/prop-types': 0, //防止在React组件定义中丢失props验证
80+
'react/react-in-jsx-scope': 2, //使用JSX时防止丢失React
81+
'react/self-closing-comp': 0, //防止没有children的组件的额外结束标签
82+
'react/sort-comp': 2, //强制组件方法顺序
83+
'no-extra-boolean-cast': 0, //禁止不必要的bool转换
84+
'react/no-array-index-key': 0, //防止在数组中遍历中使用数组key做索引
85+
'react/no-deprecated': 1, //不使用弃用的方法
86+
'react/jsx-equals-spacing': 2, //在JSX属性中强制或禁止等号周围的空格
87+
'no-unreachable': 1, //不能有无法执行的代码
88+
'comma-dangle': 2, //对象字面量项尾不能有逗号
89+
'no-mixed-spaces-and-tabs': 0, //禁止混用tab和空格
90+
'prefer-arrow-callback': 0, //比较喜欢箭头回调
91+
'arrow-parens': 0, //箭头函数用小括号括起来
92+
'arrow-spacing': 0 //=>的前/后括号
93+
},
94+
settings: {
95+
'import/ignore': ['node_modules']
96+
}
97+
}

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.history
2+
.idea
3+
node_modules
4+
.DS_Store
5+
dist
6+
dist-ssr
7+
*.local
8+
yarn.lock

.prettierrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"useTabs": false,
3+
"tabWidth": 4,
4+
"printWidth": 120,
5+
"singleQuote": true,
6+
"trailingComma": "none",
7+
"bracketSpacing": true,
8+
"semi": false,
9+
"htmlWhitespaceSensitivity": "ignore"
10+
}

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#### 更新日志
2+
```
3+
4+
```
5+
### 前言
6+
#### 本架构使用的技术为:react17+hooks+vite2 的新一代的react框架,框架使用类似 vue-admin-template
7+
8+
```
9+
框架有js和ts版本
10+
js版本分支:https://github.com/jzfai/react-admin-template.git
11+
ts版本分支:开发中
12+
新一代的微服务架构:https://github.com/jzfai/micro-service-plus
13+
```
14+
15+
> 开发和使用感受:两个字 真香!!!!!
16+
17+
### 效果
18+
19+
### 线上体验地址:http://8.135.1.141/react-admin-template
20+
21+
22+
23+
24+
### 如何运行
25+
26+
```javascript
27+
28+
克隆项目
29+
git clone https://github.com/jzfai/react-admin-template.git
30+
31+
进入项目目录
32+
cd react-admin-template
33+
34+
运行yarn安装依赖
35+
yarn
36+
37+
运行dev命令
38+
yarn run dev
39+
40+
补充:这里说下package.json里的scripts命令
41+
"scripts": {
42+
"dev": "vite --mode serve-dev", ---- 开发时运行
43+
"build": "vite build --mode build", ---- 打包发布生产环境
44+
"serve": "vite preview --mode build" ---- 这个是在你本地打包完后(yarn run build)后会生产一个dist文件夹,这个命令在你本地启动一个本地服务用于查看dist文件内容,发布生产前可以用这个先看下打包的效果
45+
"preview:build": "yarn run build && vite preview " --- 构建并查看(建议更新上product前运行一次,查看是否有问题)
46+
},
47+
```
48+
49+
#####
50+
51+
#### 如果需要实时交流的可以加入wx群(有vue3+ts视频教程)
52+
53+
54+
![http://8.135.1.141/file/images/wx-groud.png](http://8.135.1.141/file/images/wx-groud1.png)
55+
56+
大家的支持是我前进的动力 欢迎加入一起开发

config/env.js

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

config/getHttpsConfig.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const crypto = require('crypto');
6+
const chalk = require('react-dev-utils/chalk');
7+
const paths = require('./paths');
8+
9+
// Ensure the certificate and key provided are valid and if not
10+
// throw an easy to debug error
11+
function validateKeyAndCerts({ cert, key, keyFile, crtFile }) {
12+
let encrypted;
13+
try {
14+
// publicEncrypt will throw an error with an invalid cert
15+
encrypted = crypto.publicEncrypt(cert, Buffer.from('test'));
16+
} catch (err) {
17+
throw new Error(
18+
`The certificate "${chalk.yellow(crtFile)}" is invalid.\n${err.message}`
19+
);
20+
}
21+
22+
try {
23+
// privateDecrypt will throw an error with an invalid key
24+
crypto.privateDecrypt(key, encrypted);
25+
} catch (err) {
26+
throw new Error(
27+
`The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${
28+
err.message
29+
}`
30+
);
31+
}
32+
}
33+
34+
// Read file and throw an error if it doesn't exist
35+
function readEnvFile(file, type) {
36+
if (!fs.existsSync(file)) {
37+
throw new Error(
38+
`You specified ${chalk.cyan(
39+
type
40+
)} in your env, but the file "${chalk.yellow(file)}" can't be found.`
41+
);
42+
}
43+
return fs.readFileSync(file);
44+
}
45+
46+
// Get the https config
47+
// Return cert files if provided in env, otherwise just true or false
48+
function getHttpsConfig() {
49+
const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
50+
const isHttps = HTTPS === 'true';
51+
52+
if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
53+
const crtFile = path.resolve(paths.appPath, SSL_CRT_FILE);
54+
const keyFile = path.resolve(paths.appPath, SSL_KEY_FILE);
55+
const config = {
56+
cert: readEnvFile(crtFile, 'SSL_CRT_FILE'),
57+
key: readEnvFile(keyFile, 'SSL_KEY_FILE'),
58+
};
59+
60+
validateKeyAndCerts({ ...config, keyFile, crtFile });
61+
return config;
62+
}
63+
return isHttps;
64+
}
65+
66+
module.exports = getHttpsConfig;

0 commit comments

Comments
 (0)