if we use a 3rd party component which comes with 20 features. but if we need only 2 features.
will in the final js file which will be downloaded in the user browser, code of all 20 features be download? assume webpack is being used
If 3rd party allows you to select features to include and build based on selected and required (for dependencies) components then it will serve only those else it will be whole bundle.
One of the technique you can use today called "Dynamic imports". It works beautifully with webpack, which automatically split your code, create chunks and dynamically load them on-demand.
Here is the example with vue component which will be loaded dynamically.
const Foo = () => import('./Foo.vue')
I believe you can use the same method to load 2 feature out of 20 feature library (as long as library has named exports)
Here is the example of that
var object = require('lodash/fp/object')
// OR in ES6 syntax
const object = () => import('load/fp/object')
I'm using this feature here in my code repository
github.com/techlab23/kanban-board-demo/blob/bulma…
Here is the demo (unfortunately codepen doesn't support webpack but it shows what i built)
codepen.io/nigamshirish/pen/XgqOVO (you can navigate to repos from the menu links as well)
Hope this helps.
Atul Sharma
Full Stack Developer | Cloud Native Applications
As already pointed out by Ravindra, it depends upon the third party module whether the module is exporting single object containing all components or exporting components individually. Also, you need to import only the components required instead of importing all components.
I'm not very much sure if web-pack by default can handle this or not. But, you can make web-pack to do so for sure.