vite.config.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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: '/',
  13. // 路径重定向
  14. resolve: {
  15. alias: [
  16. {
  17. find: /\/#\//,
  18. replacement: pathResolve('types')
  19. },
  20. {
  21. find: '@',
  22. replacement: pathResolve('src')
  23. }
  24. ],
  25. dedupe: ['vue']
  26. },
  27. // 全局 css 注册
  28. css: {
  29. preprocessorOptions: {
  30. scss: {
  31. javascriptEnabled: true,
  32. additionalData: `@import "src/styles/common/style.scss";`
  33. }
  34. }
  35. },
  36. plugins: [
  37. vue(),
  38. monacoEditorPlugin({
  39. languageWorkers: ['editorWorkerService', 'typescript', 'json', 'html']
  40. }),
  41. viteMockServe({
  42. mockPath: '/src/api/mock',
  43. // 开发打包开关
  44. localEnabled: true,
  45. // 生产打包开关
  46. prodEnabled: true,
  47. // 打开后,可以读取 ts 文件模块。 请注意,打开后将无法监视.js 文件
  48. supportTs: true,
  49. // 监视文件更改
  50. watchFiles: true
  51. }),
  52. // 压缩
  53. viteCompression({
  54. verbose: true,
  55. disable: false,
  56. threshold: 10240,
  57. algorithm: 'gzip',
  58. ext: '.gz'
  59. })
  60. ],
  61. build: {
  62. target: 'es2015',
  63. outDir: OUTPUT_DIR,
  64. terserOptions: terserOptions,
  65. rollupOptions: rollupOptions,
  66. brotliSize: brotliSize,
  67. chunkSizeWarningLimit: chunkSizeWarningLimit
  68. }
  69. })