Commit 3509ebec165d26651cc02dc233bd9433c544bed5

Authored by vben
1 parent 8bd20c6c

fix: mock plugin error #171

.editorconfig
@@ -13,3 +13,6 @@ indent_size = 2 @@ -13,3 +13,6 @@ indent_size = 2
13 13
14 [*.md] 14 [*.md]
15 trim_trailing_whitespace = false 15 trim_trailing_whitespace = false
  16 +
  17 +[Makefile]
  18 +indent_style = tab
.env.production
@@ -2,13 +2,13 @@ @@ -2,13 +2,13 @@
2 VITE_USE_MOCK = true 2 VITE_USE_MOCK = true
3 3
4 # public path 4 # public path
5 -VITE_PUBLIC_PATH = ./ 5 +VITE_PUBLIC_PATH = /
6 6
7 # Delete console 7 # Delete console
8 VITE_DROP_CONSOLE = true 8 VITE_DROP_CONSOLE = true
9 9
10 # Whether to output gz file for packaging 10 # Whether to output gz file for packaging
11 -VITE_BUILD_GZIP = true 11 +VITE_BUILD_GZIP = false
12 12
13 # Basic interface address SPA 13 # Basic interface address SPA
14 VITE_GLOB_API_URL=/api 14 VITE_GLOB_API_URL=/api
build/script/hackXlsx.ts deleted 100644 → 0
1 -import fs from 'fs-extra';  
2 -  
3 -import path from 'path';  
4 -  
5 -// Because xlsx internally references the node module, the pre-optimization of vite2.0 fails. Since the node module inside xlsx is not used on the web side, all the code that uses the node module is replaced with `{}` to be compatible with'vite2'  
6 -function replaceCjs() {  
7 - const xlsx = path.resolve(process.cwd(), 'node_modules/xlsx/xlsx.js');  
8 - let raw = fs.readFileSync(xlsx, 'utf-8');  
9 -  
10 - raw = raw  
11 - .replace(`require('fs')`, '{}')  
12 - .replace(`require('stream')`, '{}')  
13 - .replace(`require('crypto')`, '{}');  
14 - fs.writeFileSync(xlsx, raw);  
15 -}  
16 -  
17 -replaceCjs();  
build/vite/optimizer.ts
@@ -2,10 +2,10 @@ import type { GetManualChunk, GetManualChunkApi } from 'rollup'; @@ -2,10 +2,10 @@ import type { GetManualChunk, GetManualChunkApi } from 'rollup';
2 2
3 // 3 //
4 const vendorLibs: { match: string[]; output: string }[] = [ 4 const vendorLibs: { match: string[]; output: string }[] = [
5 - {  
6 - match: ['xlsx'],  
7 - output: 'xlsx',  
8 - }, 5 + // {
  6 + // match: ['xlsx'],
  7 + // output: 'xlsx',
  8 + // },
9 ]; 9 ];
10 10
11 // @ts-ignore 11 // @ts-ignore
build/vite/plugin/gzip.ts
@@ -2,7 +2,7 @@ import gzipPlugin from 'rollup-plugin-gzip'; @@ -2,7 +2,7 @@ import gzipPlugin from 'rollup-plugin-gzip';
2 import { isBuildGzip } from '../../utils'; 2 import { isBuildGzip } from '../../utils';
3 import { Plugin } from 'vite'; 3 import { Plugin } from 'vite';
4 export function configGzipPlugin(isBuild: boolean): Plugin | Plugin[] { 4 export function configGzipPlugin(isBuild: boolean): Plugin | Plugin[] {
5 - const useGzip = isBuild && isBuildGzip; 5 + const useGzip = isBuild && isBuildGzip();
6 6
7 if (useGzip) { 7 if (useGzip) {
8 return gzipPlugin(); 8 return gzipPlugin();
package.json
1 { 1 {
2 "name": "vben-admin", 2 "name": "vben-admin",
3 - "version": "2.0.0-rc.16", 3 + "version": "2.0.0-rc.15",
4 "scripts": { 4 "scripts": {
5 "bootstrap": "yarn install", 5 "bootstrap": "yarn install",
6 "serve": "vite", 6 "serve": "vite",
@@ -15,9 +15,7 @@ @@ -15,9 +15,7 @@
15 "lint:eslint": "eslint --fix --ext \"src/**/*.{vue,less,css,scss}\"", 15 "lint:eslint": "eslint --fix --ext \"src/**/*.{vue,less,css,scss}\"",
16 "lint:prettier": "prettier --write --loglevel warn \"src/**/*.{js,json,tsx,css,less,scss,vue,html,md}\"", 16 "lint:prettier": "prettier --write --loglevel warn \"src/**/*.{js,json,tsx,css,less,scss,vue,html,md}\"",
17 "lint:stylelint": "stylelint --fix \"**/*.{vue,less,postcss,css,scss}\" --cache --cache-location node_modules/.cache/stylelint/", 17 "lint:stylelint": "stylelint --fix \"**/*.{vue,less,postcss,css,scss}\" --cache --cache-location node_modules/.cache/stylelint/",
18 - "reinstall": "rimraf yarn.lock && rimraf package.lock.json && rimraf node_modules && npm run bootstrap",  
19 - "hack-esm:xlsx": "esno ./build/script/hackXlsx",  
20 - "postinstall": "npm run hack-esm:xlsx" 18 + "reinstall": "rimraf yarn.lock && rimraf package.lock.json && rimraf node_modules && npm run bootstrap"
21 }, 19 },
22 "dependencies": { 20 "dependencies": {
23 "@iconify/iconify": "^2.0.0-rc.5", 21 "@iconify/iconify": "^2.0.0-rc.5",
@@ -98,11 +96,11 @@ @@ -98,11 +96,11 @@
98 "stylelint-order": "^4.1.0", 96 "stylelint-order": "^4.1.0",
99 "ts-node": "^9.1.0", 97 "ts-node": "^9.1.0",
100 "typescript": "^4.1.3", 98 "typescript": "^4.1.3",
101 - "vite": "^2.0.0-beta.19", 99 + "vite": "^2.0.0-beta.21",
102 "vite-plugin-html": "^2.0.0-beta.5", 100 "vite-plugin-html": "^2.0.0-beta.5",
103 - "vite-plugin-mock": "^2.0.0-beta.1", 101 + "vite-plugin-mock": "^2.0.0-beta.3",
104 "vite-plugin-purge-icons": "^0.5.0", 102 "vite-plugin-purge-icons": "^0.5.0",
105 - "vite-plugin-pwa": "^0.3.3", 103 + "vite-plugin-pwa": "^0.3.5",
106 "vue-eslint-parser": "^7.3.0", 104 "vue-eslint-parser": "^7.3.0",
107 "yargs": "^16.2.0" 105 "yargs": "^16.2.0"
108 }, 106 },
src/components/Form/src/BasicForm.vue
@@ -41,7 +41,8 @@ @@ -41,7 +41,8 @@
41 import FormAction from './components/FormAction.vue'; 41 import FormAction from './components/FormAction.vue';
42 42
43 import { dateItemType } from './helper'; 43 import { dateItemType } from './helper';
44 - import moment from 'moment'; 44 + import { dateUtil } from '/@/utils/dateUtil';
  45 +
45 // import { cloneDeep } from 'lodash-es'; 46 // import { cloneDeep } from 'lodash-es';
46 import { deepMerge } from '/@/utils'; 47 import { deepMerge } from '/@/utils';
47 48
@@ -108,11 +109,11 @@ @@ -108,11 +109,11 @@
108 // handle date type 109 // handle date type
109 if (defaultValue && dateItemType.includes(component)) { 110 if (defaultValue && dateItemType.includes(component)) {
110 if (!Array.isArray(defaultValue)) { 111 if (!Array.isArray(defaultValue)) {
111 - schema.defaultValue = moment(defaultValue); 112 + schema.defaultValue = dateUtil(defaultValue);
112 } else { 113 } else {
113 const def: moment.Moment[] = []; 114 const def: moment.Moment[] = [];
114 defaultValue.forEach((item) => { 115 defaultValue.forEach((item) => {
115 - def.push(moment(item)); 116 + def.push(dateUtil(item));
116 }); 117 });
117 schema.defaultValue = def; 118 schema.defaultValue = def;
118 } 119 }
src/components/Form/src/hooks/useFormEvents.ts
@@ -7,7 +7,7 @@ import { unref, toRaw } from 'vue'; @@ -7,7 +7,7 @@ import { unref, toRaw } from 'vue';
7 import { isArray, isFunction, isObject, isString } from '/@/utils/is'; 7 import { isArray, isFunction, isObject, isString } from '/@/utils/is';
8 import { deepMerge, unique } from '/@/utils'; 8 import { deepMerge, unique } from '/@/utils';
9 import { dateItemType, handleInputNumberValue } from '../helper'; 9 import { dateItemType, handleInputNumberValue } from '../helper';
10 -import moment from 'moment'; 10 +import { dateUtil } from '/@/utils/dateUtil';
11 import { cloneDeep } from 'lodash-es'; 11 import { cloneDeep } from 'lodash-es';
12 import { error } from '/@/utils/log'; 12 import { error } from '/@/utils/log';
13 13
@@ -67,11 +67,11 @@ export function useFormEvents({ @@ -67,11 +67,11 @@ export function useFormEvents({
67 if (Array.isArray(value)) { 67 if (Array.isArray(value)) {
68 const arr: moment.Moment[] = []; 68 const arr: moment.Moment[] = [];
69 for (const ele of value) { 69 for (const ele of value) {
70 - arr.push(moment(ele)); 70 + arr.push(dateUtil(ele));
71 } 71 }
72 formModel[key] = arr; 72 formModel[key] = arr;
73 } else { 73 } else {
74 - formModel[key] = moment(value); 74 + formModel[key] = dateUtil(value);
75 } 75 }
76 } else { 76 } else {
77 formModel[key] = value; 77 formModel[key] = value;
src/components/Form/src/hooks/useFormValues.ts
1 import { isArray, isFunction, isObject, isString } from '/@/utils/is'; 1 import { isArray, isFunction, isObject, isString } from '/@/utils/is';
2 -import moment from 'moment'; 2 +import { dateUtil } from '/@/utils/dateUtil';
  3 +
3 import { unref, nextTick } from 'vue'; 4 import { unref, nextTick } from 'vue';
4 import type { Ref, ComputedRef } from 'vue'; 5 import type { Ref, ComputedRef } from 'vue';
5 import type { FieldMapToTime, FormSchema } from '../types/form'; 6 import type { FieldMapToTime, FormSchema } from '../types/form';
@@ -65,8 +66,8 @@ export function useFormValues({ @@ -65,8 +66,8 @@ export function useFormValues({
65 66
66 const [startTime, endTime]: string[] = values[field]; 67 const [startTime, endTime]: string[] = values[field];
67 68
68 - values[startTimeKey] = moment(startTime).format(format);  
69 - values[endTimeKey] = moment(endTime).format(format); 69 + values[startTimeKey] = dateUtil(startTime).format(format);
  70 + values[endTimeKey] = dateUtil(endTime).format(format);
70 Reflect.deleteProperty(values, field); 71 Reflect.deleteProperty(values, field);
71 } 72 }
72 73
src/locales/setupI18n.ts
@@ -3,8 +3,6 @@ import type { I18n, I18nOptions } from 'vue-i18n'; @@ -3,8 +3,6 @@ import type { I18n, I18nOptions } from 'vue-i18n';
3 3
4 import { createI18n } from 'vue-i18n'; 4 import { createI18n } from 'vue-i18n';
5 5
6 -import 'moment/dist/locale/zh-cn';  
7 -  
8 import projectSetting from '/@/settings/projectSetting'; 6 import projectSetting from '/@/settings/projectSetting';
9 7
10 import messages from './getMessage'; 8 import messages from './getMessage';
src/locales/useLocale.ts
@@ -7,9 +7,7 @@ import type { Ref } from 'vue'; @@ -7,9 +7,7 @@ import type { Ref } from 'vue';
7 import { unref, ref } from 'vue'; 7 import { unref, ref } from 'vue';
8 import { useLocaleSetting } from '/@/hooks/setting/useLocaleSetting'; 8 import { useLocaleSetting } from '/@/hooks/setting/useLocaleSetting';
9 9
10 -import moment from 'moment';  
11 -  
12 -import 'moment/dist/locale/zh-cn'; 10 +import { dateUtil } from '/@/utils/dateUtil';
13 11
14 import { i18n } from './setupI18n'; 12 import { i18n } from './setupI18n';
15 13
@@ -36,14 +34,14 @@ export function useLocale() { @@ -36,14 +34,14 @@ export function useLocale() {
36 antConfigLocaleRef.value = locale.default; 34 antConfigLocaleRef.value = locale.default;
37 }); 35 });
38 36
39 - moment.locale('cn'); 37 + dateUtil.locale('cn');
40 break; 38 break;
41 // English 39 // English
42 case 'en': 40 case 'en':
43 import('ant-design-vue/es/locale/en_US').then((locale) => { 41 import('ant-design-vue/es/locale/en_US').then((locale) => {
44 antConfigLocaleRef.value = locale.default; 42 antConfigLocaleRef.value = locale.default;
45 }); 43 });
46 - moment.locale('en-us'); 44 + dateUtil.locale('en-us');
47 break; 45 break;
48 46
49 // other 47 // other
src/views/sys/lock/useNow.ts
1 -import moment from 'moment'; 1 +import { dateUtil } from '/@/utils/dateUtil';
2 import { reactive, toRefs } from 'vue'; 2 import { reactive, toRefs } from 'vue';
3 import { tryOnMounted, tryOnUnmounted } from '/@/utils/helper/vueHelper'; 3 import { tryOnMounted, tryOnUnmounted } from '/@/utils/helper/vueHelper';
4 import { useLocaleSetting } from '/@/hooks/setting/useLocaleSetting'; 4 import { useLocaleSetting } from '/@/hooks/setting/useLocaleSetting';
5 5
6 export function useNow(immediate = true) { 6 export function useNow(immediate = true) {
7 const { getLang } = useLocaleSetting(); 7 const { getLang } = useLocaleSetting();
8 - const localData = moment.localeData(getLang.value); 8 + const localData = dateUtil.localeData(getLang.value);
9 let timer: IntervalHandle; 9 let timer: IntervalHandle;
10 10
11 const state = reactive({ 11 const state = reactive({
@@ -20,7 +20,7 @@ export function useNow(immediate = true) { @@ -20,7 +20,7 @@ export function useNow(immediate = true) {
20 }); 20 });
21 21
22 const update = () => { 22 const update = () => {
23 - const now = moment(); 23 + const now = dateUtil();
24 24
25 const h = now.format('HH'); 25 const h = now.format('HH');
26 const m = now.format('mm'); 26 const m = now.format('mm');
vite.config.ts
@@ -8,7 +8,6 @@ import { loadEnv } from 'vite'; @@ -8,7 +8,6 @@ import { loadEnv } from 'vite';
8 8
9 import { modifyVars } from './build/config/lessModifyVars'; 9 import { modifyVars } from './build/config/lessModifyVars';
10 import { createProxy } from './build/vite/proxy'; 10 import { createProxy } from './build/vite/proxy';
11 -import { configManualChunk } from './build/vite/optimizer';  
12 11
13 import { wrapperEnv } from './build/utils'; 12 import { wrapperEnv } from './build/utils';
14 13
@@ -53,9 +52,11 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { @@ -53,9 +52,11 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
53 rollupOptions: { 52 rollupOptions: {
54 output: { 53 output: {
55 compact: true, 54 compact: true,
56 - manualChunks: configManualChunk,  
57 }, 55 },
58 }, 56 },
  57 + commonjsOptions: {
  58 + ignore: ['fs', 'crypto', 'stream'],
  59 + },
59 }, 60 },
60 define: { 61 define: {
61 __VERSION__: pkg.version, 62 __VERSION__: pkg.version,
@@ -69,7 +70,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { @@ -69,7 +70,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
69 preprocessorOptions: { 70 preprocessorOptions: {
70 less: { 71 less: {
71 modifyVars: { 72 modifyVars: {
72 - // reference: Avoid repeated references 73 + // reference: Avoid repeated references
73 hack: `true; @import (reference) "${resolve('src/design/config.less')}";`, 74 hack: `true; @import (reference) "${resolve('src/design/config.less')}";`,
74 ...modifyVars, 75 ...modifyVars,
75 }, 76 },
@@ -86,7 +87,11 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { @@ -86,7 +87,11 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
86 ], 87 ],
87 88
88 optimizeDeps: { 89 optimizeDeps: {
89 - include: ['ant-design-vue/es/locale/zh_CN', 'ant-design-vue/es/locale/en_US'], 90 + include: [
  91 + 'ant-design-vue/es/locale/zh_CN',
  92 + 'moment/dist/locale/zh-cn',
  93 + 'ant-design-vue/es/locale/en_US',
  94 + ],
90 }, 95 },
91 }; 96 };
92 }; 97 };
yarn.lock
@@ -925,7 +925,7 @@ @@ -925,7 +925,7 @@
925 globals "^11.1.0" 925 globals "^11.1.0"
926 lodash "^4.17.19" 926 lodash "^4.17.19"
927 927
928 -"@babel/traverse@^7.0.0", "@babel/traverse@^7.12.12": 928 +"@babel/traverse@^7.0.0":
929 version "7.12.12" 929 version "7.12.12"
930 resolved "https://registry.npmjs.org/@babel/traverse/-/traverse-7.12.12.tgz#d0cd87892704edd8da002d674bc811ce64743376" 930 resolved "https://registry.npmjs.org/@babel/traverse/-/traverse-7.12.12.tgz#d0cd87892704edd8da002d674bc811ce64743376"
931 integrity sha512-s88i0X0lPy45RrLM8b9mz8RPH5FqO9G9p7ti59cToE44xFm1Q+Pjh5Gq4SXBbtb88X7Uy7pexeqRIQDDMNkL0w== 931 integrity sha512-s88i0X0lPy45RrLM8b9mz8RPH5FqO9G9p7ti59cToE44xFm1Q+Pjh5Gq4SXBbtb88X7Uy7pexeqRIQDDMNkL0w==
@@ -7798,21 +7798,10 @@ vite-plugin-html@^2.0.0-beta.5: @@ -7798,21 +7798,10 @@ vite-plugin-html@^2.0.0-beta.5:
7798 ejs "^3.1.5" 7798 ejs "^3.1.5"
7799 html-minifier-terser "^5.1.1" 7799 html-minifier-terser "^5.1.1"
7800 7800
7801 -vite-plugin-import-context@^1.0.0-rc.1:  
7802 - version "1.0.0-rc.1"  
7803 - resolved "https://registry.npmjs.org/vite-plugin-import-context/-/vite-plugin-import-context-1.0.0-rc.1.tgz#ce3faf51b0c8d2e33bb434326b5dbd89ec7e7229"  
7804 - integrity sha512-ZVhj9npqduN+WFhA59LxvyHnrN4lEJlA5RkpYChqtVev7greyemioUpyzdgKxkXhdDVApYBOlGcRTU7rr1+Fdg==  
7805 - dependencies:  
7806 - "@babel/core" "^7.12.10"  
7807 - "@babel/plugin-transform-typescript" "^7.12.1"  
7808 - "@babel/traverse" "^7.12.12"  
7809 - "@rollup/pluginutils" "^4.1.0"  
7810 - debug "^4.3.1"  
7811 -  
7812 -vite-plugin-mock@^2.0.0-beta.1:  
7813 - version "2.0.0-beta.1"  
7814 - resolved "https://registry.npmjs.org/vite-plugin-mock/-/vite-plugin-mock-2.0.0-beta.1.tgz#660c3b7867c84d20c82bf2e074e9b8377d2a9427"  
7815 - integrity sha512-wnMAfVGXsYDlSWD4kV0xG9X6ZWir1UGsH4xeGzxbAU0XlkgQgJxxFJ1/j+QjD8bauKmuU9QUW1uAr9TWwzTShg== 7801 +vite-plugin-mock@^2.0.0-beta.3:
  7802 + version "2.0.0-beta.3"
  7803 + resolved "https://registry.npmjs.org/vite-plugin-mock/-/vite-plugin-mock-2.0.0-beta.3.tgz#5276b86734106ccd7aaa299bfb0d16a86c8d2823"
  7804 + integrity sha512-LfgXV3Mzulz89OfuXysxLpnyu66mDiFAeBjwx24N/OiEyZEHagbVRVOJU8Xz/oTmtH7EP/AyrYjQFRb2elQ0BQ==
7816 dependencies: 7805 dependencies:
7817 "@rollup/plugin-node-resolve" "^11.0.1" 7806 "@rollup/plugin-node-resolve" "^11.0.1"
7818 body-parser "^1.19.0" 7807 body-parser "^1.19.0"
@@ -7835,20 +7824,20 @@ vite-plugin-purge-icons@^0.5.0: @@ -7835,20 +7824,20 @@ vite-plugin-purge-icons@^0.5.0:
7835 "@purge-icons/generated" "^0.5.0" 7824 "@purge-icons/generated" "^0.5.0"
7836 rollup-plugin-purge-icons "^0.5.0" 7825 rollup-plugin-purge-icons "^0.5.0"
7837 7826
7838 -vite-plugin-pwa@^0.3.3:  
7839 - version "0.3.3"  
7840 - resolved "https://registry.npmjs.org/vite-plugin-pwa/-/vite-plugin-pwa-0.3.3.tgz#00ece9b7b558153a4afa3fbbac2913c5b3ff6fa8"  
7841 - integrity sha512-aojgEk9u1Aaoo80zT8AdhGlPUrWHmV9fdJhbj/9vvEyj02DJQCvu7rr5gEJJRjtUSS+xtzIWzy2Rc3P+x4gD5A== 7827 +vite-plugin-pwa@^0.3.5:
  7828 + version "0.3.5"
  7829 + resolved "https://registry.npmjs.org/vite-plugin-pwa/-/vite-plugin-pwa-0.3.5.tgz#a1700e60ab91fa5fa92d0bdf7102ac87187ac00e"
  7830 + integrity sha512-mabDRu/rk6w/f5eXGlNzD8GJCw8kKeg82UTLmaUYj3M7G5eKvyRYTXVPY2TPe1WWPMTE1c3Ypw9iL4QDV707Ww==
7842 dependencies: 7831 dependencies:
7843 debug "^4.3.2" 7832 debug "^4.3.2"
7844 fast-glob "^3.2.4" 7833 fast-glob "^3.2.4"
7845 pretty-bytes "^5.5.0" 7834 pretty-bytes "^5.5.0"
7846 workbox-build "^6.0.2" 7835 workbox-build "^6.0.2"
7847 7836
7848 -vite@^2.0.0-beta.19:  
7849 - version "2.0.0-beta.19"  
7850 - resolved "https://registry.npmjs.org/vite/-/vite-2.0.0-beta.19.tgz#9e1a3ff4843d8e72fc2b771691c43124ceeacd21"  
7851 - integrity sha512-6EJAPypH8m9lCK2pB1UfU+qBw65wCHFoMITtFotDAd03m5hz2d9cPXfPgaCk0PhQPgtGcgn5xeAfLIdZ5e6cPA== 7837 +vite@^2.0.0-beta.21:
  7838 + version "2.0.0-beta.21"
  7839 + resolved "https://registry.npmjs.org/vite/-/vite-2.0.0-beta.21.tgz#9a7233c93ed59c5b5de28c3a74f1e94b815d746e"
  7840 + integrity sha512-B6OhGHwh4DTkDBxZXtGhxmDkK75M3o0sKFz/cfZ2bdqxRze870sJgH66kPuYWjgSVDdPz0NTIKBaxrbcA8wwmw==
7852 dependencies: 7841 dependencies:
7853 esbuild "^0.8.26" 7842 esbuild "^0.8.26"
7854 postcss "^8.2.1" 7843 postcss "^8.2.1"