Support Relative Dynamic Imports
See original GitHub issueType of Issue
[ ] Bug Report
[X] Feature Request
Description
Currently when creating a dynamic import inside a library an error is thrown by rollup:
Invalid value for option "output.file" - when building multiple chunks, the "output.dir" option must be used, not "output.file". To inline dynamic imports, set the "inlineDynamicImports" option.
This prevents creating more optimized libraries.
I think that the reason behind this limitation was because of the view engine. Since that is gone, is there anything still holding us back?
Expected Behaviour
Additional chunks are created and no error is given.
Version Information
$ node_modules/.bin/ng-packagr --version
ng-packagr: 15.0.1
@angular/*: 15.0.1
typescript: 4.8.4
rxjs: 7.5.7
node: 18.12.0
npm: 9.2.0
Issue Analytics
- State:
- Created 9 months ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
JavaScript modules: dynamic import() - CanIUse
"Can I use" provides up-to-date browser support tables for support of front-end web ... Loading JavaScript modules dynamically using the import() syntax.
Read more >Correctly resolve dynamic chunk paths relative to the current ...
When dynamic imports ( import() ) the bundle should correctly load bundle chunks relative to the loading javascript file rather than the loaded ......
Read more >What are Dynamic Imports and how to use them? - Initialyze
Dynamic imports or Code Splitting is the practice of breaking up your JavaScript modules into smaller bundles and loading them dynamically ...
Read more >Dynamic imports + relative imports in Python 3 - Stack Overflow
I have a Python 3 project where I'm dynamically importing modules from ... the relative import occurs within a dynamically imported module.
Read more >Webpack and Dynamic Imports: Doing it Right - Medium
But for this article, I'm going to use the proposed ES2015 dynamic imports supported by Webpack, since the v2, through a babel plugin...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The unflattering version does have its drawbacks, it will increase the application build times, and in some cases it does result in larger bundle sizes
If you are seeing increases in bundle size when using FESMs, this typically indicates problems with the library architure and unrelated features into secondary entry-points. Which causes the unrelated code to be bundled in the same FESM.
At first I tried to follow that approach, placing every component in a entry point, but I realized that I would need a lot of entry points and that would make the library take minutes to compile… It becomes a hell to develop in that way. That being sad, I do use entry points but to separate unrelated parts of the library. I don’t think that the purpose of entry points should be to lazy load things or to optimize tree shaking… For me that’s more like an workaround to the current limitation. Entry points should be a way to well define the public API of the library. You need to be thinking on so many aspects to have the library full optimized that is almost impossible to make it right, unless as I sad, you create a entry point for every component which does not make sense…
I don’t understand why we can’t have relative dynamic imports and why we don’t use the “ESM2020” export as the default. I read this but I don’t understand what’s the problem…
Can there be an option to define what we want to be the default export? And opt out the rollup flattening?