Webpack learning (3)

1. Detailed Explanation of Tree Shaking Concept

Second, Webpack and Code Splitting

module.exports = {
	plugins: [new HtmlWebpackPlugin(
		template: 'src/index.html' 
	),new CleanWebpackPlugin(['dist'],{
        root: path.resolve(__dirname, '../')  //打包之前删除webpack.config.js文件的上一层文件的dist文件中的内容
    })],
    optimization : {
        splitChunks: {
             chunks: 'all' //打包的时候自动实现业务逻辑和库的分割
        }
    },
    output: {
    filename: '[name].js', 
    path: path.resolve(__dirname, '../dist')  //打包到webpack.config.js文件的上一层文件中的dist文件中 
  }
}

Code segmentation has nothing to do with webpack. There are two ways to implement code segmentation in webpack:

1. Synchronization code: only need to do optimization in webpack.common.js

2. Asynchronous code (import): Asynchronous code, without any configuration, will automatically perform code segmentation and place it in a new file

3. Detailed explanation of SplitChunksPlugin configuration parameters

Published 35 original articles · won praise 1 · views 6718

Guess you like

Origin blog.csdn.net/qq_36162529/article/details/91553942