nativescript-dev-webpack icon indicating copy to clipboard operation
nativescript-dev-webpack copied to clipboard

Lazy load dependencies from node_modules

Open rosen-vladimirov opened this issue 6 years ago • 0 comments

Is your feature request related to a problem? Please describe. vendor.js file contains all dependencies from node_modules. This makes the file really huge and slow for parsing during application startup. When there are lazy modules (in Angular application), it will be great in case we can place all the dependencies that are used in them, but not in the main module, in a separate file(s).

Describe the solution you'd like The main idea is during application startup to load only modules required for the main module. Everything required for lazy loaded modules, i.e. the actual code of the lazy loaded modules and the dependencies they are using, to be loaded at a later point.

Additional context I've thought about some ways to handle this and here are my suggestions:

  • Create a lazy_vendor.js and place all node_modules that are not used in the entry point inside it. This module will have to be "required" in all lazy routes.
  • In each lazy loaded module include all of the node_modules that it needs, this way some of the dependencies will be duplicated, which will probably cause other issues.
  • Create multiple vendor chunks based on the node_modules that are used in different lazy loaded modules. For example in case you have four lazy loaded modules - A, B, C and D and three of them require lodash and nativescript-facebook for example, create vendor_smth.js which includes lodash and nativescript-facebook. NOTE: This solutions seems error-prone and may lead to lot of vendor_ chunks created in the application.

rosen-vladimirov avatar Feb 20 '19 14:02 rosen-vladimirov