Skip to content

Feature request: separate app and vendor bundles #1601

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

Closed
neo-sumeet opened this issue Aug 8, 2016 · 13 comments
Closed

Feature request: separate app and vendor bundles #1601

neo-sumeet opened this issue Aug 8, 2016 · 13 comments
Labels
feature Issue that requests a new feature

Comments

@neo-sumeet
Copy link

Is there any way to have angular cli webpack produce different minified js for third party and app libraries?

  1. Running on OSX El Capitan
  2. Versions. 6.2.2
  3. Repro steps. Created the project with angular-cli: 1.0.0-beta.11-webpack
@kylecordes
Copy link

kylecordes commented Aug 9, 2016

This is a good idea - also I have it listed in my ideas back on #987 which I plan to update once the web pack version ships. Fortunately many of the ideas from that item are already done, I think the one you described here is one of the few remaining to possibly get done in the future.

@TheLarkInn
Copy link
Member

We would gladly accept a well written proposal and PR on this feature. It has been highly requested, however not currently at the top of our priority list for the time being.

@filipesilva
Copy link
Contributor

Can you elaborate on what 'different minified js' means? Different how?

@filipesilva filipesilva added the needs: more info Reporter must clarify the issue label Aug 16, 2016
@kylecordes
Copy link

@filipesilva I think the original poster was asking that the build process emit something like a lib.HASHHERE.min.js file and an app.HASHHERE.min.js file; this is popular among traditional asset pipelines.

Although I wrote above that is a good idea, as I think about it I believe it is also unfortunately incompatible with the tree shaking approach; in theory every application and almost any change to any application will use a very slightly different subset of Angular or other libraries.

We could think of it as a spectrum of optimization:

  • On one end, we use off-the-shelf libraries completely unchanged, so utterly vanilla that they can be permanently cached and loaded from CDNs... This minimizes the application JavaScript size (if you don't count for libraries). If those libraries happen to already be in a user's cache, it also optimizes typical JavaScript loading size.
  • At the other end, tree shaking of the entire combined application plus all of its libraries. This makes no assumptions about what might already be in a user cache - and therefore, while it minimizes the total code in one sense, it also cannot benefit from any code having already been loaded by other websites into the user's browser in the past.

Angular CLI implements the second thing, not the first thing. My hunch is that this won't change, and this item could be closed as "good idea for some projects for some needs, but sorry not a fit for this project".

@filipesilva
Copy link
Contributor

@kylecordes thank you for explaining. I think I get it now. It hadn't occurred to me how tree shaking would affect this feature, but your considerations are spot on.

There was a point where we had a separate vendor.ts file where vendors were listed to be loaded separately, but we don't have it anymore in master. I think it's worth a discussion for now, so I'll change the title to something easier to understand.

@filipesilva filipesilva added feature Issue that requests a new feature type: discussion and removed needs: more info Reporter must clarify the issue labels Aug 22, 2016
@filipesilva filipesilva changed the title Is there any way to have angular cli webpack produce different minified js for third party and app libraries? Feature request: separate app and vendor bundles Aug 22, 2016
@wulfsberg
Copy link

Just pitching in 2 cents here: I suspect one of reasons this has been a highly requested feature is because the System.js dev build hits you with a download of literally a thousand separate files from the different Angular modules. This is a noticeable performance hit while continuously refreshing the page, and the obvious solution would seem to be to pre-package the unchanging angular/vendor modules.

The Webpack version circumvents this entirely with a different build sequence, eliminating this pain point. Without being a mind reader, I'd guess that this really serves the purpose for a pretty large number of the requests for this feature.

@sokolovstas
Copy link

This feature is needed for production build to support caching. If we have separate vendor bundle and it didn't change for months we can provide proper caching and speed up application loading. For example my vendor.bundle.js is 4mb, this is maybe not so much but it can save traffic and server loads.

@clydin
Copy link
Member

clydin commented Sep 7, 2016

If someone wanted to do this for their project, couldn't they add a vendor.ts file to apps[0].scripts?

@sokolovstas
Copy link

Just checked, this is works too, and for now I think this is the best option!

@SanderElias
Copy link

@kylecordes @filipesilva Also consider the difference between dev mode and production mode.
During dev, it's ok for me to create 1 large bundle out of all vendor files, and handle all the developers code as a separate bundle. This will will have large impact on performance during development. (My guess, quite a bit faster)

On production one might want to do a complete tree-shake. But as stated above, some might prefer to split it differently as their need is different.

@filipesilva
Copy link
Contributor

We now produce a vendor chunk by default, which can be disabled with --no-vendor-chunk.

@soates
Copy link

soates commented Jan 31, 2017

Is there a way to add libs to this vendor chunk? for example rxjs.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Issue that requests a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants