vite.config.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. // import {vitePluginSvg} from "@webxrd/vite-plugin-svg"
  4. import { resolve } from 'path'
  5. // import commonjs from 'vite-plugin-commonjs';
  6. // import commonjs from '@rollup/plugin-commonjs';
  7. // https://vitejs.dev/config/
  8. const pathResolve = (dir) => {
  9. return resolve(__dirname, ".", dir)
  10. }
  11. const alias = {
  12. '@': pathResolve("src"),
  13. }
  14. /**
  15. * @description-en vite document address
  16. * @description-cn vite官网
  17. * https://vitejs.cn/config/ */
  18. export default ({ command }) => {
  19. const prodMock = true;
  20. return {
  21. base: './',
  22. resolve: {
  23. alias
  24. },
  25. server: {
  26. port: 3001,
  27. host: '0.0.0.0',
  28. open: true,
  29. proxy: { // 代理配置
  30. '/pro-api':{
  31. target: 'http://47.121.202.117:81',
  32. changeOrigin: true,
  33. rewrite: (path) => {
  34. return path.replace('/pro-api', '/')
  35. }
  36. }
  37. },
  38. },
  39. // build: {
  40. // rollupOptions: {
  41. // output: {
  42. // manualChunks: {
  43. // 'echarts': ['echarts']
  44. // }
  45. // }
  46. // }
  47. // },
  48. plugins: [
  49. // commonjs(),
  50. vue(),
  51. // viteMockServe({
  52. // mockPath: 'mock',
  53. // localEnabled: command === 'serve',
  54. // prodEnabled: command !== 'serve' && prodMock,
  55. // watchFiles: true,
  56. // injectCode: `
  57. // import { setupProdMockServer } from '../mockProdServer';
  58. // setupProdMockServer();
  59. // `,
  60. // logger: true,
  61. // }),
  62. // vitePluginSvg({
  63. // // 必要的。必须是绝对路径组成的数组。
  64. // iconDirs: [
  65. // resolve(__dirname, 'src/assets/svg'),
  66. // ],
  67. // // 必要的。入口script
  68. // main: resolve(__dirname, 'src/main.js'),
  69. // symbolIdFormat: 'icon-[name]'
  70. // }),
  71. ],
  72. css: {
  73. postcss: {
  74. plugins: [
  75. {
  76. postcssPlugin: 'internal:charset-removal',
  77. AtRule: {
  78. charset: (atRule) => {
  79. if (atRule.name === 'charset') {
  80. atRule.remove();
  81. }
  82. }
  83. }
  84. }
  85. ],
  86. },
  87. preprocessorOptions: {
  88. scss: {
  89. api: 'modern-compiler', // 修改api调用方式
  90. },
  91. },
  92. }
  93. };
  94. }