salesforce / lwc-webpack-plugin

Plugin to use LWC within Webpack
https://lwc.dev
BSD 3-Clause "New" or "Revised" License
2 stars 4 forks source link

Namespacing of modules #37

Open HummerDK opened 8 months ago

HummerDK commented 8 months ago

Hi

I have a setup where I use storybook to showcase components. In order for me to be able to push the components directly to a Salesforce org they need to be present in the "force-app/main/default/lwc" folder. That means when I run my local server, the components is not registered under the namespace "c" as they are when deployed to Salesforce.

Would it be possible to include an option to define a namspace for each module definition like showcased below?

"modules": [ { "dir": "src/demoComponents" }, { "namespace": "c" "dir": "force-app/main/default/lwc" } ]

Best Rasmus

nolanlawson commented 8 months ago

Thanks for opening the issue. This package delegates module resolution to the @lwc/module-resolver package, which actually lives over in the lwc repo.

Could you explain more about the problem you're running into exactly? I don't quite understand the problem space or the solution you're proposing. Thanks!

HummerDK commented 8 months ago

When having a Salesforce project, LWC components must be placed in a folder structure like "force-app/main/default/lwc/". When these components is deployed to a Salesforce org, you must refer to the component like <c-component-name> So all components is given a prefix of "c".

In the same project structure, I am running LWC open source to do local development and showcasing of these components in Storybook. Since my components is placed in the given folder structure "force-app/main/default/lwc/", I am not able to refer to them, as on the Salesforce platform, using <c-component-name>.

I would like to override the prefix of the components names, when the module resolver pick up the components. Imagine that i could define a namespace like this is the lwc.config.json

{ "namespace": "c", "dir": "src/modules" },

It can be done on single components ( https://github.com/salesforce/lwc/tree/master/packages/%40lwc/module-resolver#alias-module-record), but i would like to do it for all components no matter what folder structure they are placed within

muenzpraeger commented 8 months ago

Something that I did in the past was just to symlink force-app/main-default/lwc to my-lwc-oss-folder/c, and the use that one for Storybook.

HummerDK commented 8 months ago

Something that I did in the past was just to symlink force-app/main-default/lwc to my-lwc-oss-folder/c, and the use that one for Storybook.

I agree that it could fix the problem, I just think it would be nicer if the module resolver would support this as configuration instead

muenzpraeger commented 8 months ago

Agreed. I did a quick search on GitHub and found a mod that actually provides what you're looking for.

https://github.com/lukethacoder/lwc-module-resolver

HummerDK commented 8 months ago

Agreed. I did a quick search on GitHub and found a mod that actually provides what you're looking for.

https://github.com/lukethacoder/lwc-module-resolver

Thanks for finding the fork from lukethacoder! I still hope they will consider to add the support in the original package :)

PTST commented 8 months ago

This would greatly help our LWC development process as well!