vite.config.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * vite配置
  3. *
  4. * @Author: 1024创新实验室-主任:卓大
  5. * @Date: 2022-05-02 23:44:56
  6. * @Wechat: zhuda1024
  7. * @Email: lab1024@163.com
  8. * @Copyright 1024创新实验室 ( https://1024lab.net ),Since 2012
  9. */
  10. import { resolve } from 'path';
  11. import vue from '@vitejs/plugin-vue';
  12. const pathResolve = (dir) => {
  13. return resolve(__dirname, '.', dir);
  14. };
  15. export default {
  16. base: process.env.NODE_ENV === 'production' ? '/' : '/',
  17. root: process.cwd(),
  18. resolve: {
  19. alias: [
  20. // 国际化替换
  21. {
  22. find: 'vue-i18n',
  23. replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
  24. },
  25. // 绝对路径重命名:/@/xxxx => src/xxxx
  26. {
  27. find: /\/@\//,
  28. replacement: pathResolve('src') + '/',
  29. },
  30. {
  31. find: /^~/,
  32. replacement: '',
  33. },
  34. ],
  35. },
  36. // 服务端渲染
  37. server: {
  38. host: '0.0.0.0',
  39. port: 8081,
  40. },
  41. plugins: [vue()],
  42. optimizeDeps: {
  43. include: ['ant-design-vue/es/locale/zh_CN', 'dayjs/locale/zh-cn', 'ant-design-vue/es/locale/en_US'],
  44. exclude: ['vue-demi'],
  45. },
  46. build: {
  47. // 清除console和debugger
  48. terserOptions: {
  49. compress: {
  50. drop_console: true,
  51. drop_debugger: true,
  52. },
  53. },
  54. rollupOptions: {
  55. output: {
  56. //配置这个是让不同类型文件放在不同文件夹,不会显得太乱
  57. chunkFileNames: 'js/[name]-[hash].js',
  58. entryFileNames: 'js/[name]-[hash].js',
  59. assetFileNames: '[ext]/[name]-[hash].[ext]',
  60. manualChunks(id) {
  61. //静态资源分拆打包
  62. if (id.includes('node_modules')) {
  63. return id.toString().split('node_modules/')[1].split('/')[0].toString();
  64. }
  65. },
  66. },
  67. },
  68. target: 'modules',
  69. outDir: 'dist', // 指定输出路径
  70. assetsDir: 'assets', // 指定生成静态文件目录
  71. assetsInlineLimit: '4096', // 小于此阈值的导入或引用资源将内联为 base64 编码
  72. chunkSizeWarningLimit: 500, // chunk 大小警告的限制
  73. minify: 'terser', // 混淆器,terser构建后文件体积更小
  74. emptyOutDir: true, //打包前先清空原有打包文件
  75. },
  76. css: {
  77. preprocessorOptions: {
  78. less: {
  79. modifyVars: {
  80. hack: `true; @import (reference) "${resolve('src/theme/index.less')}";`,
  81. },
  82. javascriptEnabled: true,
  83. },
  84. },
  85. },
  86. define: {
  87. __INTLIFY_PROD_DEVTOOLS__: false,
  88. 'process.env': process.env,
  89. },
  90. };