diff --git a/src/index.js b/src/index.js index 60e909d2..3e2a9001 100644 --- a/src/index.js +++ b/src/index.js @@ -272,6 +272,7 @@ class MiniCssExtractPlugin { const chunkMap = this.getCssChunkObject(chunk); if (Object.keys(chunkMap).length > 0) { const chunkMaps = chunk.getChunkMaps(); + const { crossOriginLoading } = mainTemplate.outputOptions; const linkHrefPath = mainTemplate.getAssetPath( JSON.stringify(this.options.chunkFilename), { @@ -365,6 +366,17 @@ class MiniCssExtractPlugin { ]), '};', 'linkTag.href = fullhref;', + crossOriginLoading + ? Template.asString([ + `if (linkTag.href.indexOf(window.location.origin + '/') !== 0) {`, + Template.indent( + `linkTag.crossOrigin = ${JSON.stringify( + crossOriginLoading + )};` + ), + '}', + ]) + : '', 'var head = document.getElementsByTagName("head")[0];', 'head.appendChild(linkTag);', ]), diff --git a/test/manual/index.html b/test/manual/index.html index 8b29a314..8158d36a 100644 --- a/test/manual/index.html +++ b/test/manual/index.html @@ -47,6 +47,10 @@
Preloaded inlined CSS: Must be green.
displays an alert and should turn red.
+CrossOriginLoading Option: Must be red.
+loads chunks with crossorigin attribute and should turn green.
+