vite.config.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * vite配置
  3. *
  4. * @Author: BoundLink
  5. * @Date: 2022-05-02 23:44:56
  6. */
  7. import { resolve } from 'path';
  8. import vue from '@vitejs/plugin-vue';
  9. import vueJsx from '@vitejs/plugin-vue-jsx';
  10. import customVariables from '/@/theme/custom-variables.js';
  11. const pathResolve = (dir) => {
  12. return resolve(__dirname, '.', dir);
  13. };
  14. export default {
  15. base: process.env.NODE_ENV === 'production' ? '/' : '/',
  16. root: process.cwd(),
  17. resolve: {
  18. alias: [
  19. // 国际化替换
  20. {
  21. find: 'vue-i18n',
  22. replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
  23. },
  24. // 绝对路径重命名:/@/xxxx => src/xxxx
  25. {
  26. find: /\/@\//,
  27. replacement: pathResolve('src') + '/',
  28. },
  29. {
  30. find: /^~/,
  31. replacement: '',
  32. },
  33. ],
  34. },
  35. // 服务端渲染
  36. server: {
  37. host: '0.0.0.0',
  38. port: 8081,
  39. proxy: {
  40. '/api': {
  41. target: 'http://localhost:9000',
  42. // target: 'http://192.168.21.99:2024',
  43. //target: 'http://10.10.4.162:2024',
  44. changeOrigin: true,
  45. ws: true,
  46. rewrite: (path) => path.replace(new RegExp(`^/api`), ''),
  47. // only https
  48. // secure: false
  49. },
  50. },
  51. open: true, // 项目启动后,自动打开
  52. },
  53. plugins: [vue(), vueJsx({})],
  54. optimizeDeps: {
  55. include: ['ant-design-vue/es/locale/zh_CN', 'dayjs/locale/zh-cn', 'ant-design-vue/es/locale/en_US'],
  56. exclude: ['vue-demi'],
  57. },
  58. build: {
  59. // 清除console和debugger
  60. terserOptions: {
  61. compress: {
  62. drop_console: true,
  63. drop_debugger: true,
  64. },
  65. },
  66. rollupOptions: {
  67. output: {
  68. //配置这个是让不同类型文件放在不同文件夹,不会显得太乱
  69. chunkFileNames: 'js/[name]-[hash].js',
  70. entryFileNames: 'js/[name]-[hash].js',
  71. assetFileNames: '[ext]/[name]-[hash].[ext]',
  72. manualChunks(id) {
  73. //静态资源分拆打包
  74. if (id.includes('node_modules')) {
  75. return id.toString().split('node_modules/')[1].split('/')[0].toString();
  76. }
  77. },
  78. },
  79. // external: [
  80. // '@antv/x6',
  81. // '@antv/x6-plugin-stencil',
  82. // '@antv/x6-plugin-keyboard',
  83. // '@antv/x6-plugin-scroller',
  84. // '@antv/x6-plugin-selection',
  85. // '@antv/x6-plugin-history',
  86. // '@antv/x6-plugin-clipboard',
  87. // '@antv/x6-plugin-minimap',
  88. // '@antv/x6-plugin-snapline',
  89. // '@antv/x6-plugin-export'
  90. // ],
  91. },
  92. target: 'modules',
  93. outDir: 'dist', // 指定输出路径
  94. assetsDir: 'assets', // 指定生成静态文件目录
  95. assetsInlineLimit: '4096', // 小于此阈值的导入或引用资源将内联为 base64 编码
  96. chunkSizeWarningLimit: 500, // chunk 大小警告的限制
  97. minify: 'terser', // 混淆器,terser构建后文件体积更小
  98. emptyOutDir: true, //打包前先清空原有打包文件
  99. },
  100. css: {
  101. preprocessorOptions: {
  102. less: {
  103. modifyVars: customVariables,
  104. javascriptEnabled: true,
  105. },
  106. },
  107. },
  108. define: {
  109. __INTLIFY_PROD_DEVTOOLS__: false,
  110. 'process.env': process.env,
  111. },
  112. };