@@ -16,8 +16,12 @@ A pattern is a `from` plus optional `to`, `filename`, `context`, `globOptions`,
1616filename template, so one pattern can rename, flatten and hash.
1717
1818` output.copy ` takes a string or a list of patterns. The plugin behind it takes
19- ` concurrency ` and the ` processAssets ` ` stage ` as well — reach for
20- ` new CopyPlugin({ patterns, stage }) ` when you need those.
19+ ` concurrency ` and the ` processAssets ` ` stage ` as well, so reach for
20+ ` new webpack.CopyPlugin({ patterns, concurrency, stage }) ` when you need those —
21+ the config below copies a prebuilt vendor bundle that way. ` stage ` decides which
22+ asset-processing taps see what was copied; it is not how a file is kept out of
23+ the minimizer, which re-runs for assets added at any later stage. `info:
24+ { minimized: true }` is what leaves an already-built file alone.
2125
2226The config also registers a small plugin that merges several copied assets into
2327one — ` copy-webpack-plugin ` 's ` transformAll ` . ` output.copy ` has no equivalent
@@ -29,7 +33,7 @@ key a cache item on their contents, emit the merged asset and delete the parts.
2933``` javascript
3034" use strict" ;
3135
32- const { Compilation , sources } = require (" webpack" );
36+ const { Compilation , CopyPlugin , sources } = require (" webpack" );
3337
3438/** @import { Compiler } from "webpack" */
3539
@@ -143,6 +147,22 @@ const config = {
143147 ]
144148 },
145149 plugins: [
150+ // the plugin behind `output.copy` is where `concurrency` and `stage` live;
151+ // `stage` decides which asset-processing taps see what it copied
152+ new CopyPlugin ({
153+ patterns: [
154+ {
155+ from: " *.min.js" ,
156+ context: " vendor" ,
157+ to: " vendor" ,
158+ // the minimizer re-runs for assets added at any later stage, so
159+ // this, not a late `stage`, is what leaves a built file alone
160+ info: { minimized: true }
161+ }
162+ ],
163+ concurrency: 50 ,
164+ stage: Compilation .PROCESS_ASSETS_STAGE_ADDITIONS
165+ }),
146166 new MergeCopiedAssetsPlugin ({
147167 include: / ^ licenses\/ / ,
148168 filename: " THIRD_PARTY_LICENSES.txt" ,
@@ -193,6 +213,7 @@ assets by path *.txt 144 bytes
193213 asset THIRD_PARTY_LICENSES.txt 121 bytes [emitted] [copied]
194214 asset robots.txt 23 bytes [emitted] [from: static/robots.txt] [copied]
195215asset output.js 222 bytes [emitted] (name: main)
216+ asset vendor/analytics.min.js 72 bytes [emitted] [from: vendor/analytics.min.js] [copied]
196217asset index.html 69 bytes [emitted] [from: static/index.html] [copied]
197218asset pages/index.html 69 bytes [emitted] [from: static/index.html] [copied]
198219asset runtime/config.json 33 bytes [emitted] [from: config.json] [copied]
@@ -216,6 +237,7 @@ assets by info 44 bytes [immutable]
216237assets by path *.txt 144 bytes
217238 asset THIRD_PARTY_LICENSES.txt 121 bytes [emitted] [copied]
218239 asset robots.txt 23 bytes [emitted] [from: static/robots.txt] [copied]
240+ asset vendor/analytics.min.js 72 bytes [emitted] [from: vendor/analytics.min.js] [copied] [minimized]
219241asset index.html 64 bytes [emitted] [from: static/index.html] [copied] [minimized]
220242asset pages/index.html 64 bytes [emitted] [from: static/index.html] [copied] [minimized]
221243asset runtime/config.json 33 bytes [emitted] [from: config.json] [copied]
0 commit comments