vite.config.mts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import type { ConfigEnv, UserConfigExport } from "vite";
  2. import path from "path";
  3. import autoprefixer from 'autoprefixer';
  4. import AutoImport from 'unplugin-auto-import/vite';
  5. import tailwindcss from 'tailwindcss';
  6. import { include, exclude } from './build/optimize';
  7. import { createVitePlugins } from './build/plugins';
  8. export default ({ command, mode }: ConfigEnv): UserConfigExport => {
  9. return {
  10. base: "./", // publicPath
  11. server: {
  12. host: '0.0.0.0',
  13. port: 9191,
  14. proxy: {
  15. '/apis10': {
  16. target: 'http://192.168.1.44:9991',
  17. changeOrigin: true,
  18. rewrite: (path) => path.replace(new RegExp('^/apis10'), ''),
  19. },
  20. '/static': {
  21. target: 'http://192.168.1.44:11994',
  22. changeOrigin: true,
  23. rewrite: (path) => path.replace(new RegExp('^/static'), ''),
  24. }
  25. },
  26. },
  27. plugins: createVitePlugins(mode),
  28. optimizeDeps: { include, exclude },
  29. css: {
  30. postcss: {
  31. plugins: [
  32. tailwindcss,
  33. autoprefixer({
  34. // 自动添加前缀
  35. overrideBrowserslist: [
  36. 'Android 4.1',
  37. 'iOS 7.1',
  38. 'Chrome > 31',
  39. 'ff > 31',
  40. 'ie >= 8',
  41. '> 1%',
  42. 'last 2 versions',
  43. 'not dead',
  44. 'not ie 11',
  45. //'last 2 versions', // 所有主流浏览器最近2个版本
  46. ],
  47. grid: true,
  48. }),
  49. ]
  50. },
  51. preprocessorOptions: {
  52. scss: {
  53. additionalData: `@import "src/assets/style/variable.scss";@import "src/assets/style/mixin.scss";`,
  54. },
  55. less: {
  56. modifyVars: {
  57. "primary-color": "#d14424",
  58. "text-color": "#41464b",
  59. "font-size-base": "13px",
  60. "border-radius-base": "2px",
  61. },
  62. javascriptEnabled: true,
  63. },
  64. },
  65. },
  66. resolve: {
  67. alias: {
  68. "@": path.resolve(__dirname, "src"),
  69. },
  70. extensions: [".js", ".ts", ".jsx", ".tsx", ".vue", ".json"],
  71. },
  72. build: {
  73. target: "es2015",
  74. outDir: path.resolve(__dirname, "dist"),
  75. minify: "terser",
  76. terserOptions: {
  77. compress: {
  78. //生产环境时移除console
  79. drop_console: true,
  80. drop_debugger: true,
  81. },
  82. },
  83. // 关闭文件计算
  84. reportCompressedSize: false,
  85. // 关闭生成map文件
  86. sourcemap: false,
  87. rollupOptions: {
  88. output: {
  89. // chunkFileNames: 'js/[name]-[hash].js', // 引入文件名的名称
  90. // entryFileNames: 'js/[name]-[hash].js', // 包的入口文件名称
  91. // assetFileNames: '[ext]/[name]-[hash].[ext]', // 资源文件像 字体,图片等
  92. manualChunks: {
  93. vue: ['vue'],
  94. fabric: ['fabric'],
  95. 'lodash-es': ['lodash-es'],
  96. 'opentype.js': ['opentype.js'],
  97. 'clipper-lib': ['clipper-lib'],
  98. 'element-plus': ['element-plus'],
  99. },
  100. // manualChunks(id, any): string {
  101. // return id
  102. // }
  103. }
  104. }
  105. },
  106. };
  107. };