npm run build报错:Some chunks are larger than 500 KiB after minification

当你的Vue/Nuxt项目太大,那么使用npm run build生成项目的时候,就有可能会遇到以下报错:

 WARN                                                                                                                                                            15:32:15  
(!) Some chunks are larger than 500 KiB after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/guide/en/#outputmanualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.

这其实是vite的问题,一般调高chunk size就能解决这个问题。以下分别为vue 3和nuxt 3的解决方法。

vite.config.js :

//vite.config.js

export default defineConfig({
    ...,
    build: {
        chunkSizeWarningLimit: 1600
    }
})

nuxt.config.ts :

//nuxt.config.ts
export default defineNuxtConfig({
  vite: {
    build: { chunkSizeWarningLimit: 1600 },
  }
})

注:本文为本作者英文版文章的翻译,原文地址:Some chunks are larger than 500 KiB after minification
更多各领域的原创文章:弦圈- 找到属于你的圈子,让知识无荒原

你可能感兴趣的:(npm,前端,node.js,vue.js)