webpack 性能優化 在進行項目打包的時候,當使用babel-loader進行js兼容時,不需要將node_modules模塊下的所有js文件進行打包。


 

 module:{
        rules:[  //規則
            {   //.js文件或者.jsx文件處理
                test:/\.(js|jsx)/,  
                loader:"babel-loader",
                exclude:path.join(__dirname,"../node_modules")   //排除  node_modules中的內容
            },
            {  //圖片處理
                test:/\.(jpg|gif|png|svg)$/,  //正則,
                exclude:path.join(__dirname,"../node_modules"),   //排除  node_modules中的內容
                use:{
                    loader:"url-loader",
                    options:{
                        limit:2048,
                        name:"img/[name].[hash:8].[ext]"
                    }
                }
            },
            { //
                test:/\.(eot|svg|ttf|woff|woff2)$/,
                exclude:path.join(__dirname,"../node_modules"),  //排除  node_modules中的內容
                use:{
                    loader:"url-loader",
                    options:{
                        name:"iconfont/[name]:[hash:8].[ext]"
                    }
                }
            }
        ]
    }

  


免責聲明!

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



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