Skip to content
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

[WIP] New vendor bundle block #188

Closed
wants to merge 2 commits into from
Closed

[WIP] New vendor bundle block #188

wants to merge 2 commits into from

Conversation

sapegin
Copy link
Collaborator

@sapegin sapegin commented Aug 9, 2017

No description provided.

@diegohaz
Copy link
Contributor

diegohaz commented Aug 9, 2017

Related: https://github.com/diegohaz/webpack-blocks-split-vendor

@sapegin
Copy link
Collaborator Author

sapegin commented Aug 9, 2017

@diegohaz I think both are useful because there are different: yours is more generic and mine is more automated.

@andywer What do you think? ;-)

@diegohaz
Copy link
Contributor

diegohaz commented Aug 9, 2017

I think both are (or could be) the same. I'm all for having an official block and deprecating mine.

I would just check if the problem I wrote there still persists: https://github.com/diegohaz/webpack-blocks-split-vendor#how-it-does (the reason I used webpack-md5-hash).


#### minChunks *(default: 5)*

Minimal number of chunks to include dependency into the bundle.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why wouldn't you want to include a dependency with few chunks into the vendor bundle?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because you may have some big dependencies that you’re using only on several pages, like some fancy chart library.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So my idea was to include dependencies that are used on most pages.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh, it's not about the size of the dependency, but how many chunks are using this dependency. I think the documentation should highlight that 😉

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that’s exactly what is says! ;-)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least I didn't get that it means "number of chunks using the dependency" and I am maintainer 😜

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I’ll update it ;-)

@andywer
Copy link
Owner

andywer commented Aug 9, 2017

I think the md5-hashing is just an alternative solution to what @sapegin implemented as runtimeBundle. Not sure what's better.

Thanks for pointing out your package, @diegohaz. I almost forgot about it.

I think the way this package (in this PR) works seems cleaner, but from a high-level view they do pretty much exactly the same, right?

@diegohaz
Copy link
Contributor

diegohaz commented Aug 9, 2017

What's runtimeBundle?

@sapegin
Copy link
Collaborator Author

sapegin commented Aug 9, 2017

I think the md5-hashing is just an alternative solution to what @sapegin implemented as runtimeBundle. Not sure what's better.

Yup, it’s solving the same problem. As I understand the benefit of md5-hashing is that you don’t have another bundle just for IDs.

What's runtimeBundle?

Here it is:

/**
 * Extract webpack runtime with module IDs so changes in app code won’t invalidate the vendor bundle.
 *
 * @returns {function}
 */
module.exports = function() {
    return (context, { addPlugin }) => addPlugin(
        new context.webpack.optimize.CommonsChunkPlugin({
            name: 'runtime',
            minChunks: Infinity,
        })
    );
};

@diegohaz
Copy link
Contributor

diegohaz commented Aug 9, 2017

I see now (didn't find it in the code though). That's pretty neat.

@sapegin sapegin changed the title New vendor bundle block [WIP] New vendor bundle block Aug 11, 2017
@andywer
Copy link
Owner

andywer commented Aug 29, 2017

We still need a decision on that, right?

@sapegin
Copy link
Collaborator Author

sapegin commented Aug 29, 2017

I want to make it more generic and support both use cases: my initial and from @diegohaz’s block so we could have one block “to rule them all” ;-)

@sapegin
Copy link
Collaborator Author

sapegin commented Sep 6, 2017

@marcofugaro
Copy link
Contributor

Whoa, good idea with this PR, vendor splitting is the most common and most reasonable code splitting.

I did this once to a big project to minimize dev build times, I also tried to implement the DllPlugin on the vendor chunk to basically freeze it and almost remove the compile times of that chunk, but I wasn't able to do it because of the too much overhead of that plugin, but maybe you guys can do it!

@sapegin
Copy link
Collaborator Author

sapegin commented Sep 18, 2017

@vlad-zhukov
Copy link
Collaborator

I'd like all options to be passed down to a CommonsChunkPlugin rather than a small whitelist.

@sapegin
Copy link
Collaborator Author

sapegin commented Sep 20, 2017

@vlad-zhukov Yeah, I’m going to make it more generic.

@andywer andywer changed the base branch from release/1.0 to master October 2, 2017 19:14
@dmitmel
Copy link
Contributor

dmitmel commented Mar 3, 2018

@sapegin The functionality of this block should be included in the @webpack-blocks/webpack package because:

  1. It's a core feature
  2. The block doesn't add new dependencies, it just uses CommonsChunkPlugin included with webpack

## Usage

```js
const { createConfig } = require('@webpack-blocks/webpack')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webpack-blocks/webpack re-exports createConfig from @webpack-blocks/core.


```js
const { createConfig } = require('@webpack-blocks/webpack')
const vendorBundle = require('@webpack-blocks/vendorBundle')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change @webpack-blocks/vendorBundle to @webpack-blocks/vendor-bundle. NPM doesn't support capital letters in the package names.

name: options.main,
filename: options.filename,
children: true,
minChunks ({ userRequest }, count) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resource is better than userRequest because it's more accurate.

filename: options.filename,
children: true,
minChunks ({ userRequest }, count) {
return userRequest && userRequest.includes('node_modules') &&
Copy link
Contributor

@dmitmel dmitmel Mar 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String#indexOf is faster than String#includes (see this benchmark).

"@webpack-blocks/core": "^1.0.0-beta",
"ava": "^0.18.2",
"standard": "^8.6.0",
"webpack": "^3.5.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webpack must be in peerDependencies because index.js imports it.

@marcofugaro
Copy link
Contributor

Just a reminder, webpack 4 splits vendors by defult, so this functionality will be already there when webpack-blocks is upgraded wo webpack 4

@sapegin
Copy link
Collaborator Author

sapegin commented Mar 3, 2018

This block doesn't make any sense in webpack 4, I'm going to close the PR.

@sapegin sapegin closed this Mar 3, 2018
@vlad-zhukov vlad-zhukov deleted the vendorbundle branch March 3, 2018 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants