vue-pure-admin2/vite.config.ts

105 lines
2.9 KiB
TypeScript
Raw Normal View History

2021-04-21 23:20:14 +08:00
import { resolve } from "path";
import { UserConfigExport, ConfigEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import { loadEnv } from "./build/utils";
import { createProxy } from "./build/proxy";
import { viteMockServe } from "vite-plugin-mock";
import styleImport from "vite-plugin-style-import";
2021-03-01 15:26:05 +08:00
const pathResolve = (dir: string): any => {
2021-04-21 23:20:14 +08:00
return resolve(__dirname, ".", dir);
};
2021-03-01 15:26:05 +08:00
2021-07-07 13:33:47 +08:00
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY } = loadEnv();
2021-03-01 15:26:05 +08:00
const alias: Record<string, string> = {
2021-04-21 23:20:14 +08:00
"/@": pathResolve("src"),
2021-04-29 03:12:44 +08:00
//解决开发环境下的警告 You are running the esm-bundler build of vue-i18n. It is recommended to configure your bundler to explicitly replace feature flag globals with boolean literals to get proper tree-shaking in the final bundle.
2021-07-07 13:33:47 +08:00
"vue-i18n": "vue-i18n/dist/vue-i18n.cjs.js"
2021-04-21 23:20:14 +08:00
};
2021-03-01 15:26:05 +08:00
2021-04-21 23:20:14 +08:00
const root: string = process.cwd();
2021-03-01 15:26:05 +08:00
export default ({ command }: ConfigEnv): UserConfigExport => {
2021-07-07 13:33:47 +08:00
const prodMock = true;
return {
2021-03-01 15:26:05 +08:00
/**
*
2021-04-21 23:20:14 +08:00
* /manages/ /manages/
* @default '/'
2021-03-01 15:26:05 +08:00
*/
2021-04-21 23:20:14 +08:00
base:
process.env.NODE_ENV === "production" ? "/manages/" : VITE_PUBLIC_PATH,
root,
resolve: {
2021-07-07 13:33:47 +08:00
alias
},
// 服务端渲染
server: {
// 是否开启 https
https: false,
/**
*
* @default 3000
*/
port: VITE_PORT,
// 本地跨域代理
2021-07-07 13:33:47 +08:00
proxy: createProxy(VITE_PROXY)
},
plugins: [
vue(),
vueJsx(),
2021-04-21 23:20:14 +08:00
styleImport({
libs: [
// 按需加载element-plus
{
libraryName: "element-plus",
esModule: true,
ensureStyleFile: true,
2021-07-07 13:33:47 +08:00
resolveStyle: name => {
2021-04-21 23:20:14 +08:00
return `element-plus/lib/theme-chalk/${name}.css`;
},
2021-07-07 13:33:47 +08:00
resolveComponent: name => {
2021-04-21 23:20:14 +08:00
return `element-plus/lib/${name}`;
2021-07-07 13:33:47 +08:00
}
2021-04-21 23:20:14 +08:00
},
// 按需加载vxe-table
{
libraryName: "vxe-table",
esModule: true,
2021-07-07 13:33:47 +08:00
resolveComponent: name => `vxe-table/es/${name}`,
resolveStyle: name => `vxe-table/es/${name}/style.css`
}
]
2021-04-21 23:20:14 +08:00
}),
viteMockServe({
2021-04-21 23:20:14 +08:00
mockPath: "mock",
localEnabled: command === "serve",
prodEnabled: command !== "serve" && prodMock,
injectCode: `
import { setupProdMockServer } from './mockProdServer';
setupProdMockServer();
`,
2021-07-07 13:33:47 +08:00
logger: true
})
],
2021-04-21 23:20:14 +08:00
optimizeDeps: {
include: [
"element-plus/lib/locale/lang/zh-cn",
"element-plus/lib/locale/lang/en",
2021-05-09 22:37:17 +08:00
"vxe-table/lib/locale/lang/zh-CN",
2021-07-07 13:33:47 +08:00
"vxe-table/lib/locale/lang/en-US"
]
2021-04-21 23:20:14 +08:00
},
build: {
brotliSize: false,
// 消除打包大小超过500kb警告
2021-07-07 13:33:47 +08:00
chunkSizeWarningLimit: 2000
2021-04-09 12:54:03 +08:00
},
define: {
2021-07-07 13:33:47 +08:00
__INTLIFY_PROD_DEVTOOLS__: false
}
2021-04-21 23:20:14 +08:00
};
};