Skip to content

Commit

Permalink
fix: include runtimeId in dynamic public path var (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Mar 15, 2020
1 parent 6d117c9 commit d6751af
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/***/ (function(module, exports, __webpack_require__) {


if (window.$mwp) __webpack_require__.p = $mwp;
if (window.$mwp_testruntime) __webpack_require__.p = $mwp_testruntime;
__webpack_require__(/*! ./test.marko?dependencies */ "./src/__tests__/fixtures/basic-template-plugin-custom-runtime-id/test.marko?dependencies");

const { init } = __webpack_require__(/*! marko/components */ "marko/components");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function renderAssets() {
this.end = this.___end;

if (assets) {
__webpack_require__.p && this.script(`$mwp=${JSON.stringify(__webpack_require__.p)}`);
__webpack_require__.p && this.script(`$mwp_testruntime=${JSON.stringify(__webpack_require__.p)}`);

if (assets.js) {
const setNonce = nonce && `.setAttribute("nonce", ${JSON.stringify(nonce)})`;
Expand Down
10 changes: 8 additions & 2 deletions src/loader/get-asset-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ static function renderAssets() {
if (assets) {
${
publicPath === undefined
? "__webpack_public_path__ && this.script(`$mwp=${JSON.stringify(__webpack_public_path__)}`);"
? `__webpack_public_path__ && this.script(\`${
runtimeId ? `$mwp_${runtimeId}` : "$mwp"
}=\${JSON.stringify(__webpack_public_path__)}\`);`
: ""
}
Expand Down Expand Up @@ -55,7 +57,11 @@ static function outEndOverride(data, encoding, callback) {
this.end(data, encoding, callback);
}
${runtimeId === undefined ? "" : `$ out.global.runtimeId = ${runtimeId};`}
${
runtimeId === undefined
? ""
: `$ out.global.runtimeId = ${JSON.stringify(runtimeId)};`
}
$ out.___flush = out.flush;
$ out.___end = out.end;
$ out.___renderAssets = renderAssets;
Expand Down
9 changes: 7 additions & 2 deletions src/loader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,23 @@ export default function(source: string): string {
}
);
} else if (hydrate) {
let mwpVar = "$mwp";
if (runtimeId) {
mwpVar += `_${runtimeId}`;
}

return `
${
publicPath === undefined
? " if (window.$mwp) __webpack_public_path__ = $mwp;"
? ` if (window.${mwpVar}) __webpack_public_path__ = ${mwpVar};`
: ""
}
${loadStr(`./${path.basename(this.resourcePath)}?dependencies`)}
${
runtimeId
? `
${loadStr("marko/components", "{ init }")}
init(${runtimeId});
init(${JSON.stringify(runtimeId)});
`
: "window.$initComponents && $initComponents();"
}
Expand Down
5 changes: 1 addition & 4 deletions src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ export default class MarkoWebpackPlugin {
});

constructor(private options?: { runtimeId?: string }) {
this.options = { ...options };
if (this.options.runtimeId) {
this.options.runtimeId = JSON.stringify(options.runtimeId);
}
this.options = options;
}

// Overwritten by each compiler.
Expand Down

0 comments on commit d6751af

Please sign in to comment.