vite.config.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { fileURLToPath, URL } from 'node:url'
  2. import { defineConfig } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import vueJsx from '@vitejs/plugin-vue-jsx'
  5. import path from 'node:path'
  6. import viteConfitExtend from "./vite.config.extend";
  7. import Components from 'unplugin-vue-components/vite';
  8. import { VantResolver } from 'unplugin-vue-components/resolvers';
  9. // https://vitejs.dev/config/
  10. export default defineConfig({
  11. plugins: [
  12. vue(),
  13. vueJsx(),
  14. Components({
  15. resolvers: [VantResolver()],
  16. }),
  17. viteConfitExtend({
  18. indexPath: '../app/index/view/web/vr.html',
  19. }),
  20. ],
  21. resolve: {
  22. alias: {
  23. '@': fileURLToPath(new URL('./src', import.meta.url))
  24. }
  25. },
  26. build: {
  27. target: 'modules',
  28. // cssCodeSplit: true,//启用/禁用 CSS 代码拆分 如果设置为false,整个项目中的所有 CSS 将被提取到一个 CSS 文件中
  29. //指定输出路径
  30. outDir: "../../public/",
  31. //生成静态资源的存放路径
  32. assetsDir: "assets",
  33. //小于此阈值的导入或引用资源将内联为 base64 编码,以避免额外的 http 请求。设置为 0 可以完全禁用此项
  34. assetsInlineLimit: 40960,//40kb
  35. //构建后是否生成 source map 文件
  36. sourcemap: false,
  37. emptyOutDir: false,
  38. terserOptions: {
  39. output: {
  40. // 去掉注释内容
  41. comments: true,
  42. },
  43. },
  44. rollupOptions: {
  45. externals: {
  46. 'axios': 'axios'
  47. },
  48. output: {
  49. assetFileNames: `assets/[name].[hash].[ext]`,
  50. },
  51. },
  52. },
  53. server: {
  54. cors: true,
  55. proxy: {
  56. '/mobile': { // 匹配请求路径,localhost:3000/snow
  57. target: 'http://h5.zqxg.cc/mobile', // 代理的目标地址
  58. changeOrigin: true, // 开发模式,默认的origin是真实的 origin:localhost:3000 代理服务会把origin修改为目标地址
  59. // secure: true, // 是否https接口
  60. // ws: true, // 是否代理websockets
  61. // rewrite target目标地址 + '/abc',如果接口是这样的,那么不用重写
  62. rewrite: (path) => path.replace(/^\/mobile/, '') // 路径重写,本项目不需要重写
  63. // pathRewrite:{
  64. // "^vr":"/vr"
  65. // },
  66. }
  67. }
  68. }
  69. })