WEBPACK to extract public files from the specified portfolio

In the case of the use of CommonschunkPlugin, it is not difficult to get it directly to the use of Webpack4. In order to better understand the use of splitchunks, you must have a topic, practicing your hands, you can harvest from it (the following topics do not consider the actual application scenario):

Extract public in the designated entrance file Document

Communication of CommonschunkPlugin: entry: {index: ‘./ src / index.js’, index1:’ ./ SRC / INDEX1. JS ‘, INDEX2:’ ./ src / index2.js’}, plugins: [New CommonschunkPlugin ({name: “common1”, chunks: [‘INDEX’, ‘INDEX1’, ‘INDEX2’]})
The INDEX and INDEX1 and INDEX2 are all packaged entry files.

Optimization: {splitchunks: {chunks: “all”, minsize: 0, Cachegroups: {CommON: 3, priority: -1, name: ‘common’, chunks (chunk) {// Exclude `my-excluded-Chunk` Return [‘Index’, ‘Index1’, ‘Index2’]. include (chunk.name);}}}}}

  Under CacheGroups we define A COMMON. Through the Chunks function, specify the three entry files as: 'index', 'index1', 'index2', and we have to set the minchunks 3, indicating that the public file extracted in the three entrance files, and at least three Different entry files are referenced. So, extract public files from three entrance files.  
From two public documents, then extract public part

Let’s talk, this means:

There are 6 public documents A, B, C, D, E, F.

A common portion X, from D, E, and F extract the common portion Y from D, E, and F from the A, B, and C.

The common portion z is extracted from X, Y.
  • (123)

  New CommonschunkPlugin ({Name: "Common1", Chunks: ['INDEX', 'INDEX1', 'INDEX2']}, New CommonschunkPlugin ({Name: "Common2", Chunks: ['App', 'App1' , 'App2']}), New CommonschunkPlugin ({Name: "Common3",Chunks: ['Common1', 'Common2']}  
Clear, first extract public files in ‘INDEX’, ‘INDEX1’, ‘INDEX2’ ‘Common1 ‘, Then extract public file’ common2 ‘from’ App ”, ‘App1’, ‘App2’. Finally, the public file CommON3 is extracted from ‘Common1’ and ‘Common2’.

Optimization: {Runtimechunk: ‘SINGLE’, SPLITCHUNKS: {Chunks: “All “, minsize: 0, cachegroups: {CommON3: {Minchunks: 6, Priority: 1, ReuseExistingchunk: true}: 3, priority: -2, name: ‘common2’, chunks (chunk) {// Exclude `my-excluded-chunk` Return [‘App’, ‘App1’, ‘App2’]. Includes (chunk.name);}}, common1: {priority: -1, name: ‘COMMON1 ‘, Minchunks: 3, Enforce: true, chunks (chunk) {return [‘ index ‘,’ index1 ‘,’ index2 ‘]. include (chunk.name);}}}}}

  I didn't find it from the document: the method of extracting the public file. So I use another way:  
First extract public files from 6 files, namely CommON3 (CommON1 and Common2 public files).
From ‘INDEX’, ‘INDEX1’, ‘INDEX2’ Extracts COMMON2

The above is the full content of this article, I hope to help everyone, I hope everyone will support Tumi Clouds.
© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment