Skip to content

Commit 053cbd3

Browse files
authored
Update switch_from_webpacker.md with webpack codesplitting config (#177)
Add the configuration needed to configure webpack to do code splitting while ensuring all assets are fingerprinted.
1 parent e7881e9 commit 053cbd3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/switch_from_webpacker.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,24 @@ module.exports = {
252252
};
253253
```
254254

255+
### Optional: Use webpack to chunk assets so that it works with Sprockets
256+
257+
Sprockets was updated to detect that an asset has already been fingerprinted and won't fingerprint it again. This allows webpack to do code splitting while ensuring all assets have cache busting fingerprints and can be stored on a CDN. This config allows Sprockets to fingerprint the entrypoint file so that `javascript_include_tag` can load that asset by name.
258+
259+
```
260+
// in webpack.config.js, add
261+
module.exports = {
262+
output: {
263+
filename: "[name].js",
264+
chunkFilename: "[name]-[contenthash].digested.js",
265+
sourceMapFilename: "[file]-[fullhash].map",
266+
path: path.resolve(__dirname, '..', '..', 'app/assets/builds'),
267+
hashFunction: "sha256",
268+
hashDigestLength: 64,
269+
}
270+
}
271+
```
272+
255273
## 4. Test your build
256274

257275
Confirm you have a working webpack configuration. You can rebuild the bundle with:

0 commit comments

Comments
 (0)