You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.9 KiB

3 years ago
3 years ago
3 years ago
3 years ago
  1. import { resolve } from "path";
  2. import { UserConfigExport, ConfigEnv, loadEnv } from "vite";
  3. import vue from "@vitejs/plugin-vue";
  4. import vueJsx from "@vitejs/plugin-vue-jsx";
  5. import { warpperEnv } from "./build/utils";
  6. import { createProxy } from "./build/proxy";
  7. import { viteMockServe } from "vite-plugin-mock";
  8. import svgLoader from "vite-svg-loader";
  9. import styleImport from "vite-plugin-style-import";
  10. import ElementPlus from "unplugin-element-plus/vite";
  11. const pathResolve = (dir: string): string => {
  12. return resolve(__dirname, ".", dir);
  13. };
  14. const alias: Record<string, string> = {
  15. "/@": pathResolve("src"),
  16. "@build": pathResolve("build"),
  17. //解决开发环境下的警告 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.
  18. "vue-i18n": "vue-i18n/dist/vue-i18n.cjs.js"
  19. };
  20. const root: string = process.cwd();
  21. export default ({ command, mode }: ConfigEnv): UserConfigExport => {
  22. const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY } = warpperEnv(
  23. loadEnv(mode, root)
  24. );
  25. const prodMock = true;
  26. return {
  27. /**
  28. *
  29. * /manages/ /manages/
  30. * @default '/'
  31. */
  32. base:
  33. process.env.NODE_ENV === "production" ? "/manages/" : VITE_PUBLIC_PATH,
  34. root,
  35. resolve: {
  36. alias
  37. },
  38. // 服务端渲染
  39. server: {
  40. // 是否开启 https
  41. https: false,
  42. /**
  43. *
  44. * @default 3000
  45. */
  46. port: VITE_PORT,
  47. host: "0.0.0.0",
  48. // 本地跨域代理
  49. proxy: createProxy(VITE_PROXY)
  50. },
  51. plugins: [
  52. vue(),
  53. vueJsx(),
  54. svgLoader(),
  55. styleImport({
  56. libs: [
  57. // 按需加载vxe-table
  58. {
  59. libraryName: "vxe-table",
  60. esModule: true,
  61. ensureStyleFile: true,
  62. resolveComponent: name => `vxe-table/es/${name}`,
  63. resolveStyle: name => `vxe-table/es/${name}/style.css`
  64. }
  65. ]
  66. }),
  67. ElementPlus({}),
  68. viteMockServe({
  69. mockPath: "mock",
  70. localEnabled: command === "serve",
  71. prodEnabled: command !== "serve" && prodMock,
  72. injectCode: `
  73. import { setupProdMockServer } from './mockProdServer';
  74. setupProdMockServer();
  75. `,
  76. logger: true
  77. })
  78. ],
  79. optimizeDeps: {
  80. include: [
  81. "element-plus/lib/locale/lang/zh-cn",
  82. "element-plus/lib/locale/lang/en",
  83. "vxe-table/lib/locale/lang/zh-CN",
  84. "vxe-table/lib/locale/lang/en-US"
  85. ]
  86. },
  87. build: {
  88. // @ts-ignore
  89. sourcemap: false,
  90. brotliSize: false,
  91. // 消除打包大小超过500kb警告
  92. chunkSizeWarningLimit: 2000
  93. },
  94. define: {
  95. __INTLIFY_PROD_DEVTOOLS__: false
  96. }
  97. };
  98. };