I'm trying to follow the guide to Writing a Loader using Webpack 5.2.0. At the bottom of the page we are guided through a simple Jest test sample. The Jest test checks that the first module object source
property is the source that our loader generated. I can verify that my Webpack compiler step generated a module with a name
property of ./example.txt
. But the source
property is always 'undefined'
. This is despite stats.hasErrors()
returning false.
I'm new to Webpack loader development and I'm not sure what I'm missing. The module structure description indicates this property should contain my module source if it was successful.
Have others successfully completed this scenario with a recent verison of Webpack?
After some time of googling i found that for webpack@5 you need to pass additional options to have source
field in output.
stats.toJson({
source: true
});