diff --git a/lib/index.js b/lib/index.js index 189266b..0a12f17 100644 --- a/lib/index.js +++ b/lib/index.js @@ -14,7 +14,7 @@ const defaults = { generate: void 0, map: null, publicPath: null, - removeKeyHash: /([a-f0-9]{32}\.?)/gi, + removeKeyHash: /([a-f0-9]{16,32}\.?)/gi, // seed must be reset for each compilation. let the code initialize it to {} seed: void 0, serialize(manifest) { diff --git a/test/unit/options.js b/test/unit/options.js index 507addf..fd8b75b 100644 --- a/test/unit/options.js +++ b/test/unit/options.js @@ -10,7 +10,7 @@ const outputPath = join(__dirname, '../output/options'); test.after(() => del(outputPath)); -const clean = (what) => what.replace(/([a-f0-9]{20,32})/gi, '[test-hash]'); +const clean = (what) => what.replace(/([a-f0-9]{16,32})/gi, '[test-hash]'); test('removeKeyHash', async (t) => { const config = { @@ -49,6 +49,44 @@ test('removeKeyHash', async (t) => { t.snapshot(manifest); }); +// test('removeKeyHash, custom hash length', async (t) => { +// const config = { +// context: __dirname, +// entry: '../fixtures/file.js', +// output: { +// hashDigestLength: 16, +// filename: '[contenthash].removeKeyHash.js', +// path: join(outputPath, 'removeKeyHash') +// }, +// plugins: [ +// new CopyPlugin({ +// patterns: [ +// { from: '../fixtures/*.css', to: '[name].[contenthash].[ext]' }, +// { from: '../fixtures/*.txt', to: '[contenthash].[name].[ext]' } +// ] +// }) +// ] +// }; +// +// let { manifest } = await compile(config, t); +// +// manifest = Object.keys(manifest).reduce((prev, key) => { +// prev[clean(key)] = clean(manifest[key]); +// return prev; +// }, {}); +// +// t.snapshot(manifest); +// +// ({ manifest } = await compile(config, t, { removeKeyHash: false })); +// +// manifest = Object.keys(manifest).reduce((prev, key) => { +// prev[clean(key)] = clean(manifest[key]); +// return prev; +// }, {}); +// +// t.snapshot(manifest); +// }); + test('useEntryKeys', async (t) => { const config = { context: __dirname, diff --git a/test/unit/snapshots/options.js.md b/test/unit/snapshots/options.js.md index 6089cce..e6a6f77 100644 --- a/test/unit/snapshots/options.js.md +++ b/test/unit/snapshots/options.js.md @@ -38,3 +38,39 @@ Generated by [AVA](https://avajs.dev). main: 'main.js', 'main.js.map': 'main.js.map', } + +## removeKeyHash, custom length + +> Snapshot 1 + + { + '38bc9557de1c.file.txt': '38bc9557de1c.file.txt', + 'main.js': 'bd0a62f1ec59.removeKeyHash.js', + 'style.e75256f5f60f.css': 'style.e75256f5f60f.css', + } + +> Snapshot 2 + + { + '38bc9557de1c.file.txt': '38bc9557de1c.file.txt', + 'main.js': 'bd0a62f1ec59.removeKeyHash.js', + 'style.e75256f5f60f.css': 'style.e75256f5f60f.css', + } + +## removeKeyHash, custom hash length + +> Snapshot 1 + + { + 'file.txt': '[test-hash].file.txt', + 'main.js': '[test-hash].removeKeyHash.js', + 'style.css': 'style.[test-hash].css', + } + +> Snapshot 2 + + { + '[test-hash].file.txt': '[test-hash].file.txt', + 'main.js': '[test-hash].removeKeyHash.js', + 'style.[test-hash].css': 'style.[test-hash].css', + } diff --git a/test/unit/snapshots/options.js.snap b/test/unit/snapshots/options.js.snap index 7505ae7..7701f27 100644 Binary files a/test/unit/snapshots/options.js.snap and b/test/unit/snapshots/options.js.snap differ