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

Webpack: Set an alias to vendor dependencies and add vendor chunk #164

Closed
Restuta opened this issue Jul 25, 2016 · 6 comments
Closed

Webpack: Set an alias to vendor dependencies and add vendor chunk #164

Restuta opened this issue Jul 25, 2016 · 6 comments

Comments

@Restuta
Copy link

Restuta commented Jul 25, 2016

Want to discuss this before opening a PR, since I am not sure my vision is aligned with the philosophy of the project.

In short, setting 'react' and 'react-dom' as webpack's resolve:alias can visibly improve dev-rebuild time since it will be using pre-built dependencies.

  1. This can de done by setting an alias to pre-built react and react-dom in dev config + alias to .min version in prod.

  2. (optional) Define a vendor chunk and specify react and react-dom there also.

I guess, only first option improves build times, not sure of the built impact of the other one, but having two default chunks may teach beginners one of the common approaches, since I assume that a lot of learning will be done by reverse engineering webpack's config after eject. And by setting a standard for managing pre-compiled dependencies, beginners may be able to avoid long-term frustration with slow rebuilds that, subjectively, tend to add up really fast. (it seems ember-cli is taking this approach by default, but their philosophy is different)

Also am aware that there is DllPlugin approach, but not sure if there are any drawbacks for maintainers long-term and it may not be as easy to gasp by beginners as in mentioned above scenario.

@gaearon
Copy link
Contributor

gaearon commented Jul 25, 2016

How does this play with npm addons? Like react-addons-perf. Is there a nice way to keep them working with resolve?

Generally I'm very much pro this idea, on both counts. We should use flat bundles if possible, and we should split React code into a separate chunk.

@Restuta
Copy link
Author

Restuta commented Jul 25, 2016

@gaearon I was able to make it work for my repo and ditched it back while ago, so need some refresh. It's not straightforward, but definitely possible.

@Restuta
Copy link
Author

Restuta commented Jul 25, 2016

I use this in prod and there is little caveat. Just setting alias won't improve performance, it also should be added to 'noParse' and to make it work with reactDom or Router imports loader has to be used:

    /* tells webpack to skip parsing following libraries
     requires use of "import loader" for certain modules, based on https://github.com/christianalfoni/react-webpack-cookbook/issues/30
    */
    noParse: [ pathToReact, pathToReactDom, pathToReactRouter ], 
    loaders: [{
      test: pathToReactDOM,
      loader: 'imports'
    }, {
      test: pathToReactRouter,
      loader: 'imports'
    }, {....

So I assume same approach is good for addons.

@gaearon
Copy link
Contributor

gaearon commented Jul 25, 2016

The problem is that modules like react-addons-perf reach into React, importing things like react/lib/ReactPerf. This will change in the future, but for now this means that we need to somehow alias react/lib/ReactPerf and friends to refer to the correct thing (e.g. React.addons.ReactPerf in UMD addons build).

@Restuta
Copy link
Author

Restuta commented Jul 25, 2016

@gaearon I will take a look and do it as part of the upcoming PR.

@gaearon
Copy link
Contributor

gaearon commented Sep 3, 2016

We will likely do this as part of #210 whenever that effort is revived.

@gaearon gaearon closed this as completed Sep 3, 2016
@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants