-
Notifications
You must be signed in to change notification settings - Fork 12k
Tree-shaking for production environment drops component referred dynamically #2965
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
Comments
Production builds minify the javascript so you can't and shouldn't rely on the type name. Also, using a private member of ComponentFactoryResolver will more than likely cause problems in the future. For your use case (at least from what is described), using an ngSwitch in the template would probably be effective and cut down the complexity as well. |
This is the expected Angular behaviour. You need to add the components to Here's the FAQ for entry components: Relevant quotes from that page:
|
@clydin yes @Meligy regarding your suggestion |
The name gets mangled during minification; you can't rely on it. You'll either need to keep a lookup table to map names to types or use the ngSwitch method. |
dont understand this quite well (may be because am quite to new to webpack/angular world) hence not sure even if to consider this as a real issue or incorrect way of implementation. I've changed my implementation to have a internal mapping of name to component and moved forward. Anyway thanks for your input @clydin |
Well, I have bad news about this.
I expected my App to work, but nope. When I build it for production with:
My dynamic components are dropped by webpack, and I get the same error reported on this issue:
But I did:
then I load them with:
and the bundle for development works, Thanks in advance for any tip @filipesilva |
If 'this.state.component' is a string then my comment above applies: the names are mangled in production builds. Good practice is to not rely on them directly as this is intentional and desired; it reduces the deployed size and obfuscates the code. |
|
I'm using
results in |
Had the exact same issue with similar architecture and had to hack a fix to remove uglify plugin from the build which is a suboptimal measure. Definitely need a more permanent resolution on this as using dynamic components is crucial to many applications. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
OS?
Versions.
Repro steps.
The log given by the failure.
The text was updated successfully, but these errors were encountered: