Merge pull request #14 from kidroca/fix-insert-by-tag-missing-assest-source

Fix inject-by-tag when enumerating assets which source is not a string
This commit is contained in:
Radek 2017-04-12 12:40:21 +01:00 committed by GitHub
commit 814e3699d5
2 changed files with 22 additions and 4 deletions

View file

@ -643,22 +643,32 @@ var InjectByTag = function () {
for (var basename in compilation.assets) { for (var basename in compilation.assets) {
// only if match regex // only if match regex
if (_this.context.config.componentsOptions.InjectByTag.fileRegex.test(basename)) { if (_this.context.config.componentsOptions.InjectByTag.fileRegex.test(basename)) {
(function () { var _ret = function () {
var replaced = 0; var replaced = 0;
var asset = compilation.assets[basename]; 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++; replaced++;
return _this.context.version; return _this.context.version;
}); });
asset.source = function () { asset.source = function () {
return modFile; return modFile;
}; };
_log2.default.info('InjectByTag : match : ' + basename + ' : replaced : ' + replaced); _log2.default.info('InjectByTag : match : ' + basename + ' : replaced : ' + replaced);
})(); }();
if (_ret === 'continue') continue;
} }
} }
cb(); cb();
}); });
return new _promise2.default(function (resolve, reject) { return new _promise2.default(function (resolve, reject) {
resolve(); resolve();
}); });

View file

@ -21,16 +21,24 @@ export default class InjectByTag{
if(this.context.config.componentsOptions.InjectByTag.fileRegex.test(basename)) { if(this.context.config.componentsOptions.InjectByTag.fileRegex.test(basename)) {
let replaced = 0; let replaced = 0;
let asset = compilation.assets[basename]; 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++; replaced++;
return this.context.version; return this.context.version;
}); });
asset.source = () => modFile; asset.source = () => modFile;
log.info(`InjectByTag : match : ${basename} : replaced : ${replaced}`); log.info(`InjectByTag : match : ${basename} : replaced : ${replaced}`);
} }
} }
cb(); cb();
}); });
return new Promise((resolve, reject) => { resolve(); }) return new Promise((resolve, reject) => { resolve(); })
} }
} }