Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ HtmlWebpackInlineSourcePlugin.prototype.apply = function (compiler) {
}

var regexStr = htmlPluginData.plugin.options.inlineSource;
var nonceTemplateStr = htmlPluginData.plugin.options.nonceTemplate;

var result = self.processTags(compilation, regexStr, htmlPluginData);
var result = self.processTags(compilation, regexStr, htmlPluginData, nonceTemplateStr);

callback(null, result);
});
});
};

HtmlWebpackInlineSourcePlugin.prototype.processTags = function (compilation, regexStr, pluginData) {
HtmlWebpackInlineSourcePlugin.prototype.processTags = function (compilation, regexStr, pluginData, nonceTemplateStr) {
var self = this;

var body = [];
Expand All @@ -42,11 +43,11 @@ HtmlWebpackInlineSourcePlugin.prototype.processTags = function (compilation, reg
var regex = new RegExp(regexStr);

pluginData.head.forEach(function (tag) {
head.push(self.processTag(compilation, regex, tag));
head.push(self.processTag(compilation, regex, tag, nonceTemplateStr));
});

pluginData.body.forEach(function (tag) {
body.push(self.processTag(compilation, regex, tag));
body.push(self.processTag(compilation, regex, tag, nonceTemplateStr));
});

return { head: head, body: body, plugin: pluginData.plugin, chunks: pluginData.chunks, outputName: pluginData.outputName };
Expand Down Expand Up @@ -83,7 +84,7 @@ HtmlWebpackInlineSourcePlugin.prototype.resolveSourceMaps = function (compilatio
});
};

HtmlWebpackInlineSourcePlugin.prototype.processTag = function (compilation, regex, tag) {
HtmlWebpackInlineSourcePlugin.prototype.processTag = function (compilation, regex, tag, nonceTemplateStr) {
var assetUrl;

// inline js
Expand All @@ -97,6 +98,10 @@ HtmlWebpackInlineSourcePlugin.prototype.processTag = function (compilation, rege
}
};

if (nonceTemplateStr) {
tag.attributes.nonce = nonceTemplateStr;
}

// inline css
} else if (tag.tagName === 'link' && regex.test(tag.attributes.href)) {
assetUrl = tag.attributes.href;
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
{
"name": "html-webpack-inline-source-plugin",
"version": "0.0.10",
"name": "@postmates/html-webpack-inline-source-plugin",
"version": "0.0.10-pm1",
"description": "Embed javascript and css source inline when using the webpack dev server or middleware",
"main": "index.js",
"files": [
"index.js"
],
"scripts": {
"prepublish": "npm run test",
"pretest": "semistandard",
"test": "jasmine",
"debug": "node-debug jasmine"
},
"repository": {
"type": "git",
"url": "https://github.com/dustinjackson/html-webpack-inline-source-plugin.git"
"url": "git+https://github.com/postmates/html-webpack-inline-source-plugin.git"
},
"keywords": [
"webpack",
Expand Down