From 622f13252bdb115c200e328a408289d0053c24c3 Mon Sep 17 00:00:00 2001 From: Peter Velkov Date: Wed, 12 Apr 2017 13:11:30 +0300 Subject: [PATCH 1/2] Fix inject-by-tag when enumerating assets which source is not a string Some `assets.source()` return binary data arrays and should be skipped --- src/components/inject-by-tag.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/inject-by-tag.js b/src/components/inject-by-tag.js index 07e8e76..3f68e83 100644 --- a/src/components/inject-by-tag.js +++ b/src/components/inject-by-tag.js @@ -21,16 +21,24 @@ export default class InjectByTag{ if(this.context.config.componentsOptions.InjectByTag.fileRegex.test(basename)) { let replaced = 0; let asset = compilation.assets[basename]; - let modFile = asset.source().replace(/(\[AIV\]{version}\[\/AIV\])/g, () => { + + const originalSource = asset.source(); + if (!originalSource || typeof originalSource.replace !== 'function') { + continue; + } + + let modFile = originalSource.replace(/(\[AIV\]{version}\[\/AIV\])/g, () => { replaced++; return this.context.version; }); + asset.source = () => modFile; log.info(`InjectByTag : match : ${basename} : replaced : ${replaced}`); } } cb(); }); + return new Promise((resolve, reject) => { resolve(); }) } } \ No newline at end of file From 95b2888cfa40801b8ce790d65e62f69ae9582659 Mon Sep 17 00:00:00 2001 From: Peter Velkov Date: Wed, 12 Apr 2017 13:14:37 +0300 Subject: [PATCH 2/2] Rebuild dist with changes --- dist/WebpackAutoInjectVersion.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/dist/WebpackAutoInjectVersion.js b/dist/WebpackAutoInjectVersion.js index d05f435..6df0563 100644 --- a/dist/WebpackAutoInjectVersion.js +++ b/dist/WebpackAutoInjectVersion.js @@ -643,22 +643,32 @@ var InjectByTag = function () { for (var basename in compilation.assets) { // only if match regex if (_this.context.config.componentsOptions.InjectByTag.fileRegex.test(basename)) { - (function () { + var _ret = function () { var replaced = 0; var asset = compilation.assets[basename]; - var modFile = asset.source().replace(/(\[AIV\]{version}\[\/AIV\])/g, function () { + + var originalSource = asset.source(); + if (!originalSource || typeof originalSource.replace !== 'function') { + return 'continue'; + } + + var modFile = originalSource.replace(/(\[AIV\]{version}\[\/AIV\])/g, function () { replaced++; return _this.context.version; }); + asset.source = function () { return modFile; }; _log2.default.info('InjectByTag : match : ' + basename + ' : replaced : ' + replaced); - })(); + }(); + + if (_ret === 'continue') continue; } } cb(); }); + return new _promise2.default(function (resolve, reject) { resolve(); });