Skip to content

Commit

Permalink
fix: compatibility with workbox-webpack-plugin (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored Dec 18, 2020
1 parent 72f3093 commit 5d54128
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class CompressionPlugin {
apply(compiler) {
const pluginName = this.constructor.name;

compiler.hooks.compilation.tap(pluginName, (compilation) => {
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
compilation.hooks.processAssets.tapPromise(
{
name: pluginName,
Expand Down
52 changes: 52 additions & 0 deletions test/CompressionPlugin.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import zlib from "zlib";
import path from "path";

import { GenerateSW, InjectManifest } from "workbox-webpack-plugin";

import CompressionPlugin from "../src/index";

import {
Expand Down Expand Up @@ -423,4 +425,54 @@ describe("CompressionPlugin", () => {
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});

// TODO broken on windows https://github.com/GoogleChrome/workbox/issues/2667
it.skip("should work with 'workbox-webpack-plugin' (GenerateSW)", async () => {
const compiler = getCompiler(
"./entry.js",
{},
{
output: {
path: `${__dirname}/dist`,
filename: "[name].js?var=[hash]",
chunkFilename: "[id].[name].js?ver=[hash]",
},
}
);

new CompressionPlugin().apply(compiler);
new GenerateSW().apply(compiler);

const stats = await compile(compiler);

expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});

// TODO broken on windows https://github.com/GoogleChrome/workbox/issues/2667
it.skip("should work with 'workbox-webpack-plugin' (InjectManifest)", async () => {
const compiler = getCompiler(
"./entry.js",
{},
{
output: {
path: `${__dirname}/dist`,
filename: "[name].js?var=[hash]",
chunkFilename: "[id].[name].js?ver=[hash]",
},
}
);

new CompressionPlugin().apply(compiler);
new InjectManifest({
swSrc: path.resolve(__dirname, "./fixtures/sw.js"),
}).apply(compiler);

const stats = await compile(compiler);

expect(getAssetsNameAndSize(stats, compiler)).toMatchSnapshot("assets");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
});

0 comments on commit 5d54128

Please sign in to comment.