vite.config.mts 3.4 KB

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