From 72dd0957d64bb37d6f32d7bf1fa2e70bdf8205c8 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Fri, 15 Feb 2019 22:57:11 +0300 Subject: [PATCH] fix: handle `[contenthash]` as template --- src/preProcessPattern.js | 2 +- test/CopyPlugin.test.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/preProcessPattern.js b/src/preProcessPattern.js index bf38bef1..ad7618ab 100644 --- a/src/preProcessPattern.js +++ b/src/preProcessPattern.js @@ -7,7 +7,7 @@ import isObject from './utils/isObject'; import { stat } from './utils/promisify'; // https://www.debuggex.com/r/VH2yS2mvJOitiyr3 -const isTemplateLike = /(\[ext\])|(\[name\])|(\[path\])|(\[folder\])|(\[emoji(:\d+)?\])|(\[(\w+:)?hash(:\w+)?(:\d+)?\])|(\[\d+\])/; +const isTemplateLike = /(\[ext\])|(\[name\])|(\[path\])|(\[folder\])|(\[emoji(:\d+)?\])|(\[(\w+:)?(hash|contenthash)(:\w+)?(:\d+)?\])|(\[\d+\])/; /* eslint-disable no-param-reassign */ diff --git a/test/CopyPlugin.test.js b/test/CopyPlugin.test.js index 445f1502..bcbfc3c0 100644 --- a/test/CopyPlugin.test.js +++ b/test/CopyPlugin.test.js @@ -1184,6 +1184,20 @@ describe('apply function', () => { .catch(done); }); + it('allows pattern to contain contenthash', (done) => { + runEmit({ + expectedAssetKeys: ['directory/22af64.txt'], + patterns: [ + { + from: 'directory/directoryfile.txt', + to: 'directory/[contenthash:6].txt', + }, + ], + }) + .then(done) + .catch(done); + }); + it('transform with promise', (done) => { runEmit({ expectedAssetKeys: ['file.txt'],