@qse/edu-scripts 1.14.18 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -487
- package/asset/rspack-dev-server-client.js +534 -0
- package/{src/asset → asset}/template/edu-scripts.override.js.tpl +2 -2
- package/{lib/asset → asset}/template/tailwind.config.js.tpl +1 -1
- package/babel.config.json +6 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +1426 -0
- package/dist/index.d.mts +83 -0
- package/dist/index.mjs +13 -0
- package/eslint.config.mjs +3 -0
- package/{jest.config.js → jest.config.mjs} +8 -4
- package/package.json +52 -58
- package/src/{auto-refactor.js → auto-refactor.ts} +51 -59
- package/src/{build.js → build.ts} +22 -16
- package/src/{cli.js → cli.ts} +25 -21
- package/src/{commit-dist.js → commit-dist.ts} +28 -21
- package/src/config/paths.ts +52 -0
- package/src/config/plugins/mock-server/{index.js → index.ts} +30 -41
- package/src/config/plugins/{postcss-safe-area.js → postcss-safe-area.ts} +4 -2
- package/src/config/{webpackConfig.js → webpackConfig.ts} +152 -126
- package/src/config/{webpackDevServerConfig.js → webpackDevServerConfig.ts} +18 -18
- package/src/{deploy.js → deploy.ts} +36 -25
- package/src/{generator.js → generator.ts} +5 -14
- package/src/start.ts +52 -0
- package/src/utils/FileSizeReporter.ts +166 -0
- package/src/utils/{appConfig.js → appConfig.ts} +5 -4
- package/src/utils/{beforeStart.js → beforeStart.ts} +18 -29
- package/src/utils/{changeDeployVersion.js → changeDeployVersion.ts} +43 -48
- package/src/utils/defineConfig.ts +19 -36
- package/src/utils/{exec.js → exec.ts} +3 -3
- package/src/utils/{getConfig.js → getConfig.ts} +7 -5
- package/src/utils/getOverride.ts +32 -0
- package/src/utils/resolveModule.ts +3 -0
- package/tsconfig.json +3 -15
- package/tsdown.config.ts +5 -0
- package/docs/changelog.md +0 -5
- package/docs/debug.md +0 -17
- package/docs/deploy.md +0 -54
- package/docs/faq.md +0 -144
- package/docs/feat.md +0 -167
- package/docs/grayscale.md +0 -31
- package/docs/index.md +0 -5
- package/docs/mode.md +0 -42
- package/docs/override.md +0 -193
- package/docs/refactor-react-16.md +0 -37
- package/docs/refactor.md +0 -67
- package/docs/static.md +0 -24
- package/lib/asset/template/edu-scripts.override.js.tpl +0 -7
- package/lib/auto-refactor.js +0 -151
- package/lib/build.js +0 -59
- package/lib/cli.js +0 -66
- package/lib/commit-dist.js +0 -79
- package/lib/config/babel.dependencies.js +0 -79
- package/lib/config/babel.js +0 -107
- package/lib/config/paths.js +0 -36
- package/lib/config/plugins/babel-plugin-add-webpack-chunk-name.js +0 -31
- package/lib/config/plugins/mock-server/defineMock.d.ts +0 -6
- package/lib/config/plugins/mock-server/defineMock.js +0 -31
- package/lib/config/plugins/mock-server/index.js +0 -122
- package/lib/config/plugins/postcss-safe-area.js +0 -19
- package/lib/config/plugins/ws-utils-createSocketURL.js +0 -118
- package/lib/config/webpackConfig.js +0 -462
- package/lib/config/webpackDevServerConfig.js +0 -72
- package/lib/deploy.js +0 -143
- package/lib/generator.js +0 -50
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -32
- package/lib/start.js +0 -36
- package/lib/utils/FileSizeReporter.js +0 -107
- package/lib/utils/appConfig.js +0 -32
- package/lib/utils/beforeStart.js +0 -62
- package/lib/utils/changeDeployVersion.js +0 -89
- package/lib/utils/defineConfig.d.ts +0 -93
- package/lib/utils/defineConfig.js +0 -31
- package/lib/utils/exec.js +0 -7
- package/lib/utils/getConfig.js +0 -20
- package/lib/utils/getOverride.js +0 -61
- package/src/asset/dll/libcommon3-manifest.json +0 -181
- package/src/asset/template/edu-app-env.d.ts.tpl +0 -20
- package/src/asset/template/tailwind.config.js.tpl +0 -11
- package/src/asset/template/tsconfig.json.tpl +0 -24
- package/src/config/babel.dependencies.js +0 -66
- package/src/config/babel.js +0 -94
- package/src/config/paths.js +0 -38
- package/src/config/plugins/babel-plugin-add-webpack-chunk-name.js +0 -55
- package/src/config/plugins/ws-utils-createSocketURL.js +0 -140
- package/src/start.js +0 -44
- package/src/utils/FileSizeReporter.js +0 -151
- package/src/utils/getOverride.js +0 -48
- /package/{lib/asset → asset}/dll/libcommon3-manifest.json +0 -0
- /package/{lib/asset → asset}/template/edu-app-env.d.ts.tpl +0 -0
- /package/{lib/asset → asset}/template/tsconfig.json.tpl +0 -0
package/docs/deploy.md
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# 部署 v1
|
|
2
|
-
|
|
3
|
-
项目使用 [@qse/ssh-sftp][1] 部署代码到 v1 环境
|
|
4
|
-
|
|
5
|
-
## 教育模式
|
|
6
|
-
|
|
7
|
-
支持 局端/校端/公文 部署。无需额外的配置即可使用
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
# 局端
|
|
11
|
-
npx edu-scripts deploy -b
|
|
12
|
-
|
|
13
|
-
# 校端
|
|
14
|
-
npx edu-scripts deploy -s
|
|
15
|
-
|
|
16
|
-
# 公文
|
|
17
|
-
npx edu-scripts deploy -d
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## 独立模式
|
|
21
|
-
|
|
22
|
-
### 默认部署
|
|
23
|
-
|
|
24
|
-
默认会部署到 `/qsxxwapdev/${package.name}` 路径下
|
|
25
|
-
|
|
26
|
-
```bash
|
|
27
|
-
npx edu-scripts deploy
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### 自定义部署
|
|
31
|
-
|
|
32
|
-
自定义配置部署路径
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
# 生成配置文件
|
|
36
|
-
npx ssh-sftp init
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
编辑配置文件
|
|
40
|
-
|
|
41
|
-
```json
|
|
42
|
-
{
|
|
43
|
-
"$schema": "http://www.zhidianbao.cn:8088/qsxxwapdev/edu-ssh-sftp/sftprc.schema.json",
|
|
44
|
-
"preset": {
|
|
45
|
-
"context": "qsxxwapdev"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
可以使用预设配置,`npx ssh-sftp show-config` 查看最终的配置
|
|
51
|
-
|
|
52
|
-
其余配置请看 [@qse/ssh-sftp][1]
|
|
53
|
-
|
|
54
|
-
[1]: http://www.zhidianbao.cn:8088/qsxxwapdev/edu-ssh-sftp/
|
package/docs/faq.md
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
# 错误处理
|
|
2
|
-
|
|
3
|
-
## moment 没有 external 掉
|
|
4
|
-
|
|
5
|
-
全局搜索 `moment/locale/zh-cn`,把这些引入都删除掉即可
|
|
6
|
-
|
|
7
|
-
## ueditor 提示 css 文件加载不到
|
|
8
|
-
|
|
9
|
-
移动 `src/ueditor` 到 `public/ueditor`, 导入地址也修改下
|
|
10
|
-
|
|
11
|
-
例子: `require('../../../public/ueditor/<something>')`
|
|
12
|
-
|
|
13
|
-
## style 文件报错
|
|
14
|
-
|
|
15
|
-
```js
|
|
16
|
-
import * as style from './index.less'
|
|
17
|
-
//=> 改成
|
|
18
|
-
import style from './index.less'
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## 如果判断是缺少 `alias` 配置,使用 `npx edu-scripts g override` 生成配置文件,并且配置 `alias` 参数
|
|
22
|
-
|
|
23
|
-
```js
|
|
24
|
-
const { defineConfig } = require('@qse/edu-scripts')
|
|
25
|
-
const path = require('path')
|
|
26
|
-
|
|
27
|
-
module.exports = defineConfig({
|
|
28
|
-
alias: {
|
|
29
|
-
pages: path.resolve('src/pages'),
|
|
30
|
-
},
|
|
31
|
-
})
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## 动态导入 `import`,webpack4 以后 `import` 默认导出改成 `default`
|
|
35
|
-
|
|
36
|
-
```js
|
|
37
|
-
// 以前写法
|
|
38
|
-
import('lodash/get').then((get) => {
|
|
39
|
-
get()
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
// 现在写法
|
|
43
|
-
import('lodash/get').then(({ default: get }) => {
|
|
44
|
-
get()
|
|
45
|
-
})
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
## `react` 组件热更新失效
|
|
49
|
-
|
|
50
|
-
把上面的 `CDN` 加入到首页(index\*.html)中
|
|
51
|
-
|
|
52
|
-
其中 `process.env.NODE_ENV` 那段代码是关键
|
|
53
|
-
|
|
54
|
-
热更新需要 react16,请阅读[升级指南](/refactor-react-16)
|
|
55
|
-
|
|
56
|
-
## 主文件过大,代码分割失效
|
|
57
|
-
|
|
58
|
-
检查是否有 `require('./chunkfile').default` 这种写法,这会导致代码分割失效,直接打进 main 中
|
|
59
|
-
|
|
60
|
-
```js
|
|
61
|
-
export default (callback) => {
|
|
62
|
-
require.ensure([], (require) => {
|
|
63
|
-
// 错误例子
|
|
64
|
-
callback(require('./chunkfile').default)
|
|
65
|
-
|
|
66
|
-
// 正确写法
|
|
67
|
-
const mod = require('./chunkfile')
|
|
68
|
-
callback(mod.default)
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
另外,webpack2 开始就不推荐使用 `require.ensure` 做代码分割了。现在可以使用 `import` 方式代码分割
|
|
74
|
-
|
|
75
|
-
```js
|
|
76
|
-
export default (callback) => {
|
|
77
|
-
import(/* webpackChunkName: 'chunkfileName' */ './chunkfile').then((mod) => {
|
|
78
|
-
callback(mod.default)
|
|
79
|
-
})
|
|
80
|
-
}
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## 子工程不能含有 public/static,现已自动删除
|
|
84
|
-
|
|
85
|
-
子工程不能含有 static 是因为 新建子工程 如果拷贝了主工程代码,那 static 也复制了,打包部署 v1 后可能会覆盖主工程的 static。而且子工程本身就不应该有 static,不可以引入本地外部资源
|
|
86
|
-
|
|
87
|
-
## qsbAntd is not defiend
|
|
88
|
-
|
|
89
|
-
子工程项目如果出现这个错误,引入下面的静态资源
|
|
90
|
-
|
|
91
|
-
```html
|
|
92
|
-
<!-- 确保已经引入 react moment antd -->
|
|
93
|
-
<script src="//www.zhidianbao.cn:8088/qsxxwapdev/edu-scripts/react-dev-preset.js"></script>
|
|
94
|
-
<script src="//www.zhidianbao.cn:8088/qsxxwapdev/edu-scripts/moment2.29.1.js"></script>
|
|
95
|
-
<script src="//www.zhidianbao.cn:8088/qsxxwapdev/edu-scripts/antd3.26.20.js"></script>
|
|
96
|
-
|
|
97
|
-
<!-- 引入 @qsb/antd -->
|
|
98
|
-
<script src="//www.zhidianbao.cn:8088/qsxxwapdev/edu-scripts/qsb-antd.min.js"></script>
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
## 钉钉遇到页面打开白屏
|
|
102
|
-
|
|
103
|
-
这种情况多半是链接中带了 hash,导致页面跳转失败。(复制出来可能是新的链接,但页面其实是老的并未跳转)
|
|
104
|
-
|
|
105
|
-
将下面两段代码分别加入对应的文件中,必须保证其位置在所有 `script` 最前面
|
|
106
|
-
|
|
107
|
-
原理: 将 hash 转存至 localStorage,跳转后再取出
|
|
108
|
-
|
|
109
|
-
```html
|
|
110
|
-
<!-- index.html -->
|
|
111
|
-
<script>
|
|
112
|
-
;(function () {
|
|
113
|
-
var searchString = location.search
|
|
114
|
-
if (!/(\?|&)S=/.test(searchString)) {
|
|
115
|
-
var randomHexString = Math.random().toString(32).substring(2)
|
|
116
|
-
searchString = searchString.substring(1)
|
|
117
|
-
searchString = '?S=' + randomHexString + (searchString.length > 0 ? '&' + searchString : '')
|
|
118
|
-
}
|
|
119
|
-
if (location.hash) {
|
|
120
|
-
localStorage.setItem('qse:H', location.hash)
|
|
121
|
-
}
|
|
122
|
-
var pathnameArr = location.pathname.split('/')
|
|
123
|
-
var pathname = pathnameArr.slice(0, -1).concat('index1.html').join('/')
|
|
124
|
-
var __tmp_URL = location.origin + pathname + searchString
|
|
125
|
-
history.replaceState(null, document.title, __tmp_URL)
|
|
126
|
-
location.reload()
|
|
127
|
-
})()
|
|
128
|
-
</script>
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
```html
|
|
132
|
-
<!-- index1.html -->
|
|
133
|
-
<script>
|
|
134
|
-
;(function () {
|
|
135
|
-
var hash = localStorage.getItem('qse:H')
|
|
136
|
-
if (hash) {
|
|
137
|
-
localStorage.removeItem('qse:H')
|
|
138
|
-
hash = /^#/.test(hash) ? hash : '#' + hash
|
|
139
|
-
var url = location.origin + location.pathname + location.search + hash
|
|
140
|
-
history.replaceState(history.state, null, url)
|
|
141
|
-
}
|
|
142
|
-
})()
|
|
143
|
-
</script>
|
|
144
|
-
```
|
package/docs/feat.md
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
# 特性
|
|
2
|
-
|
|
3
|
-
## svg 模块导出
|
|
4
|
-
|
|
5
|
-
默认导出 `dataURI`,额外导出 `ReactComponent`
|
|
6
|
-
|
|
7
|
-
两种使用方式是相同的
|
|
8
|
-
|
|
9
|
-
```tsx | pure
|
|
10
|
-
import logoURI, { ReactComponent as Logo } from './logo.svg'
|
|
11
|
-
|
|
12
|
-
export default () => (
|
|
13
|
-
<>
|
|
14
|
-
<img src={logoURI} />
|
|
15
|
-
<Logo />
|
|
16
|
-
</>
|
|
17
|
-
)
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## 复制 public 文件
|
|
21
|
-
|
|
22
|
-
`edu-scripts build` 会复制 `public` 或 `public/static` 文件到 `dist` 中
|
|
23
|
-
|
|
24
|
-
教育子工程不会复制
|
|
25
|
-
|
|
26
|
-
## 支持 typescript
|
|
27
|
-
|
|
28
|
-
如果要开启 typescrit,只需要运行 `npx edu g ts`
|
|
29
|
-
|
|
30
|
-
## 生成页面模版
|
|
31
|
-
|
|
32
|
-
可以自动生成页面模版
|
|
33
|
-
|
|
34
|
-
运行 `npx edu g page -h` 查看详细信息
|
|
35
|
-
|
|
36
|
-
## 支持[自定义配置](override.md)
|
|
37
|
-
|
|
38
|
-
运行 `npx edu g override` 生成控制文件
|
|
39
|
-
|
|
40
|
-
## 自动根据 qsb 的 CDN 调整内部配置
|
|
41
|
-
|
|
42
|
-
根据 `public/*.html` 文件里的 CDN 按需自动配置 externals 与 dll
|
|
43
|
-
|
|
44
|
-
### CDN 匹配关键字
|
|
45
|
-
|
|
46
|
-
`/react16.14.*_common31?.js/`
|
|
47
|
-
|
|
48
|
-
- external: `react`, `react-dom`, `natty-fetch`, `natty-store`, `common-utils`
|
|
49
|
-
- 添加内置的 dll 文件
|
|
50
|
-
|
|
51
|
-
`/react16.14.*_axios0.21.1/`
|
|
52
|
-
|
|
53
|
-
- external: `react`, `react-dom`, `natty-fetch`, `natty-store`, `common-utils`, `axios`
|
|
54
|
-
|
|
55
|
-
`moment2.29.1.js`
|
|
56
|
-
|
|
57
|
-
- external: `moment`
|
|
58
|
-
|
|
59
|
-
`antd3.26.20.js`
|
|
60
|
-
|
|
61
|
-
- external: `react`, `react-dom`, `moment`, `antd`
|
|
62
|
-
|
|
63
|
-
如果使用 `antd3.26.20.js` 将额外执行下列规则
|
|
64
|
-
|
|
65
|
-
`qsb-antd.min.js`
|
|
66
|
-
|
|
67
|
-
- external: `@qsb/antd`, `@qse/antd`
|
|
68
|
-
|
|
69
|
-
`qsb-scheme-render.min.js`
|
|
70
|
-
|
|
71
|
-
- external: `@qsb/scheme-render` `@qse/scheme-render`
|
|
72
|
-
|
|
73
|
-
## 支持 tailwindcss
|
|
74
|
-
|
|
75
|
-
如果要开启 tailwindcss,只需要运行 `npx edu g tailwind`
|
|
76
|
-
|
|
77
|
-
## PostCSS
|
|
78
|
-
|
|
79
|
-
预处理很多样式[兼容性问题](https://preset-env.cssdb.org/features/#stage-2)
|
|
80
|
-
|
|
81
|
-
为所有 `overflow: auto/scroll` 自动增加 `-webkit-overflow-scrolling: touch`
|
|
82
|
-
|
|
83
|
-
为所有 `env(safe-area-inset-*)` 增加 fallback
|
|
84
|
-
|
|
85
|
-
## Mock
|
|
86
|
-
|
|
87
|
-
项目内建 mock 服务器,支持热更新,可以在 development 环境下使用
|
|
88
|
-
|
|
89
|
-
mock 功能会根据 mock 文件夹自动判断是否开启
|
|
90
|
-
|
|
91
|
-
可以通过 override.config.js 文件配置 mock 参数关闭该功能
|
|
92
|
-
|
|
93
|
-
### 使用步骤
|
|
94
|
-
|
|
95
|
-
根目录创建 mock 文件夹,在该文件夹下创建的所有 js、ts 文件都会被自动加载,可以创建多层级文件夹
|
|
96
|
-
|
|
97
|
-
```js
|
|
98
|
-
// path: /mock/index.js
|
|
99
|
-
// path: /mock/depth/folder/index.js 支持深层文件
|
|
100
|
-
|
|
101
|
-
import { defineMock } from '@qse/edu-scripts'
|
|
102
|
-
|
|
103
|
-
export default defineMock({
|
|
104
|
-
'GET /api/test/test': { hello: 'world' },
|
|
105
|
-
'GET /api/test/test2': [1, 2, 3],
|
|
106
|
-
'POST /api/test2/test': (req, res) => {
|
|
107
|
-
console.log(req.body, req.cookies)
|
|
108
|
-
res.json({ foo: 'bar' })
|
|
109
|
-
},
|
|
110
|
-
})
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
### mock 规则
|
|
114
|
-
|
|
115
|
-
```ts
|
|
116
|
-
import type { RequestHandler } from 'express'
|
|
117
|
-
type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE'
|
|
118
|
-
type API = string
|
|
119
|
-
|
|
120
|
-
export type MockConfig = Record<
|
|
121
|
-
`${Method} ${API}`,
|
|
122
|
-
string | number | null | undefined | boolean | Record<string, any> | RequestHandler
|
|
123
|
-
>
|
|
124
|
-
|
|
125
|
-
export function defineMock(config: MockConfig) {
|
|
126
|
-
return config
|
|
127
|
-
}
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
mock 名称是由 method 和 apiUrl 组成的,按这种规则去匹配
|
|
131
|
-
|
|
132
|
-
所有 mock 文件最终会被合并到一起,形成一个大的对象。**所以当出现同名的 mock,前面的会被后面的覆盖**
|
|
133
|
-
|
|
134
|
-
可以通过下面的方式去获取参数
|
|
135
|
-
|
|
136
|
-
- `req.body` 获取 body 参数
|
|
137
|
-
- `req.query` 获取链接上的参数
|
|
138
|
-
- `req.cookies` 获取 cookies
|
|
139
|
-
|
|
140
|
-
<Alert>mock 规则比 proxy 具有更高的优先级,如果匹配中了 mock,就会不再去 proxy 了</Alert>
|
|
141
|
-
|
|
142
|
-
```ts
|
|
143
|
-
// path: /mock/index.ts
|
|
144
|
-
import Mock from 'mockjs'
|
|
145
|
-
|
|
146
|
-
export default {
|
|
147
|
-
// method 必须是大写。可以直接返回数据
|
|
148
|
-
'GET /api/test': { hello: 'world' },
|
|
149
|
-
|
|
150
|
-
// 可以通过 express.requestHandler 处理请求。能实现自定义内容,发送文件等
|
|
151
|
-
'POST /api/test2': (req, res) => {
|
|
152
|
-
// 例如:将 body 内容返回
|
|
153
|
-
res.json(req.body)
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
// 可以通过第三方库生成 mock 数据
|
|
157
|
-
'POST /api/test3': Mock.mock({
|
|
158
|
-
// 属性 list 的值是一个数组,其中含有 1 到 10 个元素
|
|
159
|
-
'list|1-10': [
|
|
160
|
-
{
|
|
161
|
-
// 属性 id 是一个自增数,起始值为 1,每次增 1
|
|
162
|
-
'id|+1': 1,
|
|
163
|
-
},
|
|
164
|
-
],
|
|
165
|
-
}),
|
|
166
|
-
}
|
|
167
|
-
```
|
package/docs/grayscale.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# 灰度测试
|
|
2
|
-
|
|
3
|
-
## 开启灰度测试
|
|
4
|
-
|
|
5
|
-
### PC 端
|
|
6
|
-
|
|
7
|
-
前端只要在 `package.json` 文件中加入 `grayscale` 字段即可
|
|
8
|
-
|
|
9
|
-
```json
|
|
10
|
-
{
|
|
11
|
-
"name": "模块名称",
|
|
12
|
-
"edu": { "grayscale": true }
|
|
13
|
-
}
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
此时打包出来的模块就成了灰度测试用的模块,会部署到指定的目录下,主工程会处理调度问题
|
|
17
|
-
|
|
18
|
-
模块名称可与运维讨论
|
|
19
|
-
|
|
20
|
-
后端接口会由 `nginx` 处理,前端不需要关注
|
|
21
|
-
|
|
22
|
-
### H5 端
|
|
23
|
-
|
|
24
|
-
h5 与 pc 是完全不同的方案,前端是需要将代码部署到两个地方。
|
|
25
|
-
|
|
26
|
-
`/project-name` 与 `/beta_project-name`。第二个名字需要去问运维要
|
|
27
|
-
|
|
28
|
-
#### 流程
|
|
29
|
-
|
|
30
|
-
1. 访问 `/qsxxwapdev/project-name/index.html`
|
|
31
|
-
2. 网关拦截 `index.html` 请求,并根据后台灰度配置进行分流,分别进入`/qsxxwapdev/project-name/index1.html` 与 `/qsxxwapdev/beta_project-name/index1.html`
|
package/docs/index.md
DELETED
package/docs/mode.md
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
# 模式
|
|
2
|
-
|
|
3
|
-
目前有三种模式:教育主工程模式,教育子工程模式,独立模式
|
|
4
|
-
|
|
5
|
-
## 教育子工程模式
|
|
6
|
-
|
|
7
|
-
默认情况下使用**教育子工程模式**,无需配置
|
|
8
|
-
|
|
9
|
-
## 教育主工程模式
|
|
10
|
-
|
|
11
|
-
### 启用
|
|
12
|
-
|
|
13
|
-
package.json 增加 mode 字段
|
|
14
|
-
|
|
15
|
-
```json
|
|
16
|
-
{
|
|
17
|
-
"edu": { "mode": "main" }
|
|
18
|
-
}
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## 独立项目模式
|
|
22
|
-
|
|
23
|
-
### 启用
|
|
24
|
-
|
|
25
|
-
package.json 增加 mode 字段
|
|
26
|
-
|
|
27
|
-
```json
|
|
28
|
-
{
|
|
29
|
-
"edu": { "mode": "single" }
|
|
30
|
-
}
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## 共同
|
|
34
|
-
|
|
35
|
-
请查看[特性](feat.md)
|
|
36
|
-
|
|
37
|
-
## 差异
|
|
38
|
-
|
|
39
|
-
| 差异点 | 子工程 | 主工程 | 独立 |
|
|
40
|
-
| ---------------------- | ---------------------------------------- | --------------------------------------------- | --------------------------------------------------------------------------------------- |
|
|
41
|
-
| 打包 build | 不复制 `public`,不导出 `html` 文件 | 复制 `public/static` 文件夹,导出 `html` 文件 | 复制 `public` 文件夹,导出 `html` 文件,且输出的 `output.filename` 会添加 `contenthash` |
|
|
42
|
-
| [部署 deploy](deploy.md) | 只上传 `dist/js、dist/images` 两个文件夹 | 上传 `dist` | 同主工程 |
|
package/docs/override.md
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
# 自定义配置
|
|
2
|
-
|
|
3
|
-
使用 `npx edu g override` 自动生成配置文件,修改 `webpack` 配置
|
|
4
|
-
|
|
5
|
-
## 类型
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
export type Config = {
|
|
9
|
-
webpack?: (config: Configuration) => Configuration | undefined
|
|
10
|
-
devServer?: (config: DevServerConfiguration) => DevServerConfiguration | undefined
|
|
11
|
-
babel?: (config: any, type: 'src' | 'node_modules') => any | undefined
|
|
12
|
-
/**
|
|
13
|
-
* webpack alias 配置,会与内置 alias 合并
|
|
14
|
-
*
|
|
15
|
-
* @default
|
|
16
|
-
* { '@': 'src' }
|
|
17
|
-
*/
|
|
18
|
-
alias?: Record<string, string>
|
|
19
|
-
/**
|
|
20
|
-
* webpack externals 配置,会与内置 externals 合并
|
|
21
|
-
*/
|
|
22
|
-
externals?: Record<string, string>
|
|
23
|
-
/**
|
|
24
|
-
* terser pure_funcs 配置,传 [] 可以不清空 console.log
|
|
25
|
-
* @default ['console.log']
|
|
26
|
-
*/
|
|
27
|
-
pure_funcs?: string[]
|
|
28
|
-
/**
|
|
29
|
-
* 编译 node_modules 下文件
|
|
30
|
-
*
|
|
31
|
-
* 仅在 development 环境下生效。production 一定会编译 node_modules
|
|
32
|
-
* @default true
|
|
33
|
-
*/
|
|
34
|
-
transformNodeModules?: boolean
|
|
35
|
-
/**
|
|
36
|
-
* 指定压缩工具,esbuild 比 terser 快 20-40 倍,实际压缩率差 10%左右
|
|
37
|
-
*
|
|
38
|
-
* @default 'esbuild'
|
|
39
|
-
*/
|
|
40
|
-
minify?: boolean | 'terser' | 'esbuild'
|
|
41
|
-
/** 自定义全局参数 */
|
|
42
|
-
define?: Record<string, any>
|
|
43
|
-
/** webpack-dev-server proxy
|
|
44
|
-
*
|
|
45
|
-
* @default /api -> /qsxxwapdev/api
|
|
46
|
-
*/
|
|
47
|
-
proxy?: ProxyConfigArray
|
|
48
|
-
extraPostCSSPlugins?: any[]
|
|
49
|
-
/**
|
|
50
|
-
* 开启 mock 功能,会自动加载 mock 文件夹下的文件
|
|
51
|
-
*
|
|
52
|
-
* 默认情况下自动判断根目录是否存在 mock 文件夹,如果存在则开启 mock 功能。
|
|
53
|
-
* 如果设置 false,会关闭 mock 功能
|
|
54
|
-
*/
|
|
55
|
-
mock?: boolean
|
|
56
|
-
}
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## 经典用例
|
|
60
|
-
|
|
61
|
-
### 增加 alias
|
|
62
|
-
|
|
63
|
-
```js
|
|
64
|
-
const { defineConfig } = require('@qse/edu-scripts')
|
|
65
|
-
const path = require('path')
|
|
66
|
-
|
|
67
|
-
module.exports = defineConfig({
|
|
68
|
-
alias: {
|
|
69
|
-
config: path.resolve(__dirname, 'src/config'),
|
|
70
|
-
},
|
|
71
|
-
})
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### 保留 `console.log`
|
|
75
|
-
|
|
76
|
-
```js
|
|
77
|
-
const { defineConfig } = require('@qse/edu-scripts')
|
|
78
|
-
|
|
79
|
-
module.exports = defineConfig({
|
|
80
|
-
pure_funcs: [],
|
|
81
|
-
})
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### 增加 proxy 代理
|
|
85
|
-
|
|
86
|
-
```js
|
|
87
|
-
const { defineConfig } = require('@qse/edu-scripts')
|
|
88
|
-
|
|
89
|
-
module.exports = defineConfig({
|
|
90
|
-
proxy: [
|
|
91
|
-
{
|
|
92
|
-
context: ['/api/cadre_info'],
|
|
93
|
-
target: 'http://www.zhidianbao.cn:8088/qs_ymm/standard_api_work',
|
|
94
|
-
changeOrigin: true,
|
|
95
|
-
headers: {
|
|
96
|
-
origin: 'http://www.zhidianbao.cn',
|
|
97
|
-
host: 'www.zhidianbao.cn',
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
],
|
|
101
|
-
})
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### 为 antd-mobile 增加 pxtorem 插件
|
|
105
|
-
|
|
106
|
-
适用范围:antd-mobile@2, antd-mobile@5
|
|
107
|
-
|
|
108
|
-
安装公司内专用的 pxtorem 插件,比原版增加了 include 与 CSS 变量 编译。并且修改默认值 `1rem === 10px`
|
|
109
|
-
|
|
110
|
-
```bash
|
|
111
|
-
npm i @qse/postcss-pxtorem
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
```js
|
|
115
|
-
const { defineConfig } = require('@qse/edu-scripts')
|
|
116
|
-
const pxtorem = require('@qse/postcss-pxtorem')
|
|
117
|
-
|
|
118
|
-
module.exports = defineConfig({
|
|
119
|
-
extraPostCSSPlugins: [pxtorem({ include: ['antd-mobile'] })],
|
|
120
|
-
})
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
> 可选:添加动态计算 html rem 值
|
|
124
|
-
|
|
125
|
-
```html
|
|
126
|
-
<script>
|
|
127
|
-
;(function (designWidth, base, max) {
|
|
128
|
-
var docEl = document.documentElement
|
|
129
|
-
var metaEl = document.querySelector('meta[name="viewport"]')
|
|
130
|
-
|
|
131
|
-
var resize = function () {
|
|
132
|
-
var maxFontSize = Infinity
|
|
133
|
-
if (max) {
|
|
134
|
-
var scale = 1
|
|
135
|
-
var match = metaEl.getAttribute('content').match(/initial\-scale=([\d\.]+)/)
|
|
136
|
-
var isMobile = /iphone|ipad|ipod|Windows Phone|android/i.test(navigator.userAgent)
|
|
137
|
-
if (match && isMobile) {
|
|
138
|
-
scale = parseFloat(match[1])
|
|
139
|
-
}
|
|
140
|
-
maxFontSize = max / scale
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
var clientWidth = docEl.clientWidth ? docEl.clientWidth : docEl.getBoundingClientRect().width
|
|
144
|
-
|
|
145
|
-
docEl.style.setProperty(
|
|
146
|
-
'font-size',
|
|
147
|
-
Math.min((clientWidth / designWidth) * base, maxFontSize) + 'px',
|
|
148
|
-
'important'
|
|
149
|
-
)
|
|
150
|
-
}
|
|
151
|
-
resize()
|
|
152
|
-
window.addEventListener('resize', resize)
|
|
153
|
-
})(375, 16, 16)
|
|
154
|
-
</script>
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
### 为 antd-mobile@2 增加按需加载
|
|
158
|
-
|
|
159
|
-
只能给 antd-mobile@2 使用。antd-mobile@5 自带 tree shake 不需要配置
|
|
160
|
-
|
|
161
|
-
```js
|
|
162
|
-
const { defineConfig } = require('@qse/edu-scripts')
|
|
163
|
-
|
|
164
|
-
module.exports = defineConfig({
|
|
165
|
-
babel(config) {
|
|
166
|
-
config.plugins.push(['import', { libraryName: 'antd-mobile', style: true }, 'antd-mobile'])
|
|
167
|
-
},
|
|
168
|
-
})
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
### 兼容 antd-mobile@1
|
|
172
|
-
|
|
173
|
-
安装 `svg-sprite-loader` 模块,复制下面的代码
|
|
174
|
-
|
|
175
|
-
```shell
|
|
176
|
-
npm i svg-sprite-loader
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
```js
|
|
180
|
-
const { defineConfig } = require('@qse/edu-scripts')
|
|
181
|
-
module.exports = defineConfig({
|
|
182
|
-
webpack(config) {
|
|
183
|
-
config.module.rules[0].oneOf.unshift({
|
|
184
|
-
test: /\.svg$/,
|
|
185
|
-
loader: 'svg-sprite-loader',
|
|
186
|
-
options: {
|
|
187
|
-
esModule: false,
|
|
188
|
-
runtimeCompat: true,
|
|
189
|
-
},
|
|
190
|
-
})
|
|
191
|
-
},
|
|
192
|
-
})
|
|
193
|
-
```
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# 升级 react16
|
|
2
|
-
|
|
3
|
-
frame 项目 react15 升级 react16 指南
|
|
4
|
-
|
|
5
|
-
## 事前准备
|
|
6
|
-
|
|
7
|
-
准备适配 common3 的 frame 与 utils
|
|
8
|
-
|
|
9
|
-
- pc: [pc-frame-utils.zip](http://www.zhidianbao.cn:8088/qsxxwapdev/edu-scripts/pc-frame-utils.zip)
|
|
10
|
-
- h5: [h5-frame-utils.zip](http://www.zhidianbao.cn:8088/qsxxwapdev/edu-scripts/h5-frame-utils.zip)
|
|
11
|
-
|
|
12
|
-
## 开始升级
|
|
13
|
-
|
|
14
|
-
1. 先提交所有内容至svn,方便回退
|
|
15
|
-
2. 解压下载的文件,将 frame 与 utils 放到对应目录
|
|
16
|
-
3. 修改 html 文件中 frame 与 utils 的版本号,引入正确的资源
|
|
17
|
-
4. 替换 CDN 资源
|
|
18
|
-
|
|
19
|
-
```html
|
|
20
|
-
<script src="//static.qsepay.net/lib/react15.4.1_fastclick1.0.6_natty-storage2.0.2-fetch2.4.2_common2.js"></script>
|
|
21
|
-
|
|
22
|
-
将上面这条 CDN 替换成下面这条
|
|
23
|
-
|
|
24
|
-
<script src="//static.qsepay.net/lib/react16.14_fastclick1.0.6_natty-storage2.0.2-fetch2.4.2_axios0.21.1_common31.js"></script>
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
5. 运行项目看看效果
|
|
28
|
-
|
|
29
|
-
## 错误处理
|
|
30
|
-
|
|
31
|
-
### refast LogicRender 缺失
|
|
32
|
-
|
|
33
|
-
删除全部的 `LogicRender`,使用*三元表达式*处理
|
|
34
|
-
|
|
35
|
-
### prop-types 缺失
|
|
36
|
-
|
|
37
|
-
react16 将 prop-types 独立了出去,请下载 prop-types 包,修改导入
|