提交 3509ebec 编写于 作者: V vben

fix: mock plugin error #171

上级 8bd20c6c
......@@ -13,3 +13,6 @@ indent_size = 2
[*.md]
trim_trailing_whitespace = false
[Makefile]
indent_style = tab
......@@ -2,13 +2,13 @@
VITE_USE_MOCK = true
# public path
VITE_PUBLIC_PATH = ./
VITE_PUBLIC_PATH = /
# Delete console
VITE_DROP_CONSOLE = true
# Whether to output gz file for packaging
VITE_BUILD_GZIP = true
VITE_BUILD_GZIP = false
# Basic interface address SPA
VITE_GLOB_API_URL=/api
......
import fs from 'fs-extra';
import path from 'path';
// 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'
function replaceCjs() {
const xlsx = path.resolve(process.cwd(), 'node_modules/xlsx/xlsx.js');
let raw = fs.readFileSync(xlsx, 'utf-8');
raw = raw
.replace(`require('fs')`, '{}')
.replace(`require('stream')`, '{}')
.replace(`require('crypto')`, '{}');
fs.writeFileSync(xlsx, raw);
}
replaceCjs();
......@@ -2,10 +2,10 @@ import type { GetManualChunk, GetManualChunkApi } from 'rollup';
//
const vendorLibs: { match: string[]; output: string }[] = [
{
match: ['xlsx'],
output: 'xlsx',
},
// {
// match: ['xlsx'],
// output: 'xlsx',
// },
];
// @ts-ignore
......
......@@ -2,7 +2,7 @@ import gzipPlugin from 'rollup-plugin-gzip';
import { isBuildGzip } from '../../utils';
import { Plugin } from 'vite';
export function configGzipPlugin(isBuild: boolean): Plugin | Plugin[] {
const useGzip = isBuild && isBuildGzip;
const useGzip = isBuild && isBuildGzip();
if (useGzip) {
return gzipPlugin();
......
{
"name": "vben-admin",
"version": "2.0.0-rc.16",
"version": "2.0.0-rc.15",
"scripts": {
"bootstrap": "yarn install",
"serve": "vite",
......@@ -15,9 +15,7 @@
"lint:eslint": "eslint --fix --ext \"src/**/*.{vue,less,css,scss}\"",
"lint:prettier": "prettier --write --loglevel warn \"src/**/*.{js,json,tsx,css,less,scss,vue,html,md}\"",
"lint:stylelint": "stylelint --fix \"**/*.{vue,less,postcss,css,scss}\" --cache --cache-location node_modules/.cache/stylelint/",
"reinstall": "rimraf yarn.lock && rimraf package.lock.json && rimraf node_modules && npm run bootstrap",
"hack-esm:xlsx": "esno ./build/script/hackXlsx",
"postinstall": "npm run hack-esm:xlsx"
"reinstall": "rimraf yarn.lock && rimraf package.lock.json && rimraf node_modules && npm run bootstrap"
},
"dependencies": {
"@iconify/iconify": "^2.0.0-rc.5",
......@@ -98,11 +96,11 @@
"stylelint-order": "^4.1.0",
"ts-node": "^9.1.0",
"typescript": "^4.1.3",
"vite": "^2.0.0-beta.19",
"vite": "^2.0.0-beta.21",
"vite-plugin-html": "^2.0.0-beta.5",
"vite-plugin-mock": "^2.0.0-beta.1",
"vite-plugin-mock": "^2.0.0-beta.3",
"vite-plugin-purge-icons": "^0.5.0",
"vite-plugin-pwa": "^0.3.3",
"vite-plugin-pwa": "^0.3.5",
"vue-eslint-parser": "^7.3.0",
"yargs": "^16.2.0"
},
......
......@@ -41,7 +41,8 @@
import FormAction from './components/FormAction.vue';
import { dateItemType } from './helper';
import moment from 'moment';
import { dateUtil } from '/@/utils/dateUtil';
// import { cloneDeep } from 'lodash-es';
import { deepMerge } from '/@/utils';
......@@ -108,11 +109,11 @@
// handle date type
if (defaultValue && dateItemType.includes(component)) {
if (!Array.isArray(defaultValue)) {
schema.defaultValue = moment(defaultValue);
schema.defaultValue = dateUtil(defaultValue);
} else {
const def: moment.Moment[] = [];
defaultValue.forEach((item) => {
def.push(moment(item));
def.push(dateUtil(item));
});
schema.defaultValue = def;
}
......
......@@ -7,7 +7,7 @@ import { unref, toRaw } from 'vue';
import { isArray, isFunction, isObject, isString } from '/@/utils/is';
import { deepMerge, unique } from '/@/utils';
import { dateItemType, handleInputNumberValue } from '../helper';
import moment from 'moment';
import { dateUtil } from '/@/utils/dateUtil';
import { cloneDeep } from 'lodash-es';
import { error } from '/@/utils/log';
......@@ -67,11 +67,11 @@ export function useFormEvents({
if (Array.isArray(value)) {
const arr: moment.Moment[] = [];
for (const ele of value) {
arr.push(moment(ele));
arr.push(dateUtil(ele));
}
formModel[key] = arr;
} else {
formModel[key] = moment(value);
formModel[key] = dateUtil(value);
}
} else {
formModel[key] = value;
......
import { isArray, isFunction, isObject, isString } from '/@/utils/is';
import moment from 'moment';
import { dateUtil } from '/@/utils/dateUtil';
import { unref, nextTick } from 'vue';
import type { Ref, ComputedRef } from 'vue';
import type { FieldMapToTime, FormSchema } from '../types/form';
......@@ -65,8 +66,8 @@ export function useFormValues({
const [startTime, endTime]: string[] = values[field];
values[startTimeKey] = moment(startTime).format(format);
values[endTimeKey] = moment(endTime).format(format);
values[startTimeKey] = dateUtil(startTime).format(format);
values[endTimeKey] = dateUtil(endTime).format(format);
Reflect.deleteProperty(values, field);
}
......
......@@ -3,8 +3,6 @@ import type { I18n, I18nOptions } from 'vue-i18n';
import { createI18n } from 'vue-i18n';
import 'moment/dist/locale/zh-cn';
import projectSetting from '/@/settings/projectSetting';
import messages from './getMessage';
......
......@@ -7,9 +7,7 @@ import type { Ref } from 'vue';
import { unref, ref } from 'vue';
import { useLocaleSetting } from '/@/hooks/setting/useLocaleSetting';
import moment from 'moment';
import 'moment/dist/locale/zh-cn';
import { dateUtil } from '/@/utils/dateUtil';
import { i18n } from './setupI18n';
......@@ -36,14 +34,14 @@ export function useLocale() {
antConfigLocaleRef.value = locale.default;
});
moment.locale('cn');
dateUtil.locale('cn');
break;
// English
case 'en':
import('ant-design-vue/es/locale/en_US').then((locale) => {
antConfigLocaleRef.value = locale.default;
});
moment.locale('en-us');
dateUtil.locale('en-us');
break;
// other
......
import moment from 'moment';
import { dateUtil } from '/@/utils/dateUtil';
import { reactive, toRefs } from 'vue';
import { tryOnMounted, tryOnUnmounted } from '/@/utils/helper/vueHelper';
import { useLocaleSetting } from '/@/hooks/setting/useLocaleSetting';
export function useNow(immediate = true) {
const { getLang } = useLocaleSetting();
const localData = moment.localeData(getLang.value);
const localData = dateUtil.localeData(getLang.value);
let timer: IntervalHandle;
const state = reactive({
......@@ -20,7 +20,7 @@ export function useNow(immediate = true) {
});
const update = () => {
const now = moment();
const now = dateUtil();
const h = now.format('HH');
const m = now.format('mm');
......
......@@ -8,7 +8,6 @@ import { loadEnv } from 'vite';
import { modifyVars } from './build/config/lessModifyVars';
import { createProxy } from './build/vite/proxy';
import { configManualChunk } from './build/vite/optimizer';
import { wrapperEnv } from './build/utils';
......@@ -53,9 +52,11 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
rollupOptions: {
output: {
compact: true,
manualChunks: configManualChunk,
},
},
commonjsOptions: {
ignore: ['fs', 'crypto', 'stream'],
},
},
define: {
__VERSION__: pkg.version,
......@@ -69,7 +70,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
preprocessorOptions: {
less: {
modifyVars: {
// reference: Avoid repeated references
// reference: Avoid repeated references
hack: `true; @import (reference) "${resolve('src/design/config.less')}";`,
...modifyVars,
},
......@@ -86,7 +87,11 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
],
optimizeDeps: {
include: ['ant-design-vue/es/locale/zh_CN', 'ant-design-vue/es/locale/en_US'],
include: [
'ant-design-vue/es/locale/zh_CN',
'moment/dist/locale/zh-cn',
'ant-design-vue/es/locale/en_US',
],
},
};
};
......@@ -925,7 +925,7 @@
globals "^11.1.0"
lodash "^4.17.19"
"@babel/traverse@^7.0.0", "@babel/traverse@^7.12.12":
"@babel/traverse@^7.0.0":
version "7.12.12"
resolved "https://registry.npmjs.org/@babel/traverse/-/traverse-7.12.12.tgz#d0cd87892704edd8da002d674bc811ce64743376"
integrity sha512-s88i0X0lPy45RrLM8b9mz8RPH5FqO9G9p7ti59cToE44xFm1Q+Pjh5Gq4SXBbtb88X7Uy7pexeqRIQDDMNkL0w==
......@@ -7798,21 +7798,10 @@ vite-plugin-html@^2.0.0-beta.5:
ejs "^3.1.5"
html-minifier-terser "^5.1.1"
vite-plugin-import-context@^1.0.0-rc.1:
version "1.0.0-rc.1"
resolved "https://registry.npmjs.org/vite-plugin-import-context/-/vite-plugin-import-context-1.0.0-rc.1.tgz#ce3faf51b0c8d2e33bb434326b5dbd89ec7e7229"
integrity sha512-ZVhj9npqduN+WFhA59LxvyHnrN4lEJlA5RkpYChqtVev7greyemioUpyzdgKxkXhdDVApYBOlGcRTU7rr1+Fdg==
dependencies:
"@babel/core" "^7.12.10"
"@babel/plugin-transform-typescript" "^7.12.1"
"@babel/traverse" "^7.12.12"
"@rollup/pluginutils" "^4.1.0"
debug "^4.3.1"
vite-plugin-mock@^2.0.0-beta.1:
version "2.0.0-beta.1"
resolved "https://registry.npmjs.org/vite-plugin-mock/-/vite-plugin-mock-2.0.0-beta.1.tgz#660c3b7867c84d20c82bf2e074e9b8377d2a9427"
integrity sha512-wnMAfVGXsYDlSWD4kV0xG9X6ZWir1UGsH4xeGzxbAU0XlkgQgJxxFJ1/j+QjD8bauKmuU9QUW1uAr9TWwzTShg==
vite-plugin-mock@^2.0.0-beta.3:
version "2.0.0-beta.3"
resolved "https://registry.npmjs.org/vite-plugin-mock/-/vite-plugin-mock-2.0.0-beta.3.tgz#5276b86734106ccd7aaa299bfb0d16a86c8d2823"
integrity sha512-LfgXV3Mzulz89OfuXysxLpnyu66mDiFAeBjwx24N/OiEyZEHagbVRVOJU8Xz/oTmtH7EP/AyrYjQFRb2elQ0BQ==
dependencies:
"@rollup/plugin-node-resolve" "^11.0.1"
body-parser "^1.19.0"
......@@ -7835,20 +7824,20 @@ vite-plugin-purge-icons@^0.5.0:
"@purge-icons/generated" "^0.5.0"
rollup-plugin-purge-icons "^0.5.0"
vite-plugin-pwa@^0.3.3:
version "0.3.3"
resolved "https://registry.npmjs.org/vite-plugin-pwa/-/vite-plugin-pwa-0.3.3.tgz#00ece9b7b558153a4afa3fbbac2913c5b3ff6fa8"
integrity sha512-aojgEk9u1Aaoo80zT8AdhGlPUrWHmV9fdJhbj/9vvEyj02DJQCvu7rr5gEJJRjtUSS+xtzIWzy2Rc3P+x4gD5A==
vite-plugin-pwa@^0.3.5:
version "0.3.5"
resolved "https://registry.npmjs.org/vite-plugin-pwa/-/vite-plugin-pwa-0.3.5.tgz#a1700e60ab91fa5fa92d0bdf7102ac87187ac00e"
integrity sha512-mabDRu/rk6w/f5eXGlNzD8GJCw8kKeg82UTLmaUYj3M7G5eKvyRYTXVPY2TPe1WWPMTE1c3Ypw9iL4QDV707Ww==
dependencies:
debug "^4.3.2"
fast-glob "^3.2.4"
pretty-bytes "^5.5.0"
workbox-build "^6.0.2"
vite@^2.0.0-beta.19:
version "2.0.0-beta.19"
resolved "https://registry.npmjs.org/vite/-/vite-2.0.0-beta.19.tgz#9e1a3ff4843d8e72fc2b771691c43124ceeacd21"
integrity sha512-6EJAPypH8m9lCK2pB1UfU+qBw65wCHFoMITtFotDAd03m5hz2d9cPXfPgaCk0PhQPgtGcgn5xeAfLIdZ5e6cPA==
vite@^2.0.0-beta.21:
version "2.0.0-beta.21"
resolved "https://registry.npmjs.org/vite/-/vite-2.0.0-beta.21.tgz#9a7233c93ed59c5b5de28c3a74f1e94b815d746e"
integrity sha512-B6OhGHwh4DTkDBxZXtGhxmDkK75M3o0sKFz/cfZ2bdqxRze870sJgH66kPuYWjgSVDdPz0NTIKBaxrbcA8wwmw==
dependencies:
esbuild "^0.8.26"
postcss "^8.2.1"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册