Skip to content

Commit

Permalink
fix: webpack incorrectly merging expressions in prod
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Aug 10, 2020
1 parent c9c4ff1 commit 61e4f76
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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");
uinit("testruntime");
init("testruntime");


/***/ }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

__webpack_require__(/*! ./components/shared.marko?dependencies */ "./src/__tests__/fixtures/multiple-entries-plugin/components/shared.marko?dependencies");
__webpack_require__(/*! ./components/shared.marko?dependencies */ "./src/__tests__/fixtures/multiple-entries-plugin/components/shared.marko?dependencies")

/***/ }),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

__webpack_require__(/*! ./components/shared.marko?dependencies */ "./src/__tests__/fixtures/multiple-entries-plugin/components/shared.marko?dependencies");
__webpack_require__(/*! ./components/shared.marko?dependencies */ "./src/__tests__/fixtures/multiple-entries-plugin/components/shared.marko?dependencies")

/***/ }),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ marko_template.Component = marko_defineComponent(marko_component, marko_template
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

__webpack_require__(/*! ./index.marko */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/index.marko");
__webpack_require__(/*! ./index.marko */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/index.marko")

/***/ }),

Expand Down Expand Up @@ -86,7 +86,7 @@ __webpack_require__(/*! ./index.marko */ "./src/__tests__/fixtures/with-class-co
/***/ (function(module, exports, __webpack_require__) {

__webpack_require__(/*! ./test.marko.css */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/test.marko.css");
__webpack_require__(/*! ./components/nested/index.marko?dependencies */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/index.marko?dependencies");
__webpack_require__(/*! ./components/nested/index.marko?dependencies */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/index.marko?dependencies")

/***/ }),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ marko_template.Component = marko_defineComponent(marko_component, marko_template
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

__webpack_require__(/*! ./index.marko */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/index.marko");
__webpack_require__(/*! ./index.marko */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/index.marko")

/***/ }),

Expand Down Expand Up @@ -86,7 +86,7 @@ __webpack_require__(/*! ./index.marko */ "./src/__tests__/fixtures/with-class-co
/***/ (function(module, exports, __webpack_require__) {

__webpack_require__(/*! ./test.marko.css */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/test.marko.css");
__webpack_require__(/*! ./components/nested/index.marko?dependencies */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/index.marko?dependencies");
__webpack_require__(/*! ./components/nested/index.marko?dependencies */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/index.marko?dependencies")

/***/ }),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ marko_template.Component = marko_defineComponent(marko_component, marko_template
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

__webpack_require__(/*! ./index.marko */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/index.marko");
__webpack_require__(/*! ./index.marko */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/index.marko")

/***/ }),

Expand Down Expand Up @@ -86,7 +86,7 @@ __webpack_require__(/*! ./index.marko */ "./src/__tests__/fixtures/with-class-co
/***/ (function(module, exports, __webpack_require__) {

__webpack_require__(/*! ./test.marko.css */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/test.marko.css");
__webpack_require__(/*! ./components/nested/index.marko?dependencies */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/index.marko?dependencies");
__webpack_require__(/*! ./components/nested/index.marko?dependencies */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/index.marko?dependencies")

/***/ }),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ marko_template.Component = marko_defineComponent(marko_component, marko_template
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

__webpack_require__(/*! ./index.marko */ "./src/__tests__/fixtures/with-class-component-plugin/components/nested/index.marko");
__webpack_require__(/*! ./index.marko */ "./src/__tests__/fixtures/with-class-component-plugin/components/nested/index.marko")

/***/ }),

Expand Down Expand Up @@ -84,7 +84,7 @@ __webpack_require__(/*! ./index.marko */ "./src/__tests__/fixtures/with-class-co
/***/ (function(module, exports, __webpack_require__) {

__webpack_require__(/*! ./test.marko.css */ "./src/__tests__/fixtures/with-class-component-plugin/test.marko.css");
__webpack_require__(/*! ./components/nested/index.marko?dependencies */ "./src/__tests__/fixtures/with-class-component-plugin/components/nested/index.marko?dependencies");
__webpack_require__(/*! ./components/nested/index.marko?dependencies */ "./src/__tests__/fixtures/with-class-component-plugin/components/nested/index.marko?dependencies")

/***/ }),

Expand Down
25 changes: 13 additions & 12 deletions src/loader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ export default function(source: string): void | string | Buffer {
publicPath === undefined
? `if (window.${mwpVar}) __webpack_public_path__ = ${mwpVar};\n`
: ""
}${loadStr(`./${path.basename(this.resourcePath)}?dependencies`)}\n${
}${loadStr(`./${path.basename(this.resourcePath)}?dependencies`)};\n${
runtimeId
? `${loadStr("marko/components", "{ init }")}\nuinit(${JSON.stringify(
? `${loadStr("marko/components", "{ init }")};\ninit(${JSON.stringify(
runtimeId
)});`
: "window.$initComponents && $initComponents();"
Expand Down Expand Up @@ -203,13 +203,14 @@ export default function(source: string): void | string | Buffer {

if (dependenciesOnly) {
code = "";
map = undefined;

if (meta.component) {
// Register a split component.
dependencies = dependencies.concat(
dependencies.push(
loadStr("marko/components", "{ register }"),
loadStr(meta.component, "component"),
`register(${JSON.stringify(meta.id)}, component);`
`register(${JSON.stringify(meta.id)}, component)`
);
}

Expand Down Expand Up @@ -259,16 +260,16 @@ export default function(source: string): void | string | Buffer {
if (code) {
if (map) {
const concat = new ConcatMap(true, "", "\n");
concat.add(null, dependencies.join("\n"));
concat.add(null, dependencies.join(";\n"));
concat.add(this.resourcePath, code, map);
map = concat.sourceMap;
code = concat.content;
} else {
dependencies.push(code as string);
code = dependencies.join("\n");
code = dependencies.join(";\n");
}
} else {
code = dependencies.join("\n");
code = dependencies.join(";\n");
map = undefined;
}
}
Expand All @@ -292,7 +293,7 @@ function getMissingDepRequire(resource: string, meta): string | false {
const templateFileName = getBasenameWithoutExt(resource);
return `require.context(".", false, /\\${path.sep}${
templateFileName === "index" ? "" : `${templateFileName}\\.`
}(?:${missingDeps.join("|")})\\.[^\\${path.sep}]+$/);`;
}(?:${missingDeps.join("|")})\\.[^\\${path.sep}]+$/)`;
}

return false;
Expand Down Expand Up @@ -326,20 +327,20 @@ function importStr(request: string, lhs?: string) {
const id = JSON.stringify(request);

if (lhs) {
return `import ${lhs} from ${id};`;
return `import ${lhs} from ${id}`;
}

return `import ${id};`;
return `import ${id}`;
}

function requireStr(request: string, lhs?: string) {
const id = JSON.stringify(request);

if (lhs) {
return `const ${lhs} = require(${id});`;
return `const ${lhs} = require(${id})`;
}

return `require(${id});`;
return `require(${id})`;
}

function normalizeTarget(target: string): string {
Expand Down

0 comments on commit 61e4f76

Please sign in to comment.