Loading assets via a loader's `this.loadModule()` doesn't emit asset files
See original GitHub issueBug report
What is the current behavior?
When calling this.loadModule( "some-path", callback )
from a loader while some-path
is defined as an asset in the module rules (eg. type: "asset/source"
), webpack won’t emit some-path
as an asset.
If the current behavior is a bug, please provide the steps to reproduce. See my simple reproduction repo here: https://github.com/bastimeyer/webpack-load-module-asset
Relevant files
- https://github.com/bastimeyer/webpack-load-module-asset/blob/b6c670f2011ba7d4cc0cf2def17df0359b3c98c6/webpack.config.js
- https://github.com/bastimeyer/webpack-load-module-asset/blob/b6c670f2011ba7d4cc0cf2def17df0359b3c98c6/src/index.js
- https://github.com/bastimeyer/webpack-load-module-asset/blob/b6c670f2011ba7d4cc0cf2def17df0359b3c98c6/src/loader.js
Build log (verbose stats): https://github.com/bastimeyer/webpack-load-module-asset/runs/2794477055?check_suite_focus=true#step:5:1
What is the expected behavior? Webpack should emit the asset loaded from within the loader just like when loading the asset from an import / require call / etc, or when using the file-loader for emitting resolved asset files.
Other relevant information: webpack version: 5.38.1 (currently the latest version) Node.js version: 16.3.0 (irrelevant) Operating System: Arch Linux (irrelevant) Additional tools: yarn (irrelevant)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:12 (10 by maintainers)
Top GitHub Comments
we discussed this internally… In my opinion there is no need to create specific api for that. mostly you always need an url to this asset. So in case:
You can transform your json to js json
transformed
@bastimeyer That’s literally my exact use case too.
See https://github.com/usmanyunusov/webpack-webmanifest-loader for a webpack 5 loader which does a similar thing. It loads a webmanifest file (json) and replaces paths to image assets with the final bundled path of that asset. It uses child compilers and stuff which goes over my head.