webpack_报错:'WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB). This can impact web performance.'

报错详情

WARNING in asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
This can impact web performance.
Assets:
images/4d6bc2ae9cb14bbb4bd9de93ba4437a7.png (3.67 MiB)

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/

错误原因

webpack在打包时,如果资源压缩超过250kb时,会报错提示:
You can limit the size of your bundles by using import() or require.ensure to lazy load some parts of your application

解决方法

webpack.config.js文件中添加如下代码:
加大文件允许体积,提升报错门栏。

const config = {

    // some code

    performance: {
        hints: "warning", // 枚举
        maxAssetSize: 300000, // 整数类型(以字节为单位)
        maxEntrypointSize: 500000, // 整数类型(以字节为单位)
        assetFilter: function (assetFilename) {
            // 提供资源文件名的断言函数
            // 只给出js与css文件的性能提示
            return assetFilename.endsWith('.css') || assetFilename.endsWith('.js');
        }
    }
};

参考博客

js压缩合并资源,webpack报WARNING in asset size limit
webpack打包报错
webpack中文文档

posted @ 2021-03-08 11:53  Syinho  阅读(4187)  评论(0编辑  收藏  举报