Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5b8b356

Browse files
feat: compress assets added later by plugins
1 parent efadca8 commit 5b8b356

17 files changed

+549
-408
lines changed

package-lock.json

+54-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"npm-run-all": "^4.1.5",
6969
"prettier": "^2.1.2",
7070
"standard-version": "^9.0.0",
71-
"webpack": "^5.9.0",
71+
"webpack": "^5.10.0",
7272
"workbox-webpack-plugin": "^6.0.0-alpha.3"
7373
},
7474
"keywords": [

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ class CompressionPlugin {
293293
name: pluginName,
294294
stage:
295295
compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER,
296+
additionalAssets: true,
296297
},
297298
(assets) => this.compress(compiler, compilation, assets)
298299
);

test/CompressionPlugin.test.js

+25-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
compile,
88
CopyPluginWithAssetInfo,
99
ModifyExistingAsset,
10+
EmitNewAsset,
1011
getAssetsNameAndSize,
1112
getCompiler,
1213
getErrors,
@@ -171,9 +172,7 @@ describe("CompressionPlugin", () => {
171172
const stringStats = stats.toString({ relatedAssets: true });
172173
const printedCompressed = stringStats.match(/\[compressed]/g);
173174

174-
expect(printedCompressed ? printedCompressed.length : 0).toBe(
175-
getCompiler.isWebpack4() ? 0 : 3
176-
);
175+
expect(printedCompressed ? printedCompressed.length : 0).toBe(3);
177176
expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets");
178177
expect(getWarnings(stats)).toMatchSnapshot("warnings");
179178
expect(getErrors(stats)).toMatchSnapshot("errors");
@@ -407,4 +406,27 @@ describe("CompressionPlugin", () => {
407406
resolve();
408407
});
409408
});
409+
410+
it("should run plugin against assets added later by plugins", async () => {
411+
const compiler = getCompiler(
412+
"./number.js",
413+
{},
414+
{
415+
output: {
416+
path: path.resolve(__dirname, "./outputs"),
417+
filename: "[name].js",
418+
chunkFilename: "[id].js",
419+
},
420+
}
421+
);
422+
423+
new CompressionPlugin({ minRatio: 10 }).apply(compiler);
424+
new EmitNewAsset({ name: "newFile.js" }).apply(compiler);
425+
426+
const stats = await compile(compiler);
427+
428+
expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets");
429+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
430+
expect(getErrors(stats)).toMatchSnapshot("errors");
431+
});
410432
});

0 commit comments

Comments
 (0)