Closed watjurk closed 2 years ago
It's the intended behavior of the plugin :) The plugin doesn't wait for webpack to resolve the dependency graph - it runs type-check immediately. This turns out to be faster in most cases because most of the time files inside your "src" directory are ~ of the dependency graph. And this is also consistent with how tsc
works.
It's described in the README: https://github.com/TypeStrong/fork-ts-checker-webpack-plugin#modules-resolution :)
This sounds logical, but ts-loader actually does it in slightly different way - the webpack's way, and unfortunately my project was dependent on the way that ts-loader handled type checking, and I wanted to switch over to fork-ts. Are you able to create an option so that this plugin will handle type checking as described in the issue? Or this would be very difficult?
Thanks!
I think it's possible to accomplish with existing hooks that this plugin provides :) Here is a plugin that I tested locally and it seems to work:
// webpack/OnlyWebpackErrorsInForkTsCheckerWebpackPlugin.js
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
module.exports = class OnlyWebpackErrorsInForkTsCheckerWebpackPlugin {
apply(compiler) {
const hooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(compiler);
hooks.issues.tap('OnlyWebpackErrorsInForkTsCheckerWebpackPlugin', (issues, compilation) => {
const files = new Set();
for (const module of compilation.modules) {
if (module.resource) {
files.add(module.resource);
}
}
// display errors only for files that are managed by webpack
return issues.filter(issue => !issue.file || files.has(issue.file));
});
}
}
and then in the webpack.config.js
:
// webpack.config.js
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const OnlyWebpackErrorsInForkTsCheckerWebpackPlugin = require('./webpack/OnlyWebpackErrorsInForkTsCheckerWebpackPlugin');
module.exports = {
...
plugins: [
new ForkTsCheckerWebpackPlugin(),
new OnlyWebpackErrorsInForkTsCheckerWebpackPlugin()
]
};
The plugin will still run type-check on all files, but they will be ignored
It works on Mac, I'm not sure if this will work on Windows due to path differences :)
Thanks a lot it work like a dream!
Dzięki wielkie, działa jak marzenie! Kraków rządzi!
Current behavior
This plugin type-checks whole directory, it doesn't matter if the file is included in webpack bundle or not.
Expected behavior
For this plugin to type-check only files that are included in webpack bundle.
Steps to reproduce the issue
Issue reproduction repository
https://github.com/watjurk/fork-ts-checker-webpack-plugin-issue