Skip to content

D[0] docs(config): Example 3 - custom vendor chunks using RegEx #2518

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

Merged
merged 13 commits into from
Sep 18, 2018

Conversation

sakhisheikh
Copy link
Member

@sakhisheikh sakhisheikh commented Sep 15, 2018

What kind of change does this PR introduce?
An example added to SplitChunksPlugin in split-chunks-plugin.md

Did you add tests for your changes?

Not necessary.

Does this PR introduce a breaking change?

No breaking change.

What needs to be documented once your changes are merged?

No update required.

When we have to split chunks on vendor basis we write test function in splitChunks.cacheGroups.test. I have added an example which demonstrate how we can use RegEx pattern to extract custom node_modules in vendor chunk.

For this I have gone through SplitChunksPlugin.js from webpack/lib/optimize/. I have tried so many times to extract only react and react-dom at the first place with exact string matching pattern. But I failed to do this as soon as I figured it out while printing module.nameForCondition()) and got to know how modules are added in vendor chunks with RegEx test. I added '/' in the end of library name just to make sure it extracts all code under hood of the library.

@sakhisheikh sakhisheikh changed the title docs(config): Example 3 - custom vendor chunks using RegEx D[0] docs(config): Example 3 - custom vendor chunks using RegEx Sep 15, 2018

### Split Chunks: Example 3

Create a `custom vendors` chunk, which includes only those `node_modules` from the whole application which passes the RegEx Test
Copy link
Member

Choose a reason for hiding this comment

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

I think this can be slightly reworded to something like:
Create a custom vendor chunk, which contains certain node_modules packages matched by RegExp.

};
```

T> This will result into a vendor chunk containing desired libraries provided in RegEx pattern. A better understanding of chunks can be visualized by [webpack-visualizer](https://chrisbateman.github.io/webpack-visualizer/).
Copy link
Member

Choose a reason for hiding this comment

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

Not sure we need to promote webpack-visualizer here as there might be more appropriate places in docs. Instead, we might wanna say:
This will result in splitting react and react-dom into a separate chunk.

Copy link
Member Author

@sakhisheikh sakhisheikh Sep 17, 2018

Choose a reason for hiding this comment

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

@byzyk Thanks for the needful input. I'll make recommended changes. I have one concern here sometimes users aren't sure if they custom vendor actually contains only those libraries in RegEx so they can verify it with weback visualizer. Anyways, I'm taking your feedback and making changes in the PR. If you say, I can remove webpack-visualizer tip from here

Copy link
Member Author

Choose a reason for hiding this comment

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

I have pushed the latest changes.

Copy link
Member

Choose a reason for hiding this comment

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

This plugin is already mentioned in docs, so if you feel like we need to add a note about that here you can just reference the links I shared, saying something like:

If you're not sure what packages have been included in a chunk you may refer to Bundle Analysis section(link) for details.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @byzyk added requested changes.

@@ -369,4 +369,4 @@ module.exports = {
};
```

T> This will result in splitting `react` and `react-dom` into a separate chunk.
T> This will result in splitting `react` and `react-dom` into a separate chunk. If you're not sure what packages have been included in a chunk you may refer to [Bundle Analysis](https://webpack.js.org/guides/code-splitting/#bundle-analysis) section for details.
Copy link
Member

Choose a reason for hiding this comment

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

Please use relative URLs /guides/code-splitting/#bundle-analysis

Copy link
Member Author

Choose a reason for hiding this comment

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

@montogeek pushed the requested changes. Thanks

Copy link
Member

@montogeek montogeek left a comment

Choose a reason for hiding this comment

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

Please see comment

Copy link
Member

@EugeneHlushko EugeneHlushko left a comment

Choose a reason for hiding this comment

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

more examples, good

@montogeek montogeek merged commit 9e959d2 into webpack:master Sep 18, 2018
@montogeek
Copy link
Member

Thanks!

montogeek pushed a commit that referenced this pull request Sep 27, 2018
* fix(contribute) Use consistent plugin name in code snippet (#2496)

* fix(configuration) Fix small typo (#2511)

* docs(manifest) Corrections and small update to concept manifest page (#2504)

Small updates and corrections for manifest concepts page

* docs(concepts) Update dependency graph concepts page (#2495)

* docs(concepts) Update dependency graph concepts page

* docs(concepts) Dependency graph minor tweak

* docs(concepts) Use common formatting, provide more links, mention mod… (#2472)

* docs(concepts) use common formatting, provide more links, mention mode in core of the concepts

* docs(concepts) duplicate links on the list for better ux

* docs(concepts) forgot to add EugeneHlushko to contributors

* docs(configuration) Add externals examples (#2515)

Update the external docs with an example on how to combine the different syntaxes. 

I felt it was not clear how to achieve this from the existing docs.

* docs(plugins) Update Writing plugin and Plugin pattern page (#2200)

* Update Writing plugin and Plugin pattern page

* Fixed formatting issues

* Fix markdown lint issues

* Update plugin-patterns.md

* Update plugin-patterns.md

* docs(concepts) Using vendors as entry is not recommended (#2525)

* Using vendors as entry is not recommended

fixes webpack/webpack#6647

* add note about vendor entrypoints

* fix(guides) Correct misspelling and punctuation errors (#2513)

* Correct misspelling and punctuation errors

* Update build-performance.md

* docs(plugins): Add custom vendor chunks using RegEx example (#2518)

* docs(config): Example 3 - custom vendor chunk using RegEx

* docs(config): Example 3 SplitChunks Fenced blank added

* docs(config): (typo) Example 3 - custom vendor chunk using RegEx

* sakhisheikh
docs(config): (reworded) Example 3 - custom vendor chunk using RegEx

* docs(config): (Reword) Example 3 - custom vendor chunk using RegEx

* docs(config): (Reword) Example 3 - custom vendor chunk using RegEx

* chore(plugins) Remove space  (#2527)

* docs(config): Example 3 - custom vendor chunk using RegEx

* squashed everything after c81e77e

* docs(plugins) Add .mjs to the defaults (#2493)

This should be updated once webpack/webpack#7947 is released.

* chore(plugins) Minor SplitChunks Documentation Clean Up (#2252)

* Minor Documentation Clean Up

Originally, i was just trying to change defer => differ, but I ended up doing a bit more editing.

* Lower the case

* fix(api) Clarify module section (#2529)

Change wording from "bind an extension" to "bind a file extension" in order to distinguish from a webpack extension.

_describe your changes..._

- [ ] Read and sign the [CLA][1]. PRs that haven't signed it won't be accepted.
- [ ] Make sure your PR complies with the [writer's guide][2].
- [ ] Review the diff carefully as sometimes this can reveal issues.
- __Remove these instructions from your PR as they are for your eyes only.__


[1]: https://cla.js.foundation/webpack/webpack.js.org
[2]: https://webpack.js.org/writers-guide/

* docs(plugins): Update links in htmlwebpackplugin (#2530)

* docs(plugins) Fix reuseExistingChunk title nesting (#2526)

* docs(plugins) scp reuseExistingChunk title  nesting fix

* docs(plugins) scp reuseExistingChunk title notation

* docs(guides) Fix typo (#2537)

* chore(guides) Import needs to be highlighted with '+' mark (#2536)

import webpack needs to be highlighted since we are adding webpack.HashedModuleIdsPlugin()

* docs(config) Optimization moduleIds option (#2543)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants