webpack进阶【15】: 打包提取公共模块配置

2020-04-28  本文已影响0人  岚平果

webpack : 打包前提取公共模块配置、

注意:本进阶是在 webpack 进阶 【13】的基础上进行衍生。

一、为什么要进行公共模块配置?下面我们来举例说明

import $ from 'jquery'      // 用了 babel-loader 配置,现在可以用 import 引入
const div = $('div');

const app = document.querySelector('#app');
const h1 = document.createElement('h1');
h1.innerText = '这是一个 index.js文件';
app.appendChild(h1)
import $ from 'jquery'      // 用了 babel-loader 配置,现在可以用 import 引入
const div = $('div');

const app = document.querySelector('#app');
const h1 = document.createElement('h1');
h1.innerText = '这是一个 index.js文件';
app.appendChild(h1)
cnpm run build

二、webpack.base.js 配置

module.exports = {
    ...
    // 公共模块提取
    optimization: {
        splitChunks: {
            chunks: 'all'
        }
    }
}
cnpm run build
上一篇 下一篇

猜你喜欢

热点阅读