既然使用vite那就使用vue3.x,既然使用vue3.x那就使用ts,要不完全没必要升级技术,vue2.x也挺香的,所以给自己定个要求吧

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