-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/cem module path as module path #163
base: main
Are you sure you want to change the base?
Feat/cem module path as module path #163
Conversation
- add additional component property modulePath which contains the path from the CEM. Signed-off-by: Tobias Kuppens Groot <[email protected]>
Signed-off-by: Tobias Kuppens Groot <[email protected]>
Unfortunately, that path reflects the component's In a situation like yours, I would recommend adding some logic to the modulePath: (className, tagName) => {
switch (tagName) {
case 'my-custom-tab':
case 'my-custom-tabs':
return `./tabs/${className}.js`;
case 'my-select':
case 'my-option':
return `./select/${className}.js`;
default:
return `./${tagName}/${className}.js`;
}
} |
indeed it's the source of the component, but as far as I know that is the path which is used by the return `
${config.ssrSafe ? '"use client"' : ""}
import React, { forwardRef, useImperativeHandle ${
useEffect ? ", useRef, useEffect" : ""
} ${config.scopedTags ? ", useContext" : ""} } from "react";
${!config.ssrSafe ? `import '${modulePath}';` : ""}
...
` the additional parameter for the |
I was thinking of similar solution as you proposed, but it just does not feel that clean to keep a map of all my components somewhere. In case something changes I have to update this as well and keep this web-component map in sync with my component sources. Somehow this ruins the automation of things a bit ;) |
You don't want the source path for the react wrappers. You want to reference where their final output is. Otherwise, the module will be missing in production. |
With final output you mean the path to the web-components. In my case, since I do not build my components, the source and output path are the same, which probably will be a specific circumstance you mentioned. Therefore it works when updating the Anyways, in my case that is a bit troublesome to not have access to the |
I really wish the manifest would define a source path, an output path, and a types path. That would make this tooling a lot easier. The nice thing is that if you are using any of my other tools, they follow the same pattern, so you could define this once and reuse it for all of them. |
With the
customElementReactWrapperPlugin
the configuration option provided by providing a custom modulePath with the given parameters is not sufficient for web-components and their generated wrappers. Namely, if components are grouped in a directory, likemyCustomTab
andmyCustomTabs
it can create the impossible challenge to useclassName
andtagName
to resolve the path to the correct component.consider the following structure for the custom-elements:
the output will be two components with the path
Even if you would configure the
modulePath
differently like${tagName.split('-').reverse()[0]}
you wouldn't get the desired outcome.CEM provides a path which is better suited to do some custom modulePath resolution:
This PR adds this functionality.