vite.config.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import vue from '@vitejs/plugin-vue';
  2. import viteCompression from 'vite-plugin-compression'
  3. import { resolve } from 'path';
  4. import { defineConfig, loadEnv, ConfigEnv } from 'vite';
  5. const pathResolve = (dir: string): any => {
  6. return resolve(__dirname, '.', dir);
  7. };
  8. const alias: Record<string, string> = {
  9. '/@': pathResolve('./src/'),
  10. 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
  11. '@form-create/component-wangeditor': '/node_modules/@form-create/component-wangeditor/dist/index.js',
  12. '@form-create/designer': pathResolve('./src/components/form-create-designer/index.js'),
  13. };
  14. const viteConfig = defineConfig((mode: ConfigEnv) => {
  15. const env = loadEnv(mode.mode, process.cwd());
  16. return {
  17. plugins: [
  18. vue(),
  19. viteCompression({
  20. threshold: 1024 * 20, // 对大于 20k 的文件进行压缩
  21. // filter: /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i, // 需要压缩的文件
  22. algorithm: 'gzip', // 压缩方式
  23. ext: 'gz', // 后缀名
  24. deleteOriginFile: false, // 压缩后是否删除压缩源文件
  25. })
  26. ],
  27. root: process.cwd(),
  28. resolve: { alias },
  29. base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH,
  30. optimizeDeps: {
  31. include: ['element-plus/lib/locale/lang/zh-cn', 'element-plus/lib/locale/lang/en', 'element-plus/lib/locale/lang/zh-tw'],
  32. },
  33. server: {
  34. port: env.VITE_PORT as unknown as number,
  35. host: true,
  36. open: true,
  37. hmr: true,
  38. // proxy: {
  39. // [env.VITE_NGINX_PROXY ? env.VITE_NGINX_PROXY : '/xxxxxxxxxxxxx']: {
  40. // target: env.VITE_SERVER_ORIGIN,
  41. // ws: true,
  42. // changeOrigin: true,
  43. // // rewrite: (path) => path.replace(/^\/api/, ''),
  44. // },
  45. // },
  46. },
  47. build: {
  48. outDir: 'sagoo-iot',
  49. sourcemap: false,
  50. cssCodeSplit: false,
  51. chunkSizeWarningLimit: 1500,
  52. rollupOptions: {
  53. output: {
  54. entryFileNames: `assets/[name].${new Date().getTime()}.js`,
  55. chunkFileNames: `assets/[name].${new Date().getTime()}.js`,
  56. assetFileNames: `assets/[name].${new Date().getTime()}.[ext]`,
  57. compact: true,
  58. manualChunks: {
  59. vue: ['vue', 'vue-router', 'vuex'],
  60. echarts: ['echarts'],
  61. },
  62. },
  63. },
  64. },
  65. css: {
  66. postcss: {
  67. plugins: [
  68. {
  69. postcssPlugin: 'internal:charset-removal',
  70. AtRule: {
  71. charset: (atRule) => {
  72. if (atRule.name === 'charset') {
  73. atRule.remove();
  74. }
  75. },
  76. },
  77. },
  78. ],
  79. },
  80. },
  81. define: {
  82. __VUE_I18N_LEGACY_API__: JSON.stringify(false),
  83. __VUE_I18N_FULL_INSTALL__: JSON.stringify(false),
  84. __INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false),
  85. },
  86. };
  87. });
  88. export default viteConfig;