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中文文檔


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM