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:
parent
f41f5be30a
commit
622f13252b
1 changed files with 9 additions and 1 deletions
|
@ -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(); })
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue