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

Add example #1

Open
diurnalist opened this issue Sep 17, 2014 · 11 comments
Open

Add example #1

diurnalist opened this issue Sep 17, 2014 · 11 comments
Assignees

Comments

@diurnalist
Copy link
Contributor

Add an example that shows why this plugin is helpful, and how it is used.

@diurnalist diurnalist self-assigned this Sep 17, 2014
@okonet
Copy link

okonet commented Apr 10, 2015

👍 Please! This would be really helpful!

@deepsweet
Copy link

I can't get it work, chunks IDs in manifest.json changes on every build. or I don't understand the idea :)

@kentcdodds
Copy link

Could definitely use an example. I get what this line means:

Webpack can then read this mapping, assuming it is provided somehow on the client

But I'm not sure how to provide the mapping to webpack...

@deepsweet
Copy link

have found this:

You may remember from before that webpack creates an ID for each bundle, to minimise the size of all its files. So, every compiled bundle webpack produces will internally have an ID. By default, webpack will store these IDs in the common bundle. The problem with this is that whenever you change any bundle, it’ll mean the common bundle will be updated (to include the new common manifest), thus cache-busting it needlessly.

Thanks to the ChunkManifestPlugin, webpack can be told to not write this manifest directly into the common bundle. Instead it writes the manifest out and then, when it runs in the browser, will look for a global variable webpackBundleManifest

and then:

<script>
//<![CDATA[
window.webpackManifest = {"0":"0-bundle-bdbd995368b007bb18a7.js","2":"2-bundle-7ad34cf6445d875d8506.js","3":"3-bundle-f8745c8bc2319252b6de.js","4":"4-bundle-ec8f5ae62f2e8da11aa1.js","5":"authenticated-bundle-933816ada9534488d12f.js","6":"public-bundle-8eb73d97201bd2e4951b.js"}
//]]>
</script>
<script src="https://abc.cloudfront.net/assets/common-71a050793d79ce393b1e.js"></script>
<script src="https://abc.cloudfront.net/assets/public-bundle-8eb73d97201bd2e4951b.js"></script>

as far as I understand it webpack will try to find IDs map in window.webpackManifest instead of storing it in common chunk.

@diurnalist
Copy link
Contributor Author

@deepsweet @kentcdodds yes, you just assign that manifest JSON to a global variable, presumably as some sort of <script> tag in your HTML response.

Thanks for the link to the post! Does a better job of explaining.

@okonet
Copy link

okonet commented Jul 11, 2015

I've written an article on how to set it up. Would be happy for any feedback: https://medium.com/@okonetchnikov/long-term-caching-of-static-assets-with-webpack-1ecb139adb95

@deepsweet your issue is also mentioned in the article. You should use OccurenceOrderPlugin to fix this.

I've also added a repository with a sample webpack.config: https://github.com/okonet/webpack-long-term-cache-demo

@chrisabrams
Copy link

Thanks a lot for this!

@ibufu
Copy link

ibufu commented Aug 31, 2016

Is there a plugin can help us inject webpackManifest to html automatically?

@okonet
Copy link

okonet commented Aug 31, 2016

@ibufu https://github.com/szrenwei/inline-manifest-webpack-plugin

@feus4177
Copy link

@ibufu if you're talking about injecting window.webpackManifest = {...}, I found https://github.com/jouni-kantola/inline-chunk-manifest-html-webpack-plugin to be useful. I realize this is a little late but hopefully others who come after me will find it useful.

@jouni-kantola
Copy link

I've published inline-chunk-manifest-html-webpack-plugin to npm.
https://www.npmjs.com/package/inline-chunk-manifest-html-webpack-plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

8 participants