Skip to content

Commit

Permalink
fix: respect directories in output (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Sep 16, 2020
1 parent 6413654 commit 91382cf
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 5 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"lint-staged": "^10.3.0",
"memfs": "^3.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.1.1",
"prettier": "^2.1.2",
"standard-version": "^9.0.0",
"webpack": "^4.44.1"
},
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CompressionPlugin {
cache = true,
algorithm = 'gzip',
compressionOptions = {},
filename = '[base].gz',
filename = '[path][base].gz',
threshold = 0,
minRatio = 0.8,
deleteOriginalAssets = false,
Expand Down
41 changes: 41 additions & 0 deletions test/__snapshots__/filename-option.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,44 @@ Array [
exports[`"filename" option matches snapshot for custom function ({Function}): errors 1`] = `Array []`;

exports[`"filename" option matches snapshot for custom function ({Function}): warnings 1`] = `Array []`;

exports[`"filename" option show work: assets 1`] = `
Array [
Array [
"09a1a1112c577c2794359715edfcb5ac.png",
78117,
],
Array [
"09a1a1112c577c2794359715edfcb5ac.png.gz",
73160,
],
Array [
"23fc1d3ac606d117e05a140e0de79806.svg",
672,
],
Array [
"23fc1d3ac606d117e05a140e0de79806.svg.gz",
393,
],
Array [
"assets/scripts/async.async.js.gz",
171,
],
Array [
"assets/scripts/async.async.js?ver=f8840db1f464954a153b#hash",
249,
],
Array [
"assets/scripts/main.js.gz",
3016,
],
Array [
"assets/scripts/main.js?var=f8840db1f464954a153b#hash",
11650,
],
]
`;

exports[`"filename" option show work: errors 1`] = `Array []`;

exports[`"filename" option show work: warnings 1`] = `Array []`;
41 changes: 41 additions & 0 deletions test/__snapshots__/filename-option.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,44 @@ Array [
exports[`"filename" option matches snapshot for custom function ({Function}): errors 1`] = `Array []`;

exports[`"filename" option matches snapshot for custom function ({Function}): warnings 1`] = `Array []`;

exports[`"filename" option show work: assets 1`] = `
Array [
Array [
"09a1a1112c577c2794359715edfcb5ac.png",
78117,
],
Array [
"09a1a1112c577c2794359715edfcb5ac.png.gz",
73160,
],
Array [
"23fc1d3ac606d117e05a140e0de79806.svg",
672,
],
Array [
"23fc1d3ac606d117e05a140e0de79806.svg.gz",
393,
],
Array [
"assets/scripts/async.async.js.gz",
179,
],
Array [
"assets/scripts/async.async.js?ver=50393f48e1956509615a#hash",
265,
],
Array [
"assets/scripts/main.js.gz",
3581,
],
Array [
"assets/scripts/main.js?var=50393f48e1956509615a#hash",
15256,
],
]
`;

exports[`"filename" option show work: errors 1`] = `Array []`;

exports[`"filename" option show work: warnings 1`] = `Array []`;
24 changes: 24 additions & 0 deletions test/filename-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ describe('"filename" option', () => {
return removeCache();
});

it('show work', async () => {
compiler = getCompiler(
'./entry.js',
{},
{
output: {
path: path.resolve(__dirname, './outputs'),
filename: 'assets/scripts/[name].js?var=[hash]#hash',
chunkFilename: 'assets/scripts/[id].[name].js?ver=[hash]#hash',
},
}
);

new CompressionPlugin({
minRatio: 1,
}).apply(compiler);

const stats = await compile(compiler);

expect(getAssetsNameAndSize(stats)).toMatchSnapshot('assets');
expect(getWarnings(stats)).toMatchSnapshot('errors');
expect(getErrors(stats)).toMatchSnapshot('warnings');
});

it('matches snapshot for `[path][base].super-compressed.gz[query][fragment]` value ({String})', async () => {
compiler = getCompiler(
'./entry.js',
Expand Down

0 comments on commit 91382cf

Please sign in to comment.