vite.config.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { defineConfig } from 'vite';
  2. import { resolve } from 'path';
  3. import createVitePlugins from './build/plugins';
  4. import { __APP_INFO__ } from './build/utils';
  5. export default defineConfig(() => {
  6. return {
  7. resolve: {
  8. alias: {
  9. '@': resolve(__dirname, 'src'),
  10. 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
  11. }
  12. },
  13. define: {
  14. __APP_INFO__: JSON.stringify(__APP_INFO__),
  15. 'process.env': {
  16. APP_ENV: process.env.APP_ENV
  17. }
  18. },
  19. plugins: createVitePlugins(),
  20. css: {
  21. postcss: {
  22. plugins: [
  23. {
  24. postcssPlugin: 'internal:charset-removal',
  25. AtRule: {
  26. charset: atRule => {
  27. if (atRule.name === 'charset') {
  28. atRule.remove();
  29. }
  30. }
  31. }
  32. }
  33. ]
  34. },
  35. preprocessorOptions: {
  36. scss: {
  37. additionalData: `@import "@/styles/var.scss";`
  38. }
  39. }
  40. },
  41. server: {
  42. host: '0.0.0.0'
  43. },
  44. build: {
  45. outDir: `dist`,
  46. cssCodeSplit: false,
  47. sourcemap: false,
  48. emptyOutDir: true,
  49. chunkSizeWarningLimit: 1500,
  50. rollupOptions: {
  51. output: {
  52. //静态资源分类打包
  53. chunkFileNames: 'js/[name]-[hash].js',
  54. entryFileNames: 'js/[name]-[hash].js',
  55. assetFileNames: '[ext]/[name]-[hash].[ext]',
  56. manualChunks: {
  57. // 分包配置,配置完成自动按需加载
  58. vue: ['vue', 'vue-router', 'pinia', 'vue-i18n', 'element-plus'],
  59. echarts: ['echarts']
  60. }
  61. }
  62. }
  63. }
  64. };
  65. });