Fix inject-by-tag when enumerating assets which source is not a string

Some `assets.source()` return binary data arrays and should be skipped
This commit is contained in:
Peter Velkov 2017-04-12 13:11:30 +03:00
parent f41f5be30a
commit 622f13252b

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(); })
} }
} }