vite.config.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import { resolve } from 'path'
  4. import { OUTPUT_DIR, brotliSize, chunkSizeWarningLimit, terserOptions, rollupOptions } from './build/constant'
  5. import viteCompression from 'vite-plugin-compression'
  6. import { viteMockServe } from 'vite-plugin-mock'
  7. import monacoEditorPlugin from 'vite-plugin-monaco-editor'
  8. function pathResolve(dir: string) {
  9. return resolve(process.cwd(), '.', dir)
  10. }
  11. export default defineConfig({
  12. base: '/goview/',
  13. // 路径重定向
  14. resolve: {
  15. alias: [
  16. {
  17. find: /\/#\//,
  18. replacement: pathResolve('types')
  19. },
  20. {
  21. find: '@',
  22. replacement: pathResolve('src')
  23. },
  24. {
  25. find: 'vue-i18n',
  26. replacement: 'vue-i18n/dist/vue-i18n.cjs.js' //解决i8n警告
  27. }
  28. ],
  29. dedupe: ['vue']
  30. },
  31. // 全局 css 注册
  32. css: {
  33. preprocessorOptions: {
  34. scss: {
  35. javascriptEnabled: true,
  36. additionalData: `@import "src/styles/common/style.scss";`
  37. }
  38. }
  39. },
  40. plugins: [
  41. vue({
  42. template: {
  43. compilerOptions: {
  44. // 排除 iconify 图标影子组件编译报错
  45. isCustomElement: tag => tag.startsWith('iconify-icon')
  46. }
  47. }
  48. }),
  49. monacoEditorPlugin({
  50. languageWorkers: ['editorWorkerService', 'typescript', 'json', 'html']
  51. }),
  52. viteMockServe({
  53. mockPath: '/src/api/mock',
  54. // 开发打包开关
  55. localEnabled: true,
  56. // 生产打包开关
  57. prodEnabled: true,
  58. // 打开后,可以读取 ts 文件模块。 请注意,打开后将无法监视.js 文件
  59. supportTs: true,
  60. // 监视文件更改
  61. watchFiles: true
  62. }),
  63. // 压缩
  64. viteCompression({
  65. verbose: true,
  66. disable: false,
  67. threshold: 10240,
  68. algorithm: 'gzip',
  69. ext: '.gz'
  70. })
  71. ],
  72. build: {
  73. target: 'es2020',
  74. outDir: OUTPUT_DIR,
  75. // minify: 'terser', // 如果需要用terser混淆,可打开这两行
  76. // terserOptions: terserOptions,
  77. rollupOptions: rollupOptions,
  78. reportCompressedSize: brotliSize,
  79. chunkSizeWarningLimit: chunkSizeWarningLimit
  80. }
  81. })