-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
29 lines (22 loc) · 953 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'use strict';
function filterScriptTags(tag) {
return tag.tagName === 'script';
}
function addCrossoriginAttrubuteToScript(script) {
script.attributes.crossorigin = 'anonymous';
}
function addCrossoriginAttrubuteToScripts(htmlPluginData, callback) {
htmlPluginData.head.filter(filterScriptTags).forEach(addCrossoriginAttrubuteToScript);
htmlPluginData.body.filter(filterScriptTags).forEach(addCrossoriginAttrubuteToScript);
callback(null, htmlPluginData);
}
function HtmlWebpackCrossoriginPlugin() {}
HtmlWebpackCrossoriginPlugin.prototype.apply = function(compiler) {
// Hook into the html-webpack-plugin processing
compiler.plugin('compilation', function(compilation) {
compilation.plugin('html-webpack-plugin-alter-asset-tags', function(htmlPluginData, callback) {
addCrossoriginAttrubuteToScripts(htmlPluginData, callback);
});
});
};
module.exports = HtmlWebpackCrossoriginPlugin;