I'm writing a custom Webpack plugin that is supposed to modify some TypeScript source files and as a result, the dependencies between the files can change (e.g. an import to a file can be added or removed, as well as an import can be replaced by another import). I'm having issues with Webpack not picking up the new relationships between the files. The best I've got so far is that I can get it to pick up on some of the file changes, but it appears to be too late in the compilation's lifecycle and as a result the file content could be outdated. Here's a simplification of what I've got so far. I am confident that the logic that determines the newFiles and hasDependencyOnFile is correct:
class CustomWebpackPlugin {
apply(compiler) {
compiler.plugin('after-compile', (compilation, callback) => {
compilation.fileDependencies.push(...newFiles);
compilation.modules.forEach(module => {
if (hasDependencyOnFile(module.resource)) {
module.fileDependencies.push(...newFiles);
}
});
callback();
});
}
}
Is this the proper way to approach adding new entries to the dependency graph or does Webpack provide an API to do it correctly?