vite.config.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { defineConfig, loadEnv } from 'vite'
  2. import { resolve } from 'path'
  3. import libConfig from './lib.config';
  4. import createVitePlugins from './vite/plugins'
  5. // https://vitejs.dev/config/
  6. export default ({ mode, command }) => {
  7. const env = loadEnv(mode, process.cwd())
  8. const { VITE_APP_BASE, VITE_APP_ENV, VITE_PROXY } = env
  9. return defineConfig({
  10. ...(() => {
  11. if (VITE_APP_ENV == 'lib') {
  12. return libConfig
  13. }
  14. return {}
  15. })(),
  16. base: VITE_APP_BASE,
  17. resolve: {
  18. alias: {
  19. 'vue': 'vue/dist/vue.esm-bundler.js',
  20. '~': resolve(__dirname, './'),
  21. "@": resolve(__dirname, "./src"),
  22. "components": resolve(__dirname, "./src/components"),
  23. "styles": resolve(__dirname, "./src/styles"),
  24. "utils": resolve(__dirname, "./src/utils"),
  25. }
  26. },
  27. plugins: createVitePlugins(env, command === 'build'),
  28. define: {
  29. 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
  30. },
  31. server: {
  32. https: false,
  33. host: true,
  34. port: 8100,
  35. proxy: {
  36. "/dev": {
  37. target: VITE_PROXY,//代理接口
  38. changeOrigin: true,
  39. rewrite: (path) => path.replace(/^\/dev/, ""),
  40. },
  41. },
  42. open: true, //vite项目启动时自动打开浏览器
  43. },
  44. })
  45. }