Commit 07c18d602ec47215c0390096a3fa66b40004d041

Authored by vben
1 parent 23657547

chore: add some notes

.editorconfig
... ... @@ -3,7 +3,7 @@ root = true
3 3 [*]
4 4 charset=utf-8
5 5 end_of_line=lf
6   -insert_final_newline=false
  6 +insert_final_newline=true
7 7 indent_style=space
8 8 indent_size=2
9 9  
... ...
.eslintignore
1 1  
2 2 *.sh
3 3 node_modules
4   -lib
5 4 *.md
6   -*.scss
7 5 *.woff
8 6 *.ttf
9 7 .vscode
10 8 .idea
11   -/dist/
12   -/mock/
  9 +dist
13 10 /public
14 11 /docs
15   -.vscode
  12 +.husky
16 13 .local
17 14 /bin
18   -/build
19   -/config
20 15 Dockerfile
21   -vue.config.js
22   -commit-lint.js
23   -postcss.config.js
24   -stylelint.config.js
25   -commitlint.config.js
... ...
.eslintrc.js
... ... @@ -23,21 +23,7 @@ module.exports = {
23 23 '@typescript-eslint/no-empty-function': 'off',
24 24 'vue/custom-event-name-casing': 'off',
25 25 'no-use-before-define': 'off',
26   - // 'no-setting-before-define': [
27   - // 'error',
28   - // {
29   - // functions: false,
30   - // classes: true,
31   - // },
32   - // ],
33 26 '@typescript-eslint/no-use-before-define': 'off',
34   - // '@typescript-eslint/no-setting-before-define': [
35   - // 'error',
36   - // {
37   - // functions: false,
38   - // classes: true,
39   - // },
40   - // ],
41 27 '@typescript-eslint/ban-ts-comment': 'off',
42 28 '@typescript-eslint/ban-types': 'off',
43 29 '@typescript-eslint/no-non-null-assertion': 'off',
... ...
.husky/pre-commit
... ... @@ -4,5 +4,9 @@
4 4  
5 5 [ -n "$CI" ] && exit 0
6 6  
  7 +# Check the file name
  8 +# ! ls-lint cannot be used normally in mac pro of M1 system.
7 9 npm run lint:ls-lint
  10 +
  11 +# Format and submit code according to lintstagedrc.js configuration
8 12 npm run lint:lint-staged
... ...
build/vite/optimizer.ts
  1 +// TODO
1 2 import type { GetManualChunk, GetManualChunkApi } from 'rollup';
2 3  
3 4 //
... ... @@ -10,6 +11,7 @@ const vendorLibs: { match: string[]; output: string }[] = [
10 11  
11 12 // @ts-ignore
12 13 export const configManualChunk: GetManualChunk = (id: string, api: GetManualChunkApi) => {
  14 + console.log(api);
13 15 if (/[\\/]node_modules[\\/]/.test(id)) {
14 16 const matchItem = vendorLibs.find((item) => {
15 17 const reg = new RegExp(`[\\/]node_modules[\\/]_?(${item.match.join('|')})(.*)`, 'ig');
... ...
build/vite/plugin/gzip.ts
  1 +/**
  2 + * Used to package and output gzip. Note that this does not work properly in Vite, the specific reason is still being investigated
  3 + */
  4 +import type { Plugin } from 'vite';
  5 +
1 6 import gzipPlugin from 'rollup-plugin-gzip';
2 7 import { isBuildGzip } from '../../utils';
3   -import { Plugin } from 'vite';
  8 +
4 9 export function configGzipPlugin(isBuild: boolean): Plugin | Plugin[] {
5 10 const useGzip = isBuild && isBuildGzip();
6 11  
... ...
build/vite/plugin/html.ts
  1 +/**
  2 + * Plugin to minimize and use ejs template syntax in index.html.
  3 + * https://github.com/anncwb/vite-plugin-html
  4 + */
1 5 import type { Plugin } from 'vite';
2 6 import type { ViteEnv } from '../../utils';
  7 +
3 8 import html from 'vite-plugin-html';
4 9  
5 10 import pkg from '../../../package.json';
... ... @@ -7,22 +12,27 @@ import { GLOB_CONFIG_FILE_NAME } from '../../constant';
7 12  
8 13 export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) {
9 14 const { VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH } = env;
  15 +
10 16 const path = VITE_PUBLIC_PATH.endsWith('/') ? VITE_PUBLIC_PATH : `${VITE_PUBLIC_PATH}/`;
11 17  
  18 + const getAppConfigSrc = () => {
  19 + return `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${pkg.version}-${new Date().getTime()}`;
  20 + };
  21 +
12 22 const htmlPlugin: Plugin[] = html({
13 23 minify: isBuild,
14 24 inject: {
  25 + // Inject data into ejs template
15 26 injectData: {
16 27 title: VITE_GLOB_APP_TITLE,
17 28 },
  29 + // Embed the generated app.config.js file
18 30 tags: isBuild
19 31 ? [
20 32 {
21 33 tag: 'script',
22 34 attrs: {
23   - src: `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${
24   - pkg.version
25   - }-${new Date().getTime()}`,
  35 + src: getAppConfigSrc(),
26 36 },
27 37 },
28 38 ]
... ...
build/vite/plugin/imagemin.ts
  1 +// Image resource files used to compress the output of the production environment
  2 +
1 3 import viteImagemin from 'vite-plugin-imagemin';
2 4  
3 5 export function configImageminPlugin() {
... ...
build/vite/plugin/index.ts
1 1 import type { Plugin } from 'vite';
2 2  
3 3 import PurgeIcons from 'vite-plugin-purge-icons';
  4 +import vue from '@vitejs/plugin-vue';
  5 +import vueJsx from '@vitejs/plugin-vue-jsx';
  6 +import legacy from '@vitejs/plugin-legacy';
4 7  
5 8 import { ViteEnv } from '../../utils';
6 9 import { configHtmlPlugin } from './html';
... ... @@ -12,11 +15,18 @@ import { configVisualizerConfig } from './visualizer';
12 15 import { configThemePlugin } from './theme';
13 16 import { configImageminPlugin } from './imagemin';
14 17  
15   -// gen vite plugins
16 18 export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
17   - const { VITE_USE_IMAGEMIN, VITE_USE_MOCK } = viteEnv;
  19 + const { VITE_USE_IMAGEMIN, VITE_USE_MOCK, VITE_LEGACY } = viteEnv;
18 20  
19   - const vitePlugins: (Plugin | Plugin[])[] = [];
  21 + const vitePlugins: (Plugin | Plugin[])[] = [
  22 + // have to
  23 + vue(),
  24 + // have to
  25 + vueJsx(),
  26 + ];
  27 +
  28 + // @vitejs/plugin-legacy
  29 + VITE_LEGACY && isBuild && vitePlugins.push(legacy());
20 30  
21 31 // vite-plugin-html
22 32 vitePlugins.push(configHtmlPlugin(viteEnv, isBuild));
... ... @@ -36,6 +46,7 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
36 46 //vite-plugin-theme
37 47 vitePlugins.push(configThemePlugin());
38 48  
  49 + // The following plugins only work in the production environment
39 50 if (isBuild) {
40 51 //vite-plugin-imagemin
41 52 VITE_USE_IMAGEMIN && vitePlugins.push(configImageminPlugin());
... ...
build/vite/plugin/mock.ts
  1 +/**
  2 + * Mock plugin for development and production.
  3 + * https://github.com/anncwb/vite-plugin-mock
  4 + */
1 5 import { viteMockServe } from 'vite-plugin-mock';
2 6  
3 7 export function configMockPlugin(isBuild: boolean) {
... ...
build/vite/plugin/pwa.ts
  1 +/**
  2 + * Zero-config PWA for Vite
  3 + * https://github.com/antfu/vite-plugin-pwa
  4 + */
  5 +
1 6 import { VitePWA } from 'vite-plugin-pwa';
2 7  
3 8 import { ViteEnv } from '../../utils';
... ...
build/vite/plugin/styleImport.ts
  1 +/**
  2 + * Introduces component library styles on demand.
  3 + * https://github.com/anncwb/vite-plugin-style-import
  4 + */
  5 +
1 6 import styleImport from 'vite-plugin-style-import';
2 7  
3 8 export function configStyleImportPlugin() {
... ...
build/vite/plugin/theme.ts
  1 +/**
  2 + * Vite plugin for website theme color switching
  3 + * https://github.com/anncwb/vite-plugin-theme
  4 + */
1 5 import { viteThemePlugin, mixLighten, mixDarken, tinycolor } from 'vite-plugin-theme';
2 6 import { getThemeColors, generateColors } from '../../config/themeConfig';
3 7  
... ...
build/vite/plugin/visualizer.ts
  1 +/**
  2 + * Package file volume analysis
  3 + */
1 4 import visualizer from 'rollup-plugin-visualizer';
2 5 import { isReportMode } from '../../utils';
3 6  
... ...
build/vite/proxy.ts
  1 +/**
  2 + * Used to parse the .env.development proxy configuration
  3 + */
1 4 import type { ServerOptions } from 'http-proxy';
2 5  
3 6 type ProxyItem = [string, string];
... ...
mock/_util.ts
... ... @@ -38,7 +38,7 @@ export function resultError(message = 'Request failed', { code = -1, result = nu
38 38 }
39 39  
40 40 export function pagination<T = any>(pageNo: number, pageSize: number, array: T[]): T[] {
41   - let offset = (pageNo - 1) * Number(pageSize);
  41 + const offset = (pageNo - 1) * Number(pageSize);
42 42 const ret =
43 43 offset + Number(pageSize) >= array.length
44 44 ? array.slice(offset, array.length)
... ...
mock/demo/select-demo.ts
... ... @@ -18,6 +18,7 @@ export default [
18 18 timeout: 4000,
19 19 method: 'get',
20 20 response: ({ query }) => {
  21 + console.log(query);
21 22 return resultSuccess(demoList);
22 23 },
23 24 },
... ...
package.json
... ... @@ -14,8 +14,7 @@
14 14 "clean:cache": "rimraf node_modules/.cache/ && rimraf node_modules/.vite",
15 15 "clean:lib": "npx rimraf node_modules",
16 16 "typecheck": "vuedx-typecheck .",
17   - "lint:eslint": "eslint \"{src,mock}/**/*.{vue,ts,tsx}\" ",
18   - "lint:eslint:fix": "eslint \"{src,mock}/**/*.{vue,ts,tsx}\" --fix",
  17 + "lint:eslint": "eslint \"{src,mock}/**/*.{vue,ts,tsx}\" --fix",
19 18 "lint:prettier": "prettier --write --loglevel warn \"src/**/*.{js,json,tsx,css,less,scss,vue,html,md}\"",
20 19 "lint:stylelint": "stylelint --fix \"**/*.{vue,less,postcss,css,scss}\" --cache --cache-location node_modules/.cache/stylelint/",
21 20 "lint:ls-lint": "ls-lint",
... ...
prettier.config.js
... ... @@ -17,12 +17,4 @@ module.exports = {
17 17 htmlWhitespaceSensitivity: 'strict',
18 18 endOfLine: 'lf',
19 19 rangeStart: 0,
20   - overrides: [
21   - {
22   - files: '*.md',
23   - options: {
24   - tabWidth: 2,
25   - },
26   - },
27   - ],
28 20 };
... ...
src/components/Description/src/index.tsx
... ... @@ -84,35 +84,36 @@ export default defineComponent({
84 84  
85 85 function renderItem() {
86 86 const { schema, data } = unref(getProps);
87   - return unref(schema).map((item) => {
88   - const { render, field, span, show, contentMinWidth } = item;
89   -
90   - if (show && isFunction(show) && !show(data)) {
91   - return null;
92   - }
93   -
94   - const getContent = () => {
95   - const _data = unref(data);
96   - const getField = get(_data, field);
97   - return isFunction(render) ? render(getField, _data) : getField ?? '';
98   - };
99   -
100   - const width = contentMinWidth;
101   - return (
102   - <Descriptions.Item label={renderLabel(item)} key={field} span={span}>
103   - {() => {
104   - if (!contentMinWidth) {
105   - return getContent();
106   - }
107   - const style: CSSProperties = {
108   - minWidth: `${width}px`,
109   - };
110   - return <div style={style}>{getContent()}</div>;
111   - }}
112   - </Descriptions.Item>
113   - );
114   - })
115   - .filter((item) => !!item);
  87 + return unref(schema)
  88 + .map((item) => {
  89 + const { render, field, span, show, contentMinWidth } = item;
  90 +
  91 + if (show && isFunction(show) && !show(data)) {
  92 + return null;
  93 + }
  94 +
  95 + const getContent = () => {
  96 + const _data = unref(data);
  97 + const getField = get(_data, field);
  98 + return isFunction(render) ? render(getField, _data) : getField ?? '';
  99 + };
  100 +
  101 + const width = contentMinWidth;
  102 + return (
  103 + <Descriptions.Item label={renderLabel(item)} key={field} span={span}>
  104 + {() => {
  105 + if (!contentMinWidth) {
  106 + return getContent();
  107 + }
  108 + const style: CSSProperties = {
  109 + minWidth: `${width}px`,
  110 + };
  111 + return <div style={style}>{getContent()}</div>;
  112 + }}
  113 + </Descriptions.Item>
  114 + );
  115 + })
  116 + .filter((item) => !!item);
116 117 }
117 118  
118 119 const renderDesc = () => {
... ...
stylelint.config.js
... ... @@ -28,7 +28,7 @@ module.exports = {
28 28 ignore: ['after-comment', 'first-nested'],
29 29 },
30 30 ],
31   - // 指定声明块内属性的字母顺序
  31 + // Specify the alphabetical order of the attributes in the declaration block
32 32 'order/properties-order': [
33 33 'position',
34 34 'top',
... ...
vite.config.ts
1 1 import type { UserConfig, ConfigEnv } from 'vite';
2   -import { resolve } from 'path';
3   -import vue from '@vitejs/plugin-vue';
4   -import vueJsx from '@vitejs/plugin-vue-jsx';
5   -import legacy from '@vitejs/plugin-legacy';
6 2  
7 3 import { loadEnv } from 'vite';
  4 +import { resolve } from 'path';
8 5  
9 6 import { generateModifyVars } from './build/config/themeConfig';
10 7 import { createProxy } from './build/vite/proxy';
... ... @@ -18,11 +15,14 @@ function pathResolve(dir: string) {
18 15 return resolve(__dirname, '.', dir);
19 16 }
20 17  
21   -const root = process.cwd();
22   -
23 18 export default ({ command, mode }: ConfigEnv): UserConfig => {
  19 + const root = process.cwd();
  20 +
24 21 const env = loadEnv(mode, root);
  22 +
  23 + // The boolean type read by loadEnv is a string. This function can be converted to boolean type
25 24 const viteEnv = wrapperEnv(env);
  25 +
26 26 const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE, VITE_LEGACY } = viteEnv;
27 27  
28 28 const isBuild = command === 'build';
... ... @@ -32,12 +32,14 @@ export default ({ command, mode }: ConfigEnv): UserConfig =&gt; {
32 32 root,
33 33 alias: [
34 34 {
  35 + // /@/xxxx => src/xxx
35 36 find: /^\/@\//,
36 37 replacement: pathResolve('src') + '/',
37 38 },
38 39 ],
39 40 server: {
40 41 port: VITE_PORT,
  42 + // Load proxy configuration from .env
41 43 proxy: createProxy(VITE_PROXY),
42 44 hmr: {
43 45 overlay: true,
... ... @@ -50,9 +52,11 @@ export default ({ command, mode }: ConfigEnv): UserConfig =&gt; {
50 52 terserOptions: {
51 53 compress: {
52 54 keep_infinity: true,
  55 + // Used to delete console in production environment
53 56 drop_console: VITE_DROP_CONSOLE,
54 57 },
55 58 },
  59 + // Turning off brotliSize display can slightly reduce packaging time
56 60 brotliSize: false,
57 61 chunkSizeWarningLimit: 1200,
58 62 },
... ... @@ -68,6 +72,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig =&gt; {
68 72 preprocessorOptions: {
69 73 less: {
70 74 modifyVars: {
  75 + // Used for global import to avoid the need to import each style file separately
71 76 // reference: Avoid repeated references
72 77 hack: `true; @import (reference) "${resolve('src/design/config.less')}";`,
73 78 ...generateModifyVars(),
... ... @@ -77,14 +82,11 @@ export default ({ command, mode }: ConfigEnv): UserConfig =&gt; {
77 82 },
78 83 },
79 84  
80   - plugins: [
81   - vue(),
82   - vueJsx(),
83   - ...(VITE_LEGACY && isBuild ? [legacy()] : []),
84   - ...createVitePlugins(viteEnv, isBuild),
85   - ],
  85 + // The vite plugin used by the project. The quantity is large, so it is separately extracted and managed
  86 + plugins: createVitePlugins(viteEnv, isBuild),
86 87  
87 88 optimizeDeps: {
  89 + // @iconify/iconify: The dependency is dynamically and virtually loaded by @purge-icons/generated, so it needs to be specified explicitly
88 90 include: ['@iconify/iconify'],
89 91 },
90 92 };
... ...