Skip to content

Commit 91382cf

Browse files
fix: respect directories in output (#200)
1 parent 6413654 commit 91382cf

6 files changed

+111
-5
lines changed

package-lock.json

+3-3
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
@@ -69,7 +69,7 @@
6969
"lint-staged": "^10.3.0",
7070
"memfs": "^3.2.0",
7171
"npm-run-all": "^4.1.5",
72-
"prettier": "^2.1.1",
72+
"prettier": "^2.1.2",
7373
"standard-version": "^9.0.0",
7474
"webpack": "^4.44.1"
7575
},

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class CompressionPlugin {
3232
cache = true,
3333
algorithm = 'gzip',
3434
compressionOptions = {},
35-
filename = '[base].gz',
35+
filename = '[path][base].gz',
3636
threshold = 0,
3737
minRatio = 0.8,
3838
deleteOriginalAssets = false,

test/__snapshots__/filename-option.test.js.snap.webpack4

+41
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,44 @@ Array [
122122
exports[`"filename" option matches snapshot for custom function ({Function}): errors 1`] = `Array []`;
123123

124124
exports[`"filename" option matches snapshot for custom function ({Function}): warnings 1`] = `Array []`;
125+
126+
exports[`"filename" option show work: assets 1`] = `
127+
Array [
128+
Array [
129+
"09a1a1112c577c2794359715edfcb5ac.png",
130+
78117,
131+
],
132+
Array [
133+
"09a1a1112c577c2794359715edfcb5ac.png.gz",
134+
73160,
135+
],
136+
Array [
137+
"23fc1d3ac606d117e05a140e0de79806.svg",
138+
672,
139+
],
140+
Array [
141+
"23fc1d3ac606d117e05a140e0de79806.svg.gz",
142+
393,
143+
],
144+
Array [
145+
"assets/scripts/async.async.js.gz",
146+
171,
147+
],
148+
Array [
149+
"assets/scripts/async.async.js?ver=f8840db1f464954a153b#hash",
150+
249,
151+
],
152+
Array [
153+
"assets/scripts/main.js.gz",
154+
3016,
155+
],
156+
Array [
157+
"assets/scripts/main.js?var=f8840db1f464954a153b#hash",
158+
11650,
159+
],
160+
]
161+
`;
162+
163+
exports[`"filename" option show work: errors 1`] = `Array []`;
164+
165+
exports[`"filename" option show work: warnings 1`] = `Array []`;

test/__snapshots__/filename-option.test.js.snap.webpack5

+41
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,44 @@ Array [
122122
exports[`"filename" option matches snapshot for custom function ({Function}): errors 1`] = `Array []`;
123123

124124
exports[`"filename" option matches snapshot for custom function ({Function}): warnings 1`] = `Array []`;
125+
126+
exports[`"filename" option show work: assets 1`] = `
127+
Array [
128+
Array [
129+
"09a1a1112c577c2794359715edfcb5ac.png",
130+
78117,
131+
],
132+
Array [
133+
"09a1a1112c577c2794359715edfcb5ac.png.gz",
134+
73160,
135+
],
136+
Array [
137+
"23fc1d3ac606d117e05a140e0de79806.svg",
138+
672,
139+
],
140+
Array [
141+
"23fc1d3ac606d117e05a140e0de79806.svg.gz",
142+
393,
143+
],
144+
Array [
145+
"assets/scripts/async.async.js.gz",
146+
179,
147+
],
148+
Array [
149+
"assets/scripts/async.async.js?ver=50393f48e1956509615a#hash",
150+
265,
151+
],
152+
Array [
153+
"assets/scripts/main.js.gz",
154+
3581,
155+
],
156+
Array [
157+
"assets/scripts/main.js?var=50393f48e1956509615a#hash",
158+
15256,
159+
],
160+
]
161+
`;
162+
163+
exports[`"filename" option show work: errors 1`] = `Array []`;
164+
165+
exports[`"filename" option show work: warnings 1`] = `Array []`;

test/filename-option.test.js

+24
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,30 @@ describe('"filename" option', () => {
1818
return removeCache();
1919
});
2020

21+
it('show work', async () => {
22+
compiler = getCompiler(
23+
'./entry.js',
24+
{},
25+
{
26+
output: {
27+
path: path.resolve(__dirname, './outputs'),
28+
filename: 'assets/scripts/[name].js?var=[hash]#hash',
29+
chunkFilename: 'assets/scripts/[id].[name].js?ver=[hash]#hash',
30+
},
31+
}
32+
);
33+
34+
new CompressionPlugin({
35+
minRatio: 1,
36+
}).apply(compiler);
37+
38+
const stats = await compile(compiler);
39+
40+
expect(getAssetsNameAndSize(stats)).toMatchSnapshot('assets');
41+
expect(getWarnings(stats)).toMatchSnapshot('errors');
42+
expect(getErrors(stats)).toMatchSnapshot('warnings');
43+
});
44+
2145
it('matches snapshot for `[path][base].super-compressed.gz[query][fragment]` value ({String})', async () => {
2246
compiler = getCompiler(
2347
'./entry.js',

0 commit comments

Comments
 (0)