vite.config.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { defineConfig, loadEnv } from "vite";
  2. import uni from "@dcloudio/vite-plugin-uni";
  3. import path from "path";
  4. // https://vitejs.dev/config/
  5. export default defineConfig(({ mode }) => {
  6. return {
  7. base: "./", //等同於 assetsPublicPath :'./'
  8. plugins: [uni(),
  9. { // 自定义插件禁用vite:vue插件的devToolsEnabled,强制编译 vue 模板时 inline 为 true
  10. name: 'fix-vite-plugin-vue',
  11. configResolved(config) {
  12. const plugin = config.plugins.find((p) => p.name === 'vite:vue')
  13. if (plugin && plugin.api && plugin.api.options) {
  14. plugin.api.options.devToolsEnabled = false
  15. }
  16. },
  17. },
  18. ],
  19. resolve: {
  20. alias: {
  21. '@': path.resolve(__dirname, './src/'),
  22. }
  23. },
  24. css: {
  25. preprocessorOptions: {
  26. scss: {
  27. preprocessorOptions: `@import "@/static/css/common.scss";`
  28. },
  29. }
  30. },
  31. server: {
  32. host: '0.0.0.0',
  33. port: 8081,
  34. https: false,
  35. proxy: {
  36. '/api': {
  37. target: loadEnv(mode, process.cwd()).VITE_APP_URL_H5,
  38. changeOrigin: true,
  39. rewrite: (path) => path.replace(/^\/api/, '')
  40. }
  41. }
  42. }
  43. }
  44. });