Skip to content

Conversation

andresgutgon
Copy link

@andresgutgon andresgutgon commented Feb 4, 2017

What is this?

Hi, first of all thank you for your article I'm trying to follow because we want to accomplish these goals in our project:

The goals

  • Long term webpack caching
  • Code splitting by route

I took from your example and added some big guys like react, react-router or lodash...because, well. That's our real world 😄

The plan

I will explain how I would like to accomplish our goals:

  • Use webpack 2
  • Use yarn because is faster :)
  • Fill this repo with the big guys
  • Add Babel to use react more easily.
  • Split our code in 2 bundles. app and vendor
  • Understand how manifest work. To get long term cache
  • Implement code splitting by react-router routes and make it work with long term caching
  • Tree Shaking with webpack 2
  • Maybe something else...

Merge this PR with your code?

Maybe your intention is to keep the example simple. I want to make clear that I'm not doing this PR to be merged (unless you see it like something positive). My plan is open it just to ask you some questions and discuss with more people. I hope this is ok for you :)

Question 1: The manifest

This part is not clear to me in the article. As far as I understand you're proposing two ways of extracting webpack manifest.

Option 1: used in your code

This option uses chunk-manifest-webpack-plugin and webpack-manifest-plugin but I think is harder to integrate with html-webpack-plugin

Option 2: using html-wp-plugin and inline-manifest

You were wondering to add html-webpack-plugin and inline-manifest-webpack-plugin to this repo in this issue

Option 2 is what I'm trying but I'm not sure if I'm doing it right. Could you check my PR?

Tree shaking

Webpack 2 tree shaking only works with ES2015 export not with node module.exports commonJS modules. To have Tree shaking we need to declare our es2015 babel preset in this way:

{
  "presets": [
    ["es2015", { "modules": false }],
  ]
}

modules false make webpack not to convert es2015 exports into commonJS exports. I think.

{
"name": "webpack-long-term-cache-demo",
"version": "1.0.0",
"version": "2.0.0",
Copy link
Author

Choose a reason for hiding this comment

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

Ignore this. I just wanted to make clear that those changes is breaking everything 😸

"mobx-react-devtools": "4.2.11",
"react": "15.4.2",
"react-dom": "15.4.2",
"react-router": "3.0.2"
Copy link
Author

Choose a reason for hiding this comment

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

Look all those big guys ☝️

}
}
})
}
Copy link
Author

Choose a reason for hiding this comment

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

I want to experiment with route authorization and code splitting at the same time


module.exports = {
entry: {
app: resolvePath('src/index.js')
Copy link
Author

Choose a reason for hiding this comment

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

No explicit vendor. Look 👇 down

new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
chunks: ['app'],
minChunks: ({ resource }) => /node_modules/.test(resource)
Copy link
Author

Choose a reason for hiding this comment

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

What I'm trying to do here is dynamically move all node_modules dependencies into vendor chunk.

I'm not sure if it's a good idea because my goal is to implement code splitting. That means that maybe some dependency is just used in one of our dynamic chunks (for example on route-b. Maybe it's a bad idea to have that underused dependency in vendor. We'll see.

minChunks: ({ resource }) => /node_modules/.test(resource)
}),
new webpack.optimize.CommonsChunkPlugin({
name: ['manifest']
Copy link
Author

Choose a reason for hiding this comment

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

I'm don't know what I'm doing here.

  1. What is supposed to do this commonChunks?
  2. How works webpack manifest? there is only 1 manifest or each generated chunk generates a manifest?

This part is super confusing to me.

}),
new InlineManifestWebpackPlugin({
name: 'webpackManifest'
}),
Copy link
Author

Choose a reason for hiding this comment

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

With HtmlWebpackPlugin and InlineManifestWebpackPlugin I can see how a manifest is inline in my index.html. Is this enough?
image

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.

1 participant