Skip to content

Commit

Permalink
fix: optimize component registration for top level stateful components (
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Mar 17, 2020
1 parent 18f72b4 commit 4d1787b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ marko_template.Component = marko_defineComponent(marko_component, marko_template
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {


const { register } = __webpack_require__(/*! marko/components */ "marko/components");
const component = __webpack_require__(/*! ./index.marko */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/index.marko");
register("/@marko/webpack-tests$x.x.x/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/index.marko", component);

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

/***/ }),
Expand Down Expand Up @@ -109,17 +105,6 @@ __webpack_require__(/*! ./components/nested/index.marko?dependencies */ "./src/_



/***/ }),

/***/ "marko/components":
/*!***********************************!*\
!*** external "marko/components" ***!
\***********************************/
/*! no static exports found */
/***/ (function(module, exports) {

module.exports = marko/components;

/***/ }),

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


const { register } = __webpack_require__(/*! marko/components */ "marko/components");
const component = __webpack_require__(/*! ./index.marko */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/index.marko");
register("/@marko/webpack-tests$x.x.x/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/index.marko", component);

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

/***/ }),
Expand Down Expand Up @@ -109,17 +105,6 @@ __webpack_require__(/*! ./components/nested/index.marko?dependencies */ "./src/_



/***/ }),

/***/ "marko/components":
/*!***********************************!*\
!*** external "marko/components" ***!
\***********************************/
/*! no static exports found */
/***/ (function(module, exports) {

module.exports = marko/components;

/***/ }),

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


const { register } = __webpack_require__(/*! marko/components */ "marko/components");
const component = __webpack_require__(/*! ./index.marko */ "./src/__tests__/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/index.marko");
register("/@marko/webpack-tests$x.x.x/fixtures/with-class-component-plugin-dynamic-bundle/components/nested/index.marko", component);

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

/***/ }),
Expand Down Expand Up @@ -109,17 +105,6 @@ __webpack_require__(/*! ./components/nested/index.marko?dependencies */ "./src/_



/***/ }),

/***/ "marko/components":
/*!***********************************!*\
!*** external "marko/components" ***!
\***********************************/
/*! no static exports found */
/***/ (function(module, exports) {

module.exports = marko/components;

/***/ }),

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


const { register } = __webpack_require__(/*! marko/components */ "marko/components");
const component = __webpack_require__(/*! ./index.marko */ "./src/__tests__/fixtures/with-class-component-plugin/components/nested/index.marko");
register("/@marko/webpack-tests$x.x.x/fixtures/with-class-component-plugin/components/nested/index.marko", component);

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

/***/ }),
Expand Down Expand Up @@ -107,17 +103,6 @@ __webpack_require__(/*! ./components/nested/index.marko?dependencies */ "./src/_



/***/ }),

/***/ "marko/components":
/*!***********************************!*\
!*** external "marko/components" ***!
\***********************************/
/*! no static exports found */
/***/ (function(module, exports) {

module.exports = marko/components;

/***/ }),

/***/ "marko/dist/runtime/components/defineComponent":
Expand Down
19 changes: 13 additions & 6 deletions src/loader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export default function(source: string): string {
babelConfig.caller
);

const dependenciesOnly = this.resource.endsWith("?dependencies");
const hydrate = this.resource.endsWith("?hydrate");
const assets = this.resource.endsWith("?assets");
let sourceMaps =
Expand Down Expand Up @@ -163,14 +162,22 @@ export default function(source: string): string {
this.addDependency(dep)
);

const dependenciesOnly = this.resource.endsWith("?dependencies");
let dependencies = [];

if (dependenciesOnly && meta.component) {
dependencies = dependencies.concat(`
${loadStr("marko/components", "{ register }")}
${loadStr(meta.component, "component")}
register(${JSON.stringify(meta.id)}, component);
`);
if (
path.join(path.dirname(this.resourcePath), meta.component) ===
this.resourcePath
) {
dependencies.push(loadStr(meta.component));
} else {
dependencies = dependencies.concat(`
${loadStr("marko/components", "{ register }")}
${loadStr(meta.component, "component")}
register(${JSON.stringify(meta.id)}, component);
`);
}
}

if (meta.deps) {
Expand Down

0 comments on commit 4d1787b

Please sign in to comment.