vite.config.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * @Author: luoxi
  3. * @Date: 2022-01-25 09:51:12
  4. * @LastEditors: Please set LastEditors
  5. * @LastEditTime: 2023-02-21 22:57:42
  6. * @FilePath: \vue-admin-box\vite.config.ts
  7. * @Description:
  8. */
  9. import vue from '@vitejs/plugin-vue'
  10. import { viteMockServe } from 'vite-plugin-mock'
  11. // import {vitePluginSvg} from "@webxrd/vite-plugin-svg"
  12. import { resolve } from 'path'
  13. const pathResolve = (dir) => {
  14. return resolve(__dirname, ".", dir)
  15. }
  16. const alias = {
  17. '@': pathResolve("src")
  18. }
  19. /**
  20. * @description-en vite document address
  21. * @description-cn vite官网
  22. * https://vitejs.cn/config/ */
  23. export default ({ command }) => {
  24. const prodMock = true;
  25. return {
  26. base: './',
  27. resolve: {
  28. alias
  29. },
  30. server: {
  31. port: 3001,
  32. host: '0.0.0.0',
  33. open: true,
  34. proxy: { // 代理配置
  35. '/dev': 'https://www.fastmock.site/mock/48cab8545e64d93ff9ba66a87ad04f6b/'
  36. },
  37. },
  38. build: {
  39. rollupOptions: {
  40. output: {
  41. manualChunks: {
  42. 'echarts': ['echarts']
  43. }
  44. }
  45. }
  46. },
  47. plugins: [
  48. vue(),
  49. viteMockServe({
  50. mockPath: 'mock',
  51. localEnabled: command === 'serve',
  52. prodEnabled: command !== 'serve' && prodMock,
  53. watchFiles: true,
  54. injectCode: `
  55. import { setupProdMockServer } from '../mockProdServer';
  56. setupProdMockServer();
  57. `,
  58. logger: true,
  59. }),
  60. /* vitePluginSvg({
  61. // 必要的。必须是绝对路径组成的数组。
  62. iconDirs: [
  63. resolve(__dirname, 'src/assets/svg'),
  64. ],
  65. // 必要的。入口script
  66. main: resolve(__dirname, 'src/main.js'),
  67. symbolIdFormat: 'icon-[name]'
  68. }), */
  69. ],
  70. css: {
  71. postcss: {
  72. plugins: [
  73. {
  74. postcssPlugin: 'internal:charset-removal',
  75. AtRule: {
  76. charset: (atRule) => {
  77. if (atRule.name === 'charset') {
  78. atRule.remove();
  79. }
  80. }
  81. }
  82. }
  83. ],
  84. },
  85. }
  86. };
  87. }