亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

webpack中的optimization怎么配置

發布時間:2023-02-23 14:35:03 來源:億速云 閱讀:143 作者:iii 欄目:開發技術

本篇內容主要講解“webpack中的optimization怎么配置”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“webpack中的optimization怎么配置”吧!

webpack配置optimization

  • minimizer

  • runtimeChunk

  • noEmitOnErrors

  • splitChunks

主要就是根據不同的策略來分割打包出來的bundle。

本人項目中splitChunks配置如下:

module.exports = {
                    chainWebpack(config) {
                        config.when(process.env.NODE_ENV != 'development',
                            config => {
                                config.optimization.splitChunks({
                                    chunks: 'all',
                                    cacheGroups: {
                                        // 第三方組件
                                        libs: {
                                            指定chunks名稱
                                            name: 'chunk-libs',
                                            //符合組的要求就給構建venders
                                            test: /[\\/]node_modules[\\/]/,
                                            //priority:優先級:數字越大優先級越高,因為默認值為0,所以自定義的一般是負數形式,決定cacheGroups中相同條件下每個組執行的優先順序。
                                            priority: 10,
                                            // 僅限于最初依賴的第三方
                                            chunks: 'initial'
                                        },
                                        elementUI: {
                                            // 將elementUI拆分為單個包
                                            name: 'chunk-elementUI',
                                            // 重量需要大于libs和app,否則將打包到libs或app中
                                            priority: 20,
                                            // 為了適應cnpm
                                            test: /[\\/]node_modules[\\/]_?element-ui(.*)/
                                        },
                                        //公共組件
                                        commons: {
                                            name: 'chunk-commons',
                                            // can customize your rules
                                            test: resolve('src/components'),
                                            minChunks: 3,
                                            priority: 30,
                                            //這個的作用是當前的chunk如果包含了從main里面分離出來的模塊,則重用這個模塊,這樣的問題是會影響chunk的名稱。
                                            reuseExistingChunk: true,
                                            //最大初始化加載次數,一個入口文件可以并行加載的最大文件數量,默認3
                                            maxInitialRequests: 3,
                                            //表示在分離前的最小模塊大小,默認為0,最小為30000
                                            minSize: 0
                                        },
                                        echarts: { // split echarts libs
                                            name: 'chunk-echarts',
                                            test: /[\\/]node_modules[\\/]_?echarts(.*)/,
                                            priority: 40,
                                            chunks: 'async',
                                            reuseExistingChunk: true
                                        },
                                        monaco: { // split monaco libs
                                            name: 'chunk-monaco',
                                            test: /[\\/]node_modules[\\/]_?monaco(.*)/,
                                            priority: 40,
                                            chunks: 'async',
                                            reuseExistingChunk: true
                                        },
                                        'project-components': { // split project libs
                                            name: 'chunk-project-components',
                                            test: resolve('src/views/project'),
                                            priority: 50,
                                            chunks: 'async',
                                            reuseExistingChunk: true
                                        },
                                        'teachers-components': { // split teacher libs
                                            name: 'chunk-teachers-components',
                                            test: resolve('src/views/teachers'),
                                            priority: 60,
                                            chunks: 'async',
                                            reuseExistingChunk: true
                                        },
                                        'utils': { // split utils libs
                                            name: 'chunk-utils',
                                            test: resolve('src/utils'),
                                            priority: 70,
                                            chunks: 'async',
                                            reuseExistingChunk: true
                                        },
                                    }
                                })
                            })

                    }
                }

分析工具:webpack-bundle-analyzer

  • 安裝

npm i --save-dev webpack-bundle-analyzer

  • 配置

 config.plugin('BundleAnalyzerPlugin').use(BundleAnalyzerPlugin).tap(() => [
      {
        rel: 'BundleAnalyzerPlugin',
        analyzerMode: 'server', // 'server': 啟動端口服務;'static': 生成 report.html;'disabled': 配合 generateStatsFile 使用;
        generateStatsFile: false, // 是否生成stats.json文件
        analyzerHost: '127.0.0.1',
        analyzerPort: '8667',
        reportFilename: 'report.html',
        defaultSizes: 'parsed',
        openAnalyzer: false,
        statsFilename: 'stats.json',
        statsOptions: null,
        excludeAssets: null
      }

運行

npm run build 或者 npm run dev

訪問

http://127.0.0.1:8877

擴展:webpack中module package bundle chunk詳細講解

  • module 模塊 寫一個commonjs 或者amd規范的包就叫module

  • package 是所有module構成的,它是一個整體的概念,整個項目就是一個package,它可能是commonjs或者amd規范的包

  • bundle是webpack打包的結果 所有的module都打包成一個文件 (module集合)

  • chunk bundle是入口bundle,異步加載一個模塊,是需要運行時去處理的,獲取的過程就是一個代碼塊即chunk;由bundle獲取的包為chunk

到此,相信大家對“webpack中的optimization怎么配置”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

瑞昌市| 合水县| 页游| 阳朔县| 洮南市| 安新县| 黎川县| 六枝特区| 廊坊市| 龙井市| 临颍县| 防城港市| 雷山县| 延川县| 师宗县| 和平县| 修水县| 洮南市| 河津市| 太湖县| 彰化县| 锦屏县| 江西省| 灵寿县| 那坡县| 武乡县| 绵阳市| 长宁区| 古蔺县| 洛隆县| 福海县| 七台河市| 许昌市| 威远县| 荔浦县| 晋中市| 昆山市| 双鸭山市| 达拉特旗| 安远县| 南宫市|