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..0907b80 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, 'removeKeyHashCustomLength') + }, + 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..086ca0a 100644 --- a/test/unit/snapshots/options.js.md +++ b/test/unit/snapshots/options.js.md @@ -6,6 +6,24 @@ Generated by [AVA](https://avajs.dev). ## removeKeyHash +> 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', + } + +## removeKeyHash, custom hash length + > Snapshot 1 { diff --git a/test/unit/snapshots/options.js.snap b/test/unit/snapshots/options.js.snap index 7505ae7..24445cb 100644 Binary files a/test/unit/snapshots/options.js.snap and b/test/unit/snapshots/options.js.snap differ