提交 daf2b1e0 作者: vben

wip: suppoer vite2 -- hack xlsx

上级 47f72e7e
import fs from 'fs';
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();
...@@ -15,7 +15,9 @@ ...@@ -15,7 +15,9 @@
"lint:eslint": "eslint --fix --ext \"src/**/*.{vue,less,css,scss}\"", "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: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/", "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" "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"
}, },
"dependencies": { "dependencies": {
"@iconify/iconify": "^2.0.0-rc.5", "@iconify/iconify": "^2.0.0-rc.5",
...@@ -39,6 +41,7 @@ ...@@ -39,6 +41,7 @@
"vue-types": "^3.0.1", "vue-types": "^3.0.1",
"vuex": "^4.0.0-rc.2", "vuex": "^4.0.0-rc.2",
"vuex-module-decorators": "^1.0.1", "vuex-module-decorators": "^1.0.1",
"xlsx": "^0.16.9",
"zxcvbn": "^4.4.2" "zxcvbn": "^4.4.2"
}, },
"devDependencies": { "devDependencies": {
...@@ -61,8 +64,8 @@ ...@@ -61,8 +64,8 @@
"@types/zxcvbn": "^4.4.0", "@types/zxcvbn": "^4.4.0",
"@typescript-eslint/eslint-plugin": "^4.12.0", "@typescript-eslint/eslint-plugin": "^4.12.0",
"@typescript-eslint/parser": "^4.12.0", "@typescript-eslint/parser": "^4.12.0",
"@vitejs/plugin-legacy": "^1.1.0", "@vitejs/plugin-legacy": "^1.1.1",
"@vitejs/plugin-vue": "^1.0.4", "@vitejs/plugin-vue": "^1.0.5",
"@vitejs/plugin-vue-jsx": "^1.0.1", "@vitejs/plugin-vue-jsx": "^1.0.1",
"@vue/compiler-sfc": "^3.0.5", "@vue/compiler-sfc": "^3.0.5",
"@vuedx/typecheck": "^0.4.1", "@vuedx/typecheck": "^0.4.1",
...@@ -95,7 +98,7 @@ ...@@ -95,7 +98,7 @@
"stylelint-order": "^4.1.0", "stylelint-order": "^4.1.0",
"ts-node": "^9.1.0", "ts-node": "^9.1.0",
"typescript": "^4.1.3", "typescript": "^4.1.3",
"vite": "^2.0.0-beta.15", "vite": "^2.0.0-beta.16",
"vite-plugin-html": "^2.0.0-beta.5", "vite-plugin-html": "^2.0.0-beta.5",
"vite-plugin-import-context": "^1.0.0-rc.1", "vite-plugin-import-context": "^1.0.0-rc.1",
"vite-plugin-mock": "^2.0.0-beta.1", "vite-plugin-mock": "^2.0.0-beta.1",
......
...@@ -12,10 +12,11 @@ const LayoutMap = new Map<LayoutMapKey, () => Promise<typeof import('*.vue')>>() ...@@ -12,10 +12,11 @@ const LayoutMap = new Map<LayoutMapKey, () => Promise<typeof import('*.vue')>>()
// 动态引入 // 动态引入
function asyncImportRoute(routes: AppRouteRecordRaw[] | undefined) { function asyncImportRoute(routes: AppRouteRecordRaw[] | undefined) {
// TODO Because xlsx does not support vite2.0 temporarily. So filter the excel example first // TODO Because xlsx does not support vite2.0 temporarily. So filter the excel example first
// regexp: /^(?!.*\/demo\/excel).*\.(tsx?|vue)$/,
const dynamicViewsModules = importContext({ const dynamicViewsModules = importContext({
dir: '/@/views', dir: '/@/views',
deep: true, deep: true,
regexp: /^(?!.*\/demo\/excel).*\.(tsx?|vue)$/, regexp: /\.(tsx?|vue)$/,
dynamicImport: true, dynamicImport: true,
dynamicEnabled: 'autoImportRoute', dynamicEnabled: 'autoImportRoute',
}); });
......
...@@ -172,51 +172,51 @@ const feat: AppRouteModule = { ...@@ -172,51 +172,51 @@ const feat: AppRouteModule = {
title: t('routes.demo.feat.errorLog'), title: t('routes.demo.feat.errorLog'),
}, },
}, },
// { {
// path: 'excel', path: 'excel',
// name: 'Excel', name: 'Excel',
// redirect: '/feat/excel/customExport', redirect: '/feat/excel/customExport',
// component: getParentLayout('Excel'), component: getParentLayout('Excel'),
// meta: { meta: {
// // icon: 'mdi:microsoft-excel', // icon: 'mdi:microsoft-excel',
// title: t('routes.demo.excel.excel'), title: t('routes.demo.excel.excel'),
// }, },
// children: [ children: [
// { {
// path: 'customExport', path: 'customExport',
// name: 'CustomExport', name: 'CustomExport',
// component: () => import('/@/views/demo/excel/CustomExport.vue'), component: () => import('/@/views/demo/excel/CustomExport.vue'),
// meta: { meta: {
// title: t('routes.demo.excel.customExport'), title: t('routes.demo.excel.customExport'),
// }, },
// }, },
// { {
// path: 'jsonExport', path: 'jsonExport',
// name: 'JsonExport', name: 'JsonExport',
// component: () => import('/@/views/demo/excel/JsonExport.vue'), component: () => import('/@/views/demo/excel/JsonExport.vue'),
// meta: { meta: {
// title: t('routes.demo.excel.jsonExport'), title: t('routes.demo.excel.jsonExport'),
// }, },
// }, },
// { {
// path: 'arrayExport', path: 'arrayExport',
// name: 'ArrayExport', name: 'ArrayExport',
// component: () => import('/@/views/demo/excel/ArrayExport.vue'), component: () => import('/@/views/demo/excel/ArrayExport.vue'),
// meta: { meta: {
// title: t('routes.demo.excel.arrayExport'), title: t('routes.demo.excel.arrayExport'),
// }, },
// }, },
// { {
// path: 'importExcel', path: 'importExcel',
// name: 'ImportExcel', name: 'ImportExcel',
// component: () => import('/@/views/demo/excel/ImportExcel.vue'), component: () => import('/@/views/demo/excel/ImportExcel.vue'),
// meta: { meta: {
// title: t('routes.demo.excel.importExcel'), title: t('routes.demo.excel.importExcel'),
// }, },
// }, },
// ], ],
// }, },
{ {
path: 'testTab/:id', path: 'testTab/:id',
name: 'TestTab', name: 'TestTab',
......
...@@ -69,7 +69,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { ...@@ -69,7 +69,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
preprocessorOptions: { preprocessorOptions: {
less: { less: {
modifyVars: { modifyVars: {
// reference Avoid repeated references // reference: Avoid repeated references
hack: `true; @import (reference) "${resolve('src/design/config.less')}";`, hack: `true; @import (reference) "${resolve('src/design/config.less')}";`,
...modifyVars, ...modifyVars,
}, },
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论