I am trying to get a list of files that end up in my build after treeshaking. I use conditional compilation constants to remove dev/debug code from bundle and Webpack is doing a good job with treeshaking, I don't find any dev code in the resulted build. But I want to write some code that would check wether some dev files ended up in production build by mistake.
I've tried NormalModuleReplacementPlugin
but Webpack still load imports even if they are not used, it has to analyse all the sources to determine whether any of them are a dead code.
I've tried adding plugin to emit
stage hook and going through all the modules and checking resources, but I still find references to my dev code file there, even though they don't end up in the resulted build.
class DevImportsMonitorPlugin {
apply(compiler) {
compiler.hooks.emit.tapAsync('DevImportsMonitor', (compilation, callback) => {
compilation.chunks.forEach(chunk => {
// explore chunk
chunk.getModules().forEach(module => {
// explore modules
})
});
callback();
});
}
}
I've put a breakpoint there and explored the context of chunks and modules, but it still has references to the dev/test modules.
Maybe there is a way to determine maybe what module was removed from the output?