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

What is the architecture needed to achieve steps 8—Optimizing common code. #39

Closed
chemoish opened this issue Aug 10, 2015 · 1 comment

Comments

@chemoish
Copy link

It does not seem like a bundle can be loaded lazily or otherwise (So I am not sure how you would load Profile/Feed).

How does one achieve loading multiple entry points over some router?

// webpack.config.js

var webpack = require('webpack');

var commonsPlugin =
  new webpack.optimize.CommonsChunkPlugin('common.js');

module.exports = {
  entry: {
    Profile: './profile.js', // go to profile page—load Profile
    Feed: './feed.js' // go to feed page—load Feed
  },
  output: {
    path: 'build',
    filename: '[name].js' // Template based on keys in entry above
  },
  plugins: [commonsPlugin]
};
@chemoish
Copy link
Author

Maybe someone from the future will needs this. So here we are.


Not exactly sure if this is optimal, but it seems to be working.

Define multiple entry points.

entry: {
    app: './src/app.js',

    pageHome: './src/components/home/Home.js',
    pageSetting: './src/components/setting/Setting.js'
}

Define the common chunk plugin to look at your end points.

plugins: [
    new webpack.optimize.CommonsChunkPlugin('common.js', [
        'app',
        'pageHome',
        'pageSetting'
    ], 2)
]

Utilize react-router and react-router-proxy-loader… (Not sure if this works with bundle-loader alone).

https://github.com/rackt/react-router/blob/0.13.x/docs/guides/overview.md
https://github.com/odysseyscience/react-router-proxy-loader

<Route path="/" handler={App}>
    <DefaultRoute handler={require('react-router-proxy!./components/home/Home.js')}></DefaultRoute>

    <Route name="home" handler={require('react-router-proxy!./components/home/Home.js')}></Route>
    <Route name="setting" path="settings" handler={require('react-router-proxy!./components/setting/Setting.js')}></Route>
</Route>

Success?

Success Kid

  1. Pages will be loaded with only the dependencies they require.
  2. Any common related code will be extracted and placed into common.js.
  3. Seems to work with react-hot, babel-loader, file-loader, style-loader, etc.

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

No branches or pull requests

1 participant