WARNING in asset size limit: 静态资源过大

本文指导如何解决Nuxt项目npm run build时出现的过大资源和入口文件警告,提供配置webpack性能优化的解决方案,包括maxEntrypointSize和maxAssetSize设置,以及使用assetFilter进行JS文件特定提示。

nuxt项目 npm run build 时,有时会出现如下错误:

WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
This can impact web performance.
Assets:
…/dist/bundle/index.js (329 KiB)
WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.
Entrypoints:
main (329 KiB)
…/dist/bundle/index.js
WARNING in webpack performance recommendations:
You can limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application.
For more info visit https://webpack.js.org/guides/code-splitting/

错误原因,资源(asset)和入口起点超过指定文件限制,需要在 nuxt.config.js 文件内做如下配置:

configureWebpack: {
    //关闭 webpack 的性能提示
    performance: {
      hints:'warning',
      //入口起点的最大体积
      maxEntrypointSize: 50000000,
      //生成文件的最大体积
      maxAssetSize: 30000000,
      //只给出 js 文件的性能提示
      assetFilter: function(assetFilename) {
        return assetFilename.endsWith('.js');
      }
    }
  }

详细配置可见 webpack 官网:https://www.webpackjs.com/configuration/performance/

前端编译失败 Entrypoint app [big] = static/js/runtime.c7a73902.js static/css/chunk-elementUI.68b6389b.css static/js/chunk-elementUI.709889cd.js static/css/chunk-libs.b7bf4b0e.css static/js/chunk-libs.760b932b.js static/css/app.5bc5aac9.css static/js/app.0e86cf05.js WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB). This can impact web performance. Assets: static/img/login_in.72b900b.png (395 KiB) static/img/vote_bg_grey2.53b929c.jpg (827 KiB) static/img/first_bg.324459b.jpg (331 KiB) static/img/bg3-xh.6802321.png (727 KiB) static/img/login_bg.d0a43a9.jpg (302 KiB) static/img/bgn1-xh.02e1a23.png (967 KiB) static/js/chunk-38c6.efb7a871.js (296 KiB) static/js/chunk-4c77.54a05faf.js (850 KiB) static/js/chunk-ebf7.657f248d.js (1.06 MiB) static/js/chunk-elementUI.709889cd.js (750 KiB) static/js/chunk-libs.760b932b.js (307 KiB) static/UEditor/third-party/highcharts/highcharts.src.js (451 KiB) static/UEditor/third-party/snapscreen/UEditorSnapscreen.exe (508 KiB) static/UEditor/ueditor.all.js (1.09 MiB) static/UEditor/ueditor.all.min.js (373 KiB) WARNING in entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance. Entrypoints: app (1.5 MiB) static/js/runtime.c7a73902.js static/css/chunk-elementUI.68b6389b.css static/js/chunk-elementUI.709889cd.js static/css/chunk-libs.b7bf4b0e.css static/js/chunk-libs.760b932b.js static/css/app.5bc5aac9.css static/js/app.0e86cf05.js 是什么异常导致的
07-03
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值