【Vue3】Vite打包发布错误若干问题解决方案,新手遇到的问题都在这里。

一、打包命令

npm run build

二、错误1:出现打包报错:块的大小超过限制,Some chunks are larger than 500kb after minification

在vite.config.js 中加入下面的代码

build: {
    chunkSizeWarningLimit: 1000,
    rollupOptions: {
      output: {
        // 分包
        manualChunks(id) {
          if (id.includes("node_modules")) {
            return id
              .toString()
              .split("node_modules/")[1]
              .split("/")[0]
              .toString();
          }
        },
      },
    },
  }

vite.config.js 完整代码

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],

  server: {
    host:"0.0.0.0",
    open:false,
    port:4000,
    https:false,
    hotOnly:false,
    proxy: {
      '/suoker': {
        target: 'http://www.sr.com',
        rewrite: (path) => path.replace(/^\/sr/, ''),
        changeOrigin: true,             //是否跨域
      },
      '/asp': {
        target: 'http://localhost:1100/api/',
        rewrite: (path) => path.replace(/^\/asp/, ''),
        changeOrigin: true,             //是否跨域
      },

    }
  },
  build: {
    chunkSizeWarningLimit: 1000,
    rollupOptions: {
      output: {
        // 分包
        manualChunks(id) {
          if (id.includes("node_modules")) {
            return id
              .toString()
              .split("node_modules/")[1]
              .split("/")[0]
              .toString();
          }
        },
      },
    },
  }

})

猜你喜欢

转载自blog.csdn.net/dxnn520/article/details/129154599
今日推荐