Skip to content

Commit 66de564

Browse files
Merge pull request #69 from wulijian/master
fix: close #57, 'source' undefined
2 parents e557e50 + 1f59155 commit 66de564

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ HtmlWebpackInlineSourcePlugin.prototype.resolveSourceMaps = function (compilatio
8282

8383
HtmlWebpackInlineSourcePlugin.prototype.processTag = function (compilation, regex, tag, filename) {
8484
var assetUrl;
85+
var preTag = tag;
8586

8687
// inline js
8788
if (tag.tagName === 'script' && tag.attributes && regex.test(tag.attributes.src)) {
@@ -115,8 +116,12 @@ HtmlWebpackInlineSourcePlugin.prototype.processTag = function (compilation, rege
115116
}
116117
var assetName = path.posix.relative(publicUrlPrefix, assetUrl);
117118
var asset = getAssetByName(compilation.assets, assetName);
118-
var updatedSource = this.resolveSourceMaps(compilation, assetName, asset);
119-
tag.innerHTML = (tag.tagName === 'script') ? updatedSource.replace(/(<)(\/script>)/g, '\\x3C$2') : updatedSource;
119+
if (compilation.assets[assetName] !== undefined) {
120+
var updatedSource = this.resolveSourceMaps(compilation, assetName, asset);
121+
tag.innerHTML = (tag.tagName === 'script') ? updatedSource.replace(/(<)(\/script>)/g, '\\x3C$2') : updatedSource;
122+
}else{
123+
return preTag;
124+
}
120125
}
121126

122127
return tag;

0 commit comments

Comments
 (0)