Commit 2f1fbf8e487fdae4db5c144d97f9d20e42bb1603

Authored by vben
1 parent 7658f4d6

style: add some notes

.eslintignore
... ... @@ -20,9 +20,6 @@ lib
20 20 Dockerfile
21 21 vue.config.js
22 22 commit-lint.js
23   -/src/assets/iconfont/
24   -/types/shims
25   -/src/types/shims
26 23 postcss.config.js
27 24 stylelint.config.js
28 25 commitlint.config.js
... ...
build/constant.ts
  1 +/**
  2 + * The name of the configuration file entered in the production environment
  3 + */
1 4 export const GLOB_CONFIG_FILE_NAME = '_app.config.js';
... ...
build/getShortName.ts
  1 +/**
  2 + * Get the configuration file variable name
  3 + * @param env
  4 + */
1 5 export const getShortName = (env: any) => {
2 6 return `__PRODUCTION__${env.VITE_GLOB_APP_SHORT_NAME || '__APP'}__CONF__`
3 7 .toUpperCase()
... ...
build/script/buildConf.ts
  1 +/**
  2 + * Generate additional configuration files when used for packaging. The file can be configured with some global variables, so that it can be changed directly externally without repackaging
  3 + */
1 4 import { GLOB_CONFIG_FILE_NAME } from '../constant';
2 5 import fs, { writeFileSync } from 'fs-extra';
3 6  
4 7 import viteConfig from '../../vite.config';
5 8 import { errorConsole, successConsole, getCwdPath, getEnvConfig } from '../utils';
6   -
7   -const getShortName = (env: any) => {
8   - return `__PRODUCTION__${env.VITE_GLOB_APP_SHORT_NAME || '__APP'}__CONF__`
9   - .toUpperCase()
10   - .replace(/\s/g, '');
11   -};
  9 +import { getShortName } from '../getShortName';
12 10  
13 11 function createConfig(
14 12 {
... ... @@ -20,6 +18,7 @@ function createConfig(
20 18 try {
21 19 const windowConf = `window.${configName}`;
22 20 const outDir = viteConfig.outDir || 'dist';
  21 + // Ensure that the variable will not be modified
23 22 const configStr = `${windowConf}=${JSON.stringify(config)};
24 23  
25 24 Object.freeze(${windowConf});
... ...
build/utils.ts
... ... @@ -7,6 +7,7 @@ import chalk from 'chalk';
7 7  
8 8 export const isFunction = (arg: unknown): arg is (...args: any[]) => any =>
9 9 typeof arg === 'function';
  10 +
10 11 export const isRegExp = (arg: unknown): arg is RegExp =>
11 12 Object.prototype.toString.call(arg) === '[object RegExp]';
12 13  
... ... @@ -43,6 +44,9 @@ export function readAllFile(root: string, reg: RegExp) {
43 44 return resultArr;
44 45 }
45 46  
  47 +/**
  48 + * get client ip address
  49 + */
46 50 export function getIPAddress() {
47 51 let interfaces = networkInterfaces();
48 52 for (let devName in interfaces) {
... ... @@ -67,12 +71,23 @@ export function isProdFn(): boolean {
67 71 return process.env.NODE_ENV === 'production';
68 72 }
69 73  
  74 +/**
  75 + * Whether to generate package preview
  76 + */
70 77 export function isReportMode(): boolean {
71 78 return process.env.REPORT === 'true';
72 79 }
  80 +
  81 +/**
  82 + * Whether to generate gzip for packaging
  83 + */
73 84 export function isBuildGzip(): boolean {
74 85 return process.env.VITE_BUILD_GZIP === 'true';
75 86 }
  87 +
  88 +/**
  89 + * Whether to generate package site
  90 + */
76 91 export function isSiteMode(): boolean {
77 92 return process.env.SITE === 'true';
78 93 }
... ... @@ -89,6 +104,7 @@ export interface ViteEnv {
89 104 VITE_BUILD_GZIP: boolean;
90 105 }
91 106  
  107 +// Read all environment variable configuration files to process.env
92 108 export function loadEnv(): ViteEnv {
93 109 const env = process.env.NODE_ENV;
94 110 const ret: any = {};
... ... @@ -116,6 +132,11 @@ export function loadEnv(): ViteEnv {
116 132 return ret;
117 133 }
118 134  
  135 +/**
  136 + * Get the environment variables starting with the specified prefix
  137 + * @param match prefix
  138 + * @param confFiles ext
  139 + */
119 140 export function getEnvConfig(match = 'VITE_GLOB_', confFiles = ['.env', '.env.production']) {
120 141 let envConfig = {};
121 142 confFiles.forEach((item) => {
... ... @@ -142,18 +163,34 @@ function consoleFn(color: string, message: any) {
142 163 );
143 164 }
144 165  
  166 +/**
  167 + * warnConsole
  168 + * @param message
  169 + */
145 170 export function successConsole(message: any) {
146 171 consoleFn('green', '✨ ' + message);
147 172 }
148 173  
  174 +/**
  175 + * warnConsole
  176 + * @param message
  177 + */
149 178 export function errorConsole(message: any) {
150 179 consoleFn('red', '✨ ' + message);
151 180 }
152 181  
  182 +/**
  183 + * warnConsole
  184 + * @param message message
  185 + */
153 186 export function warnConsole(message: any) {
154 187 consoleFn('yellow', '✨ ' + message);
155 188 }
156 189  
  190 +/**
  191 + * Get user root directory
  192 + * @param dir file path
  193 + */
157 194 export function getCwdPath(...dir: string[]) {
158 195 return path.resolve(process.cwd(), ...dir);
159 196 }
... ...
build/vite/hm.ts
1   -// 百度统计代码 用于站点部署
2   -// 只在build:site开启
  1 +// Baidu statistics code for site deployment
  2 +// Only open in build:site
3 3 export const hmScript = `<script>
4 4 var _hmt = _hmt || [];
5 5 (function() {
... ...
build/vite/plugin/gzip/index.ts
1 1 // 修改自https://github.com/kryops/rollup-plugin-gzip
2 2 // 因为rollup-plugin-gzip不支持vite
3 3 // vite对css打包独立的。所以不能在打包的时候顺带打包css
  4 +// TODO rc.9会支持 configurBuild 配置项。到时候重新修改
4 5  
5 6 import { readFile, writeFile } from 'fs';
6 7 import { basename } from 'path';
... ...
build/vite/proxy.ts
... ... @@ -3,6 +3,11 @@ type ProxyItem = [string, string];
3 3 type ProxyList = ProxyItem[];
4 4  
5 5 const reg = /^https:\/\//;
  6 +
  7 +/**
  8 + * Generate proxy
  9 + * @param list
  10 + */
6 11 export function createProxy(list: ProxyList = []) {
7 12 const ret: any = {};
8 13 for (const [prefix, target] of list) {
... ... @@ -12,6 +17,7 @@ export function createProxy(list: ProxyList = []) {
12 17 target: target,
13 18 changeOrigin: true,
14 19 rewrite: (path: string) => path.replace(new RegExp(`^${prefix}`), ''),
  20 + // https is require secure=false
15 21 ...(isHttps ? { secure: false } : {}),
16 22 };
17 23 }
... ...
mock/_createProductionServer.ts
... ... @@ -3,6 +3,9 @@ import userMock from &#39;./sys/user&#39;;
3 3 import menuMock from './sys/menu';
4 4 import tableDemoMock from './demo/table-demo';
5 5  
  6 +/**
  7 + * Used in a production environment. Need to manually import all modules
  8 + */
6 9 export function setupProdMockServer() {
7 10 createProdMockServer([...userMock, ...menuMock, ...tableDemoMock]);
8 11 }
... ...
src/App.vue
... ... @@ -23,14 +23,20 @@
23 23 name: 'App',
24 24 components: { ConfigProvider },
25 25 setup() {
  26 + // Initialize application settings
26 27 useInitAppConfigStore();
  28 + // Initialize network monitoring
27 29 useListenerNetWork();
  30 + // Initialize breakpoint monitoring
28 31 createBreakpointListen();
  32 + // Get system configuration
29 33 const { projectSetting } = useSetting();
  34 + // Get ConfigProvider configuration
30 35 const { transformCellText } = useConfigProvider();
31 36  
32 37 let lockOn = {};
33 38 if (projectSetting.lockTime) {
  39 + // Monitor the mouse or keyboard time, used to recalculate the lock screen time
34 40 const { on } = useLockPage();
35 41 lockOn = on;
36 42 }
... ...
src/main.ts
... ... @@ -22,8 +22,10 @@ setupRouter(app);
22 22 // store
23 23 setupStore(app);
24 24  
  25 +// Directives
25 26 setupDirectives(app);
26 27  
  28 +// error-handle
27 29 setupErrorHandle(app);
28 30  
29 31 router.isReady().then(() => {
... ... @@ -35,8 +37,10 @@ if (isDevMode()) {
35 37 window.__APP__ = app;
36 38 }
37 39  
  40 +// If you do not need to use the mock service in the production environment, you can comment the code
38 41 if (isProdMode() && isUseMock()) {
39 42 setupProdMockServer();
40 43 }
41 44  
  45 +// Used to share app instances in other modules
42 46 setApp(app);
... ...
src/useApp.ts
  1 +// Application related functions
1 2 import type { ProjectConfig } from '/@/types/config';
2 3 import type { App } from 'vue';
3 4 import { computed, ref } from 'vue';
... ...
src/utils/http/axios/const.ts
  1 +// 接口返回值data不能为这个,否则会判为请求失败
1 2 export const errorResult = '__ERROR_RESULT__';
... ...
vite.config.ts
... ... @@ -35,79 +35,89 @@ const viteConfig: UserConfig = {
35 35 // TODO build error
36 36 // entry: './public/index.html',
37 37 /**
38   - * 端口号
  38 + * port
39 39 * @default '3000'
40 40 */
41 41 port: VITE_PORT,
42 42 /**
43   - * 服务地址
44 43 * @default 'localhost'
45 44 */
46 45 hostname: 'localhost',
47 46 /**
48   - * 运行自动打开浏览器·
  47 + * Run to open the browser automatically
49 48 * @default 'false'
50 49 */
51 50 open: false,
52 51 /**
53   - * 压缩代码
54   - * boolean | 'terser' | 'esbuild'
  52 + * Set to `false` to disable minification, or specify the minifier to use.
  53 + * Available options are 'terser' or 'esbuild'.
55 54 * @default 'terser'
56 55 */
57 56 minify: isDevFn() ? 'esbuild' : 'terser',
58 57 /**
59   - * 基本公共路径
  58 + * Base public path when served in production.
60 59 * @default '/'
61 60 */
62 61 base: VITE_PUBLIC_PATH,
63 62  
64 63 /**
65   - * 打包输入路径
  64 + * Directory relative from `root` where build output will be placed. If the
  65 + * directory exists, it will be removed before the build.
66 66 * @default 'dist'
67 67 */
68 68 outDir: 'dist',
69 69 /**
70   - * @default 'false'
  70 + * Whether to generate sourcemap
  71 + * @default false
71 72 */
72 73 sourcemap: false,
73 74 /**
74   - * 资源输出路径
  75 + * Directory relative from `outDir` where the built js/css/image assets will
  76 + * be placed.
75 77 * @default '_assets'
76 78 */
77 79 assetsDir: '_assets',
78 80 /**
79   - * 静态资源小于该大小将会内联,默认4096kb
80   - * @default '4096'
  81 + * Static asset files smaller than this number (in bytes) will be inlined as
  82 + * base64 strings. Default limit is `4096` (4kb). Set to `0` to disable.
  83 + * @default 4096
81 84 */
82 85 assetsInlineLimit: 4096,
83 86 /**
84   - * esbuild转换目标。
  87 + * Transpile target for esbuild.
85 88 * @default 'es2020'
86 89 */
87 90 esbuildTarget: 'es2020',
  91 + /**
  92 + * Whether to log asset info to console
  93 + * @default false
  94 + */
88 95 silent: false,
89   - // 别名
  96 + /**
  97 + * Import alias. The entries can either be exact request -> request mappings
  98 + * (exact, no wildcard syntax), or request path -> fs directory mappings.
  99 + * When using directory mappings, the key **must start and end with a slash**.
  100 + * ```
  101 + */
90 102 alias: {
91 103 '/@/': pathResolve('src'),
92 104 },
93   - // terser配置
  105 + // terser options
94 106 terserOptions: {
95 107 compress: {
96   - // 是否删除console
97 108 drop_console: VITE_DROP_CONSOLE,
98 109 },
99 110 },
100 111 define: {
101 112 __VERSION__: pkg.version,
102 113 },
103   - // css预处理
104 114 cssPreprocessOptions: {
105 115 less: {
106 116 modifyVars: modifyVars,
107 117 javascriptEnabled: true,
108 118 },
109 119 },
110   - // 会使用 rollup 对 包重新编译,将编译成符合 esm 模块规范的新的包放入 node_modules/.vite_opt_cache
  120 + // The package will be recompiled using rollup, and the new package compiled into the esm module specification will be put into node_modules/.vite_opt_cache
111 121 optimizeDeps: {
112 122 include: [
113 123 'echarts',
... ... @@ -118,7 +128,7 @@ const viteConfig: UserConfig = {
118 128 ],
119 129 },
120 130  
121   - // 本地跨域代理
  131 + // Local cross-domain proxy
122 132 proxy: createProxy(VITE_PROXY),
123 133 plugins: createVitePlugins(viteEnv),
124 134 rollupInputOptions: {
... ...