diff --git a/src/__tests__/fixtures/asset-tag/__snapshots__/webpack4/server--main.js b/src/__tests__/fixtures/asset-tag/__snapshots__/webpack4/server--main.js index 653c9da..1ff7862 100644 --- a/src/__tests__/fixtures/asset-tag/__snapshots__/webpack4/server--main.js +++ b/src/__tests__/fixtures/asset-tag/__snapshots__/webpack4/server--main.js @@ -254,6 +254,7 @@ const _marko_template = Object(marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_ +const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin"; function renderAssets(out) { const entries = this.___entries; @@ -275,7 +276,7 @@ function renderAssets(out) { for (const href of assets.js) { if (!written.has(href)) { written.add(href); - scripts += ``; + scripts += ``; } } } diff --git a/src/__tests__/fixtures/asset-tag/__snapshots__/webpack5/server--main.js b/src/__tests__/fixtures/asset-tag/__snapshots__/webpack5/server--main.js index d14de78..787f6b5 100644 --- a/src/__tests__/fixtures/asset-tag/__snapshots__/webpack5/server--main.js +++ b/src/__tests__/fixtures/asset-tag/__snapshots__/webpack5/server--main.js @@ -156,6 +156,7 @@ const _marko_template = (0,marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_0__. +const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin"; function renderAssets(out) { const entries = this.___entries; @@ -177,7 +178,7 @@ function renderAssets(out) { for (const href of assets.js) { if (!written.has(href)) { written.add(href); - scripts += ``; + scripts += ``; } } } diff --git a/src/__tests__/fixtures/basic-template-plugin-custom-runtime-id/__snapshots__/webpack4/server--main.js b/src/__tests__/fixtures/basic-template-plugin-custom-runtime-id/__snapshots__/webpack4/server--main.js index 2d783d8..1d285dd 100644 --- a/src/__tests__/fixtures/basic-template-plugin-custom-runtime-id/__snapshots__/webpack4/server--main.js +++ b/src/__tests__/fixtures/basic-template-plugin-custom-runtime-id/__snapshots__/webpack4/server--main.js @@ -166,6 +166,7 @@ const _marko_template = Object(marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_ +const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin"; function renderAssets(out) { const entries = this.___entries; @@ -187,7 +188,7 @@ function renderAssets(out) { for (const href of assets.js) { if (!written.has(href)) { written.add(href); - scripts += ``; + scripts += ``; } } } diff --git a/src/__tests__/fixtures/basic-template-plugin-custom-runtime-id/__snapshots__/webpack5/server--main.js b/src/__tests__/fixtures/basic-template-plugin-custom-runtime-id/__snapshots__/webpack5/server--main.js index 209b9ba..06b1485 100644 --- a/src/__tests__/fixtures/basic-template-plugin-custom-runtime-id/__snapshots__/webpack5/server--main.js +++ b/src/__tests__/fixtures/basic-template-plugin-custom-runtime-id/__snapshots__/webpack5/server--main.js @@ -66,6 +66,7 @@ const _marko_template = (0,marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_0__. +const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin"; function renderAssets(out) { const entries = this.___entries; @@ -87,7 +88,7 @@ function renderAssets(out) { for (const href of assets.js) { if (!written.has(href)) { written.add(href); - scripts += ``; + scripts += ``; } } } diff --git a/src/__tests__/fixtures/basic-template-plugin-production/__snapshots__/webpack4/server--main.js b/src/__tests__/fixtures/basic-template-plugin-production/__snapshots__/webpack4/server--main.js index 066c99d..fb30a65 100644 --- a/src/__tests__/fixtures/basic-template-plugin-production/__snapshots__/webpack4/server--main.js +++ b/src/__tests__/fixtures/basic-template-plugin-production/__snapshots__/webpack4/server--main.js @@ -1 +1 @@ -!function(e){var t={};function r(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,r),s.l=!0,s.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)r.d(n,s,function(t){return e[t]}.bind(null,s));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=6)}([function(e,t){e.exports=require("marko/dist/runtime/helpers/render-tag")},function(e,t){e.exports=require("marko/dist/runtime/html")},function(e,t){e.exports=require("marko/dist/runtime/components/renderer")},function(e,t){e.exports=require("marko/dist/core-tags/core/__flush_here_and_after__.js")},function(e,t){e.exports=require("marko/dist/core-tags/components/init-components-tag.js")},function(e,t){e.exports=require("marko/dist/core-tags/core/await/reorderer-renderer.js")},function(e,t,r){const n=r(7),s=r(8);n.createServer((e,t)=>{s.render({},t)}).listen(0)},function(e,t){e.exports=require("http")},function(e,t,r){"use strict";r.r(t);var n=r(1),s=r(2),o=r.n(s);const i=Object(n.t)();var c=i;i._=o()((function(e,t,r,n,s){t.w("

Hello World

")}),{t:"7Fk+kAfP",i:!0},{});var u={getAssets(e){return this.build[e]},build:{"test_7Fk-":{js:["test_7Fk-.js"]}}},f=r(3),a=r.n(f),l=r(0),_=r.n(l),d=r(4),p=r.n(d),b=r(5),g=r.n(b);const m=Object(n.t)();t.default=m;function h(e){const t=this.___entries;if(this.___entries=void 0,t){r.p&&e.script("$mwp="+JSON.stringify(r.p));const n=this.buildName,s=this.cspNonce,o=s?" nonce="+JSON.stringify(s):"",i=this.___writtenAssets||(this.___writtenAssets=new Set);let c="",f="";for(const e of t){const t=u.getAssets(e,n);if(t.js)for(const e of t.js)i.has(e)||(i.add(e),c+=``; + scripts += ``; } } } diff --git a/src/__tests__/fixtures/basic-template-plugin/__snapshots__/webpack5/server--main.js b/src/__tests__/fixtures/basic-template-plugin/__snapshots__/webpack5/server--main.js index b6504ff..a3569a1 100644 --- a/src/__tests__/fixtures/basic-template-plugin/__snapshots__/webpack5/server--main.js +++ b/src/__tests__/fixtures/basic-template-plugin/__snapshots__/webpack5/server--main.js @@ -66,6 +66,7 @@ const _marko_template = (0,marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_0__. +const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin"; function renderAssets(out) { const entries = this.___entries; @@ -87,7 +88,7 @@ function renderAssets(out) { for (const href of assets.js) { if (!written.has(href)) { written.add(href); - scripts += ``; + scripts += ``; } } } diff --git a/src/__tests__/fixtures/multiple-entries-plugin/__snapshots__/webpack4/server--main.js b/src/__tests__/fixtures/multiple-entries-plugin/__snapshots__/webpack4/server--main.js index 99b9bb3..76b9d56 100644 --- a/src/__tests__/fixtures/multiple-entries-plugin/__snapshots__/webpack4/server--main.js +++ b/src/__tests__/fixtures/multiple-entries-plugin/__snapshots__/webpack4/server--main.js @@ -154,6 +154,7 @@ const _marko_template = Object(marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_ +const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin"; function renderAssets(out) { const entries = this.___entries; @@ -175,7 +176,7 @@ function renderAssets(out) { for (const href of assets.js) { if (!written.has(href)) { written.add(href); - scripts += ``; + scripts += ``; } } } @@ -321,6 +322,7 @@ const _marko_template = Object(marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_ +const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin"; function renderAssets(out) { const entries = this.___entries; @@ -342,7 +344,7 @@ function renderAssets(out) { for (const href of assets.js) { if (!written.has(href)) { written.add(href); - scripts += ``; + scripts += ``; } } } @@ -458,6 +460,7 @@ const _marko_template = Object(marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_ +const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin"; function renderAssets(out) { const entries = this.___entries; @@ -479,7 +482,7 @@ function renderAssets(out) { for (const href of assets.js) { if (!written.has(href)) { written.add(href); - scripts += ``; + scripts += ``; } } } diff --git a/src/__tests__/fixtures/multiple-entries-plugin/__snapshots__/webpack5/server--main.js b/src/__tests__/fixtures/multiple-entries-plugin/__snapshots__/webpack5/server--main.js index 0be01d4..c02db43 100644 --- a/src/__tests__/fixtures/multiple-entries-plugin/__snapshots__/webpack5/server--main.js +++ b/src/__tests__/fixtures/multiple-entries-plugin/__snapshots__/webpack5/server--main.js @@ -73,6 +73,7 @@ const _marko_template = (0,marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_0__. +const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin"; function renderAssets(out) { const entries = this.___entries; @@ -94,7 +95,7 @@ function renderAssets(out) { for (const href of assets.js) { if (!written.has(href)) { written.add(href); - scripts += ``; + scripts += ``; } } } @@ -247,6 +248,7 @@ const _marko_template = (0,marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_0__. +const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin"; function renderAssets(out) { const entries = this.___entries; @@ -268,7 +270,7 @@ function renderAssets(out) { for (const href of assets.js) { if (!written.has(href)) { written.add(href); - scripts += ``; + scripts += ``; } } } @@ -389,6 +391,7 @@ const _marko_template = (0,marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_0__. +const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin"; function renderAssets(out) { const entries = this.___entries; @@ -410,7 +413,7 @@ function renderAssets(out) { for (const href of assets.js) { if (!written.has(href)) { written.add(href); - scripts += ``; + scripts += ``; } } } diff --git a/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/webpack4/server--main.js b/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/webpack4/server--main.js index 1c85f1d..9e10740 100644 --- a/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/webpack4/server--main.js +++ b/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/webpack4/server--main.js @@ -207,6 +207,7 @@ const _marko_template = Object(marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_ +const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin"; function renderAssets(out) { const entries = this.___entries; @@ -228,7 +229,7 @@ function renderAssets(out) { for (const href of assets.js) { if (!written.has(href)) { written.add(href); - scripts += ``; + scripts += ``; } } } diff --git a/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/webpack5/server--main.js b/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/webpack5/server--main.js index 87692c9..fd2cce6 100644 --- a/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/webpack5/server--main.js +++ b/src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/__snapshots__/webpack5/server--main.js @@ -109,6 +109,7 @@ const _marko_template = (0,marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_0__. +const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin"; function renderAssets(out) { const entries = this.___entries; @@ -130,7 +131,7 @@ function renderAssets(out) { for (const href of assets.js) { if (!written.has(href)) { written.add(href); - scripts += ``; + scripts += ``; } } } diff --git a/src/__tests__/fixtures/with-class-component-plugin/__snapshots__/webpack4/server--main.js b/src/__tests__/fixtures/with-class-component-plugin/__snapshots__/webpack4/server--main.js index 57c5cb1..11206f9 100644 --- a/src/__tests__/fixtures/with-class-component-plugin/__snapshots__/webpack4/server--main.js +++ b/src/__tests__/fixtures/with-class-component-plugin/__snapshots__/webpack4/server--main.js @@ -205,6 +205,7 @@ const _marko_template = Object(marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_ +const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin"; function renderAssets(out) { const entries = this.___entries; @@ -226,7 +227,7 @@ function renderAssets(out) { for (const href of assets.js) { if (!written.has(href)) { written.add(href); - scripts += ``; + scripts += ``; } } } diff --git a/src/__tests__/fixtures/with-class-component-plugin/__snapshots__/webpack5/server--main.js b/src/__tests__/fixtures/with-class-component-plugin/__snapshots__/webpack5/server--main.js index 2fd4ed3..d98ef94 100644 --- a/src/__tests__/fixtures/with-class-component-plugin/__snapshots__/webpack5/server--main.js +++ b/src/__tests__/fixtures/with-class-component-plugin/__snapshots__/webpack5/server--main.js @@ -107,6 +107,7 @@ const _marko_template = (0,marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_0__. +const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin"; function renderAssets(out) { const entries = this.___entries; @@ -128,7 +129,7 @@ function renderAssets(out) { for (const href of assets.js) { if (!written.has(href)) { written.add(href); - scripts += ``; + scripts += ``; } } } diff --git a/src/__tests__/fixtures/with-public-path/__snapshots__/webpack4/server--main.js b/src/__tests__/fixtures/with-public-path/__snapshots__/webpack4/server--main.js index 7195640..63f8d6c 100644 --- a/src/__tests__/fixtures/with-public-path/__snapshots__/webpack4/server--main.js +++ b/src/__tests__/fixtures/with-public-path/__snapshots__/webpack4/server--main.js @@ -166,6 +166,7 @@ const _marko_template = Object(marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_ +const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin"; function renderAssets(out) { const entries = this.___entries; @@ -186,7 +187,7 @@ function renderAssets(out) { for (const href of assets.js) { if (!written.has(href)) { written.add(href); - scripts += ``; + scripts += ``; } } } diff --git a/src/__tests__/fixtures/with-public-path/__snapshots__/webpack5/server--main.js b/src/__tests__/fixtures/with-public-path/__snapshots__/webpack5/server--main.js index 1959c03..237c423 100644 --- a/src/__tests__/fixtures/with-public-path/__snapshots__/webpack5/server--main.js +++ b/src/__tests__/fixtures/with-public-path/__snapshots__/webpack5/server--main.js @@ -66,6 +66,7 @@ const _marko_template = (0,marko_dist_runtime_html__WEBPACK_IMPORTED_MODULE_0__. +const crossOriginAttr = new URL(__webpack_require__.p, "file:").protocol === "file:" ? "" : " crossorigin"; function renderAssets(out) { const entries = this.___entries; @@ -86,7 +87,7 @@ function renderAssets(out) { for (const href of assets.js) { if (!written.has(href)) { written.add(href); - scripts += ``; + scripts += ``; } } } diff --git a/src/__tests__/main.ts b/src/__tests__/main.ts index a2fbaa3..5e8ea86 100644 --- a/src/__tests__/main.ts +++ b/src/__tests__/main.ts @@ -12,7 +12,7 @@ const srcDir = path.dirname(__dirname); const fixturesDir = path.join(__dirname, "fixtures"); const fixtures = fs.readdirSync(fixturesDir); const srcDirReg = new RegExp( - [srcDir, srcDir.slice(srcDir.indexOf(path.sep)).replace(/[/\\/_.]+/g, "_")] + [srcDir, srcDir.slice(srcDir.indexOf(path.sep)).replace(/[/\\_.-]+/g, "_")] .map(escapeStringRegexp) .join("|"), "gi" diff --git a/src/loader/get-asset-code.ts b/src/loader/get-asset-code.ts index 7d3a352..3e58e21 100644 --- a/src/loader/get-asset-code.ts +++ b/src/loader/get-asset-code.ts @@ -12,6 +12,8 @@ import template from ${templatePath}; import manifest from "!!@marko/webpack/loader!?manifest"; export * from ${templatePath}; +// Check if public path is relative, if not we'll set the crossorigin attribute on scripts. +static const crossOriginAttr = new URL(__webpack_public_path__, "file:").protocol === "file:" ? "" : " crossorigin"; static function renderAssets(out) { const entries = this.___entries; this.___entries = undefined; @@ -39,7 +41,7 @@ static function renderAssets(out) { for (const href of assets.js) { if (!written.has(href)) { written.add(href); - scripts += \`\`; + scripts += \`\`; } } }