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

Handling async chunks from splitChunks? #25

Closed
leebenson opened this issue Mar 5, 2018 · 7 comments
Closed

Handling async chunks from splitChunks? #25

leebenson opened this issue Mar 5, 2018 · 7 comments

Comments

@leebenson
Copy link

Using Webpack 4, this plugin works perfectly with sync chunks, but doesn't handle async chunks generated by import() statements.

A dump of my manifest.json:

{
  "assets/img/logo.png": "assets/img/logo.png",
  "main.css": "assets/css/main.d41d8cd98f00b204e9800998ecf8427e.css",
  "main.css.map": "assets/css/main.d41d8cd98f00b204e9800998ecf8427e.css.map",
  "main.js": "assets/js/main.530c2d547d428f017101.js",
  "main.js.map": "assets/js/main.530c2d547d428f017101.js.map"
}

But on the filesystem:

screen shot 2018-03-05 at 11 12 35

@webdeveric
Copy link
Owner

@leebenson I looked into this a long time ago (Webpack v1) and from what I can remember, it wasn't possible/feasible to get a name for chunks loaded with require.ensure (now import()). And since async chunks are loaded from other files (main.530c2d547d428f017101.js in your example) and not loaded directly with a <script> tag, I didn't see the need to include them in the manifest.json.

Assuming I can get the async chunk URLs into the manifest, how would you use them? Maybe there is a valid reason I can't think of at the moment.

@webdeveric
Copy link
Owner

@leebenson After looking into this a bit, I've found that you can opt-in to having your async chunks included in the manifest.json by providing a webpackChunkName comment in the import(). I'm still looking at it to see if this can be automated.

Example:

import(/* webpackChunkName: "[request]" */ './some-file.js');

@persocon
Copy link

I saw that it goes to the root of the manifest, is it possible to include it to the entrypoint it belongs?
the idea behind it is to make custom prefetch of assets

@mxmul
Copy link

mxmul commented May 11, 2019

+1 for associating the async chunks with their entrypoints somehow. I'd like to do something similar to GoogleChromeLabs/preload-webpack-plugin in my application, but this plugin doesn't currently tell me which assets should be preloaded/prefetched for a given entrypoint.

@huzhongchun
Copy link

Have you resolve this problem? @leebenson

@pavelloz
Copy link

pavelloz commented Oct 5, 2019

https://github.com/danethurber/webpack-manifest-plugin - this plugin seems to do it pretty good

@mxmul
Copy link

mxmul commented Oct 5, 2019

For my specific use-case (preloading React components in async chunks), the @loadable library solved the problem (specifically the SSR integration).

webdeveric added a commit that referenced this issue Nov 24, 2020
- Minimum webpack version is now 4.40.0
- Updated dependencies - fixes #96
- Updated tests
- Added `enabled` option
- Added `entrypointsUseAssets` option - fixes #66
- Brought back the `contextRelativeKeys` option - fixes $44
- Use lock files when using `writeToDisk` - fixes #89
- Use lock files when emitting the manifest - fixes #64
- Get all compilation assets with `getAssets()` - fixes #56 #49 #25
- Swapped the key/value in `assetNames` - fixes #56
- Updated merge behavior for entrypoints - fixes #48
webdeveric added a commit that referenced this issue Nov 24, 2020
- Minimum webpack version is now 4.40.0
- Updated dependencies - fixes #96
- Updated tests
- Added `enabled` option
- Added `entrypointsUseAssets` option - fixes #66
- Brought back the `contextRelativeKeys` option - fixes #44
- Use lock files when using `writeToDisk` - fixes #89
- Use lock files when emitting the manifest - fixes #64
- Get all compilation assets with `getAssets()` - fixes #56 #49 #25
- Swapped the key/value in `assetNames` - fixes #56
- Updated merge behavior for entrypoints - fixes #48
webdeveric added a commit that referenced this issue Nov 25, 2020
- Minimum webpack version is now 4.40.0
- Updated dependencies - fixes #96
- Updated tests
- Added `enabled` option
- Added `entrypointsUseAssets` option - fixes #66
- Brought back the `contextRelativeKeys` option - fixes #44
- Use lock files when using `writeToDisk` - fixes #89
- Use lock files when emitting the manifest - fixes #64
- Get all compilation assets with `getAssets()` - fixes #56 #49 #25
- Swapped the key/value in `assetNames` - fixes #56
- Updated merge behavior for entrypoints - fixes #48
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 a pull request may close this issue.

6 participants