Skip to content

Commit

Permalink
fix(index): skip not changed chunk files in watch mode (fix #133)
Browse files Browse the repository at this point in the history
  • Loading branch information
akosyakov committed Oct 15, 2019
1 parent af883d8 commit f9bd29d
Show file tree
Hide file tree
Showing 15 changed files with 252 additions and 126 deletions.
41 changes: 11 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class CompressionPlugin {
constructor(options = {}) {
validateOptions(schema, options, 'Compression Plugin');

this.chunkVersions = {};

const {
test,
include,
Expand Down Expand Up @@ -85,12 +87,34 @@ class CompressionPlugin {
? findCacheDir({ name: 'compression-webpack-plugin' }) ||
os.tmpdir()
: cache;

const skipFiles = {};
for (const chunk of compilation.chunks) {
const oldVersion = this.chunkVersions[chunk.id];
this.chunkVersions[chunk.id] = chunk.hash;
if (chunk.hash === oldVersion) {
for (const chunkModule of chunk.getModules()) {
if (chunkModule.buildInfo.assets) {
for (const file of Object.keys(chunkModule.buildInfo.assets)) {
skipFiles[file] = true;
}
}
}
for (const file of chunk.files) {
skipFiles[file] = true;
}
}
}

const { assets } = compilation;

// eslint-disable-next-line consistent-return
async.forEach(
Object.keys(assets),
(file, cb) => {
if (skipFiles[file]) {
return cb();
}
if (!ModuleFilenameHelpers.matchObject(this.options, file)) {
return cb();
}
Expand Down
18 changes: 9 additions & 9 deletions test/__snapshots__/algorithm.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ exports[`when applied with \`algorithm\` option matches snapshot for \`unknown\`
exports[`when applied with \`algorithm\` option matches snapshot for custom function ({Function}): assets 1`] = `
Array [
Array [
"0.async.dbe59b7ea0e1a63e45d4.js",
130,
"0.async.c587a252db9084a74145.js",
156,
],
Array [
"0.async.dbe59b7ea0e1a63e45d4.js.gz",
130,
"0.async.c587a252db9084a74145.js.gz",
156,
],
Array [
"5b1f36bc41ab31f5b801d48ba1d65781.png",
Expand All @@ -70,11 +70,11 @@ Array [
672,
],
Array [
"js.b329671af0217355535e.js",
"js.f9610f680ea96abb497c.js",
10267,
],
Array [
"js.b329671af0217355535e.js.gz",
"js.f9610f680ea96abb497c.js.gz",
10267,
],
]
Expand All @@ -95,8 +95,8 @@ exports[`when applied with \`algorithm\` option matches snapshot for custom func
exports[`when applied with \`algorithm\` option matches snapshot for custom function with error ({Function}): assets 1`] = `
Array [
Array [
"0.async.dbe59b7ea0e1a63e45d4.js",
130,
"0.async.c587a252db9084a74145.js",
156,
],
Array [
"5b1f36bc41ab31f5b801d48ba1d65781.png",
Expand All @@ -107,7 +107,7 @@ Array [
672,
],
Array [
"js.b329671af0217355535e.js",
"js.f9610f680ea96abb497c.js",
10267,
],
]
Expand Down
54 changes: 27 additions & 27 deletions test/__snapshots__/cache-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
exports[`when applied with \`cache\` option matches snapshot for \`false\` value ({Boolean}): assets 1`] = `
Array [
Array [
"0.async.dbe59b7ea0e1a63e45d4.js",
130,
"0.async.c587a252db9084a74145.js",
156,
],
Array [
"0.async.dbe59b7ea0e1a63e45d4.js.gz",
117,
"0.async.c587a252db9084a74145.js.gz",
141,
],
Array [
"5b1f36bc41ab31f5b801d48ba1d65781.png",
Expand All @@ -27,12 +27,12 @@ Array [
393,
],
Array [
"js.b329671af0217355535e.js",
"js.f9610f680ea96abb497c.js",
10267,
],
Array [
"js.b329671af0217355535e.js.gz",
2798,
"js.f9610f680ea96abb497c.js.gz",
2800,
],
]
`;
Expand Down Expand Up @@ -151,10 +151,10 @@ exports[`when applied with \`cache\` option matches snapshot for \`other-cache-d

exports[`when applied with \`cache\` option matches snapshot for \`other-cache-directory\` value ({String}): warnings 2`] = `Array []`;

exports[`when applied with \`cache\` option matches snapshot for \`true\` value ({Boolean}): 0.async.dbe59b7ea0e1a63e45d4.js 1`] = `
exports[`when applied with \`cache\` option matches snapshot for \`true\` value ({Boolean}): 0.async.c587a252db9084a74145.js 1`] = `
Array [
"0.async.dbe59b7ea0e1a63e45d4.js",
"5c060e109cf6db498e14403ffb1625d2",
"0.async.c587a252db9084a74145.js",
"7f47cd87e89ca2c1c3bd594a48c080ea",
]
`;

Expand All @@ -175,12 +175,12 @@ Array [
exports[`when applied with \`cache\` option matches snapshot for \`true\` value ({Boolean}): assets 1`] = `
Array [
Array [
"0.async.dbe59b7ea0e1a63e45d4.js",
130,
"0.async.c587a252db9084a74145.js",
156,
],
Array [
"0.async.dbe59b7ea0e1a63e45d4.js.gz",
117,
"0.async.c587a252db9084a74145.js.gz",
141,
],
Array [
"5b1f36bc41ab31f5b801d48ba1d65781.png",
Expand All @@ -199,25 +199,25 @@ Array [
393,
],
Array [
"js.b329671af0217355535e.js",
"js.f9610f680ea96abb497c.js",
10267,
],
Array [
"js.b329671af0217355535e.js.gz",
2798,
"js.f9610f680ea96abb497c.js.gz",
2800,
],
]
`;

exports[`when applied with \`cache\` option matches snapshot for \`true\` value ({Boolean}): assets 2`] = `
Array [
Array [
"0.async.dbe59b7ea0e1a63e45d4.js",
130,
"0.async.c587a252db9084a74145.js",
156,
],
Array [
"0.async.dbe59b7ea0e1a63e45d4.js.gz",
117,
"0.async.c587a252db9084a74145.js.gz",
141,
],
Array [
"5b1f36bc41ab31f5b801d48ba1d65781.png",
Expand All @@ -236,12 +236,12 @@ Array [
393,
],
Array [
"js.b329671af0217355535e.js",
"js.f9610f680ea96abb497c.js",
10267,
],
Array [
"js.b329671af0217355535e.js.gz",
2798,
"js.f9610f680ea96abb497c.js.gz",
2800,
],
]
`;
Expand All @@ -250,10 +250,10 @@ exports[`when applied with \`cache\` option matches snapshot for \`true\` value

exports[`when applied with \`cache\` option matches snapshot for \`true\` value ({Boolean}): errors 2`] = `Array []`;

exports[`when applied with \`cache\` option matches snapshot for \`true\` value ({Boolean}): js.b329671af0217355535e.js 1`] = `
exports[`when applied with \`cache\` option matches snapshot for \`true\` value ({Boolean}): js.f9610f680ea96abb497c.js 1`] = `
Array [
"js.b329671af0217355535e.js",
"2d7d8055981a31c21f6b265777fe4abe",
"js.f9610f680ea96abb497c.js",
"6de9239c24abaf17df39cff09218a67a",
]
`;

Expand Down
Loading

0 comments on commit f9bd29d

Please sign in to comment.