Skip to content
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

Export catalog components to be able to reuse them #1245

Closed
Spielboerg opened this issue Nov 30, 2021 · 4 comments
Closed

Export catalog components to be able to reuse them #1245

Spielboerg opened this issue Nov 30, 2021 · 4 comments

Comments

@Spielboerg
Copy link
Contributor

Is your feature request related to a problem? Please describe.
We would like to reuse your components from the CatalogModule (for example, the ProductAssetsComponent) in our own plugins. Currently, we have to copy all the component code into new files to use it in our plugin. It would be nice if instead we could just import the CatalogModule into the plugin's module and then use your existing components.

Describe the solution you'd like
Add all components declared in the CatalogModule to the exports array.

Describe alternatives you've considered
Currently, we copy the required components and import them into the plugin module. Of course, this leads to larger app bundles, which we would like to avoid.

@michaelbromley
Copy link
Member

Hi,

have you tried importing the components into your module's declarations array directly from @vendure/admin-ui/catalog? Or does Angular not allow that?

@Spielboerg
Copy link
Contributor Author

Hi,

in general, Angular does not allow you to declare a component in more than one module. For example, if you want to use component "A" in multiple components (each declared in a different module), you must create a module for component "A". This "A" module can then be imported into the modules of the components in which you want to use it. The "A" module then only needs to export the "A" component via the exports array. https://angular.io/guide/sharing-ngmodules

I still tried to declare the component in my module. This gives me a lot of other errors that have nothing to do with declaring it in 2 modules. The errors come from the fact that I would have to declare all components that are used within the components themselves. In the end, I would have to create a separate catalog module that does the same as yours, and even that wouldn't stop the app bundle from increasing in size, because of the duplicate declarations of the components.

It would be great if you could release a new npm package with a version of 1.3.5-alpha or so including the suggested change in CatalogModule, so I can try it out in my project and give you feedback here.

@michaelbromley
Copy link
Member

OK, thanks for the explanation.

I'll add this to the next release. If you like you can test locally by cloning this repo, making the change and building the admin-ui package and using the built package files in your node_modules - either copy paste them or use something like Verdaccio to install from a local npm server. But I think it is a pretty straightforward change.

@Spielboerg
Copy link
Contributor Author

I tested it locally with a modified build and it works fine :) see #1248 for the changes I made.

Because I stumbled across this bug while testing, I created another pull request: #1249

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants