From baefbb9d3c509bef2f67947ee3eb9be8e5292a53 Mon Sep 17 00:00:00 2001 From: Chikara Chan Date: Wed, 21 Nov 2018 19:30:58 +0800 Subject: [PATCH] feat: add crossOriginLoading option --- src/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/index.js b/src/index.js index 49d458ff..d943062d 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), { @@ -363,6 +364,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);', ]),