@qse/edu-scripts 0.0.0-beta.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 +5 -0
- package/README.md +107 -0
- package/app.d.ts +73 -0
- package/babel.config.json +3 -0
- package/docs/.vitepress/config.ts +35 -0
- package/docs/changelog.md +1 -0
- package/docs/debug.md +17 -0
- package/docs/deploy.md +54 -0
- package/docs/faq.md +144 -0
- package/docs/feat.md +167 -0
- package/docs/grayscale.md +31 -0
- package/docs/index.md +15 -0
- package/docs/install.md +1 -0
- package/docs/mode.md +42 -0
- package/docs/override.md +193 -0
- package/docs/refactor-react-16.md +37 -0
- package/docs/refactor.md +67 -0
- package/docs/static.md +24 -0
- package/es/asset/dll/libcommon3-manifest.json +181 -0
- package/es/asset/template/edu-app-env.d.ts.tpl +20 -0
- package/es/asset/template/edu-scripts.override.js.tpl +7 -0
- package/es/asset/template/tailwind.config.js.tpl +11 -0
- package/es/asset/template/tsconfig.json.tpl +24 -0
- package/es/auto-refactor.js +153 -0
- package/es/build.js +58 -0
- package/es/cli.js +65 -0
- package/es/commit-dist.js +83 -0
- package/es/config/paths.js +39 -0
- package/es/config/plugins/mock-server/defineMock.d.ts +6 -0
- package/es/config/plugins/mock-server/defineMock.js +7 -0
- package/es/config/plugins/mock-server/index.js +122 -0
- package/es/config/plugins/postcss-safe-area.js +22 -0
- package/es/config/plugins/ws-utils-createSocketURL.js +98 -0
- package/es/config/webpackConfig.js +418 -0
- package/es/config/webpackDevServerConfig.js +73 -0
- package/es/deploy.js +148 -0
- package/es/generator.js +52 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +7 -0
- package/es/start.js +36 -0
- package/es/utils/FileSizeReporter.js +107 -0
- package/es/utils/appConfig.js +35 -0
- package/es/utils/beforeStart.js +51 -0
- package/es/utils/changeDeployVersion.js +85 -0
- package/es/utils/defineConfig.d.ts +76 -0
- package/es/utils/defineConfig.js +7 -0
- package/es/utils/exec.js +10 -0
- package/es/utils/getConfig.js +23 -0
- package/es/utils/getOverride.js +28 -0
- package/eslint.config.mjs +3 -0
- package/jest.config.mjs +199 -0
- package/package.json +95 -0
- package/src/asset/dll/libcommon3-manifest.json +181 -0
- package/src/asset/template/edu-app-env.d.ts.tpl +20 -0
- package/src/asset/template/edu-scripts.override.js.tpl +7 -0
- package/src/asset/template/tailwind.config.js.tpl +11 -0
- package/src/asset/template/tsconfig.json.tpl +24 -0
- package/src/auto-refactor.js +170 -0
- package/src/build.js +64 -0
- package/src/cli.js +88 -0
- package/src/commit-dist.js +103 -0
- package/src/config/paths.js +38 -0
- package/src/config/plugins/mock-server/defineMock.ts +12 -0
- package/src/config/plugins/mock-server/index.js +150 -0
- package/src/config/plugins/postcss-safe-area.js +21 -0
- package/src/config/plugins/ws-utils-createSocketURL.js +140 -0
- package/src/config/webpackConfig.js +444 -0
- package/src/config/webpackDevServerConfig.js +83 -0
- package/src/deploy.js +182 -0
- package/src/generator.js +67 -0
- package/src/index.ts +2 -0
- package/src/start.js +37 -0
- package/src/utils/FileSizeReporter.js +148 -0
- package/src/utils/appConfig.js +36 -0
- package/src/utils/beforeStart.js +55 -0
- package/src/utils/changeDeployVersion.js +119 -0
- package/src/utils/defineConfig.ts +81 -0
- package/src/utils/exec.js +7 -0
- package/src/utils/getConfig.js +26 -0
- package/src/utils/getOverride.js +33 -0
- package/tsconfig.json +21 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# 教育工程化基础框架
|
|
2
|
+
|
|
3
|
+
svn://192.168.10.168/edu/code/A0.New-system/0A2.front-end-component/edu-scripts/trunk
|
|
4
|
+
|
|
5
|
+
<Alert>内网里的 @qsb/edu-scripts 已经弃用,请更换成公网的 @qse/edu-scripts </Alert>
|
|
6
|
+
|
|
7
|
+
## 运行条件
|
|
8
|
+
|
|
9
|
+
nodejs 版本至少 12+
|
|
10
|
+
|
|
11
|
+
## 快速体验
|
|
12
|
+
|
|
13
|
+
执行下面的命令,快速建立一个最小的应用模版,支持 [教育集成 与 独立项目模式](/mode)
|
|
14
|
+
|
|
15
|
+
```shell
|
|
16
|
+
# npm 安装
|
|
17
|
+
npm create @qse/edu-app@latest
|
|
18
|
+
|
|
19
|
+
# 或者 yarn 安装
|
|
20
|
+
yarn create @qse/edu-app@latest
|
|
21
|
+
|
|
22
|
+
# 或者 pnpm 安装
|
|
23
|
+
pnpm create @qse/edu-app@latest
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 安装
|
|
27
|
+
|
|
28
|
+
<Alert>第一次使用这个框架,请看<Link to="/refactor">老项目接入流程</Link></Alert>
|
|
29
|
+
|
|
30
|
+
```shell
|
|
31
|
+
npm i @qse/edu-scripts -D
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 用法
|
|
35
|
+
|
|
36
|
+
`edu-scripts` 可以使用缩写 `edu`,在手写命令行时方便使用
|
|
37
|
+
|
|
38
|
+
```shell
|
|
39
|
+
# 开发
|
|
40
|
+
edu-scripts start
|
|
41
|
+
# 开发指定端口 默认3000
|
|
42
|
+
edu-scripts start --port 5000
|
|
43
|
+
|
|
44
|
+
# 打包
|
|
45
|
+
edu-scripts build
|
|
46
|
+
# 打包并分析
|
|
47
|
+
edu-scripts build --analyze
|
|
48
|
+
# 打包并导出 html 文件
|
|
49
|
+
edu-scripts build --output-html
|
|
50
|
+
|
|
51
|
+
# 部署代码 校端
|
|
52
|
+
edu-scripts deploy -s
|
|
53
|
+
# 部署代码 局端
|
|
54
|
+
edu-scripts deploy -b
|
|
55
|
+
# 部署代码 公文端
|
|
56
|
+
edu-scripts deploy -d
|
|
57
|
+
# 部署代码 校端 + 局端 + 公文端
|
|
58
|
+
edu-scripts deploy -s -b -d
|
|
59
|
+
|
|
60
|
+
# 生成 override 文件
|
|
61
|
+
edu-scripts generator override
|
|
62
|
+
# 自动生成代码 可使用 npx edu-scripts generator page -h 查看具体效果
|
|
63
|
+
edu-scripts generator page --name <module-name>
|
|
64
|
+
# 生成 tailwind 配置
|
|
65
|
+
edu-scripts generator tailwind
|
|
66
|
+
# 生成 tsconfig 配置
|
|
67
|
+
edu-scripts generator ts
|
|
68
|
+
|
|
69
|
+
# SVN 提交 dist 到 dist 分支上
|
|
70
|
+
edu-scripts commit-dist
|
|
71
|
+
# SVN 提交 dist 到 dist 分支上,并且删除本地 dist
|
|
72
|
+
edu-scripts commit-dist --rm-local
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## ENV 环境变量
|
|
76
|
+
|
|
77
|
+
| 参数 | 默认值 | 说明 |
|
|
78
|
+
| ------- | ------ | ------------ |
|
|
79
|
+
| PORT | 3000 | 启动端口 |
|
|
80
|
+
| ANALYZE | false | 开启打包分析 |
|
|
81
|
+
|
|
82
|
+
## 自定义配置
|
|
83
|
+
|
|
84
|
+
```shell
|
|
85
|
+
# 创建 edu-scripts.override.js 文件
|
|
86
|
+
npx edu-scripts g override
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
具体看[override](/override)
|
|
90
|
+
|
|
91
|
+
### 自定义 antd 样式
|
|
92
|
+
|
|
93
|
+
如果不需要,可以跳过
|
|
94
|
+
|
|
95
|
+
根目录生成 `theme.js` 或 `theme.json`
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
module.exports = {
|
|
99
|
+
'@primary-color': '#99f',
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"@primary-color": "#99f"
|
|
106
|
+
}
|
|
107
|
+
```
|
package/app.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
declare namespace NodeJS {
|
|
2
|
+
interface ProcessEnv {
|
|
3
|
+
readonly NODE_ENV: 'development' | 'production'
|
|
4
|
+
readonly APP_NAME: string
|
|
5
|
+
readonly APP_VERSION: string
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module '*.avif' {
|
|
10
|
+
const src: string
|
|
11
|
+
export default src
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '*.bmp' {
|
|
15
|
+
const src: string
|
|
16
|
+
export default src
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module '*.gif' {
|
|
20
|
+
const src: string
|
|
21
|
+
export default src
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module '*.jpg' {
|
|
25
|
+
const src: string
|
|
26
|
+
export default src
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare module '*.jpeg' {
|
|
30
|
+
const src: string
|
|
31
|
+
export default src
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module '*.png' {
|
|
35
|
+
const src: string
|
|
36
|
+
export default src
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module '*.webp' {
|
|
40
|
+
const src: string
|
|
41
|
+
export default src
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare module '*.md' {
|
|
45
|
+
const content: string
|
|
46
|
+
export default content
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
declare module '*?raw' {
|
|
50
|
+
const content: string
|
|
51
|
+
export default content
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
declare module '*.svg' {
|
|
55
|
+
import * as React from 'react'
|
|
56
|
+
|
|
57
|
+
export const ReactComponent: React.FunctionComponent<
|
|
58
|
+
React.SVGProps<SVGSVGElement> & { title?: string }
|
|
59
|
+
>
|
|
60
|
+
|
|
61
|
+
const src: string
|
|
62
|
+
export default src
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
declare module '*.module.css' {
|
|
66
|
+
const classes: { readonly [key: string]: string }
|
|
67
|
+
export default classes
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
declare module '*.less' {
|
|
71
|
+
const classes: { readonly [key: string]: string }
|
|
72
|
+
export default classes
|
|
73
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { defineConfig } from 'vitepress'
|
|
2
|
+
import fs from 'fs-extra'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
|
|
5
|
+
const mds = fs.readdirSync(path.resolve(import.meta.dirname, '..')).filter((s) => s.endsWith('.md'))
|
|
6
|
+
|
|
7
|
+
const sidebarItems = mds
|
|
8
|
+
.map((file) => {
|
|
9
|
+
const md = fs.readFileSync(path.resolve(import.meta.dirname, '..', file), 'utf-8')
|
|
10
|
+
const title = md.split('\n')[0].match(/#\s+(.+)/)?.[1]
|
|
11
|
+
if (title) {
|
|
12
|
+
return { text: title, link: `/${file.replace('.md', '')}` }
|
|
13
|
+
}
|
|
14
|
+
return null
|
|
15
|
+
})
|
|
16
|
+
.filter((o) => !!o)
|
|
17
|
+
|
|
18
|
+
// https://vitepress.dev/reference/site-config
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
title: '@qse/edu-scripts',
|
|
21
|
+
description: '教育工程化基础框架',
|
|
22
|
+
base: '/qsxxwapdev/edu-scripts/',
|
|
23
|
+
themeConfig: {
|
|
24
|
+
// https://vitepress.dev/reference/default-theme-config
|
|
25
|
+
nav: [],
|
|
26
|
+
|
|
27
|
+
sidebar: [
|
|
28
|
+
{ text: '快速开始', link: '/install' },
|
|
29
|
+
{ text: '更新日志', link: '/changelog' },
|
|
30
|
+
{ text: '教程', items: sidebarItems },
|
|
31
|
+
],
|
|
32
|
+
|
|
33
|
+
socialLinks: [{ icon: 'github', link: 'https://github.com/vuejs/vitepress' }],
|
|
34
|
+
},
|
|
35
|
+
})
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<!-- @include: ../CHANGELOG.md -->
|
package/docs/debug.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# 代码调试
|
|
2
|
+
|
|
3
|
+
## 使用 `React Developer Tools` 调试
|
|
4
|
+
|
|
5
|
+
1. 安装 `React Developer Tools` 插件
|
|
6
|
+
2. 打开控制台(F12)
|
|
7
|
+
3. 切换到 `Component` 标签页
|
|
8
|
+
4. 选中需要查看的组件,可以看到 `state/props/hooks` 等信息
|
|
9
|
+
|
|
10
|
+
## 使用 vscode 调试代码
|
|
11
|
+
|
|
12
|
+
1. 打开 `JavaScript Debug Terminal` 终端,输入 `npm run start` 命令启动项目。
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
2. 按住 `ctrl/command` 点击 `http://localhost:port` 打开链接
|
|
17
|
+
3. 代码里打断点,网页点击触发断点
|
package/docs/deploy.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
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
|
+
```
|
|
@@ -0,0 +1,31 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
# https://vitepress.dev/reference/default-theme-home-page
|
|
3
|
+
layout: home
|
|
4
|
+
|
|
5
|
+
hero:
|
|
6
|
+
name: '@qse/edu-scripts'
|
|
7
|
+
text: 教育工程化基础框架
|
|
8
|
+
actions:
|
|
9
|
+
- theme: brand
|
|
10
|
+
text: 快速开始
|
|
11
|
+
link: /install
|
|
12
|
+
features:
|
|
13
|
+
- title: rspack重构
|
|
14
|
+
details: 使用rspack重构,比webpack快10x以上
|
|
15
|
+
---
|
package/docs/install.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<!-- @include: ../README.md -->
|