0

I am trying to dynamically load a module depending on the sub-class' class name. The code could be seen here:

const name = this.constructor.name;
import(
  `../../src/components/${name}/View/${name}.js`).then((module) => {
});

I am using a mixin with is extended by a sub-class. The mixin resides in node_modules.

Assuming the sub-class resides in ./src/components/ExampleComponent Is there any way to infer the sub-class' directory from the mixin?

Is there anyway to infer the project root?

Using webpack, webpack is unable to find the template ExampleComponent/View/ExampleComponent unless the mixin resides inside of the project root.

Thanks for your help.

  • May you share the code you’re using? – evolutionxbox Oct 13 '18 at 19:00
  • You should be able to find it at: https://raw.githubusercontent.com/anoblet/RenderTemplate/master/RenderTemplate.js – Andrew Noblet Oct 14 '18 at 23:42
  • Keep the link, but to be fair to future users put any relevant code in a [mcve] in the question. – evolutionxbox Oct 15 '18 at 08:55
  • Are you using Babel to enable dynamic imports? – Keir Oct 15 '18 at 16:55
  • The mixin should not need to care about the class that extends it at all. Why do you think you need that path in the first place? – Bergi Oct 15 '18 at 18:35
  • Edited the original post to add the code that I have. I am not using Babel, but I am using Webpack. The reason why I need the sub-class is because a 'view' is being loaded from inside of the sub-class directory. The code get's loaded into Webpack but on the frontend it requests 'e/View/e.js'. – Andrew Noblet Oct 29 '18 at 23:22

0 Answers0