I am using ifdef-loader to conditionally include modules based on some environment variables. When compiling with webpack (ifdef-loader and then ts-loader) it works as expected. When adding ForkTsCheckerWebpackPlugin I get errors that imported modules could not be find, even though the imports were inside ifdefs.
The TS checker runs after the loaders, so the ifdef removed code is not taken into account.
ifdef-loader loaderIs there a way to make sure the loader runs before the plugin?
fork-ts-checker-webpack-plugin runs in a separate thread next to webpack and always checks all files that are defined in the tsconfig.json - due to being run in a different thread it has not access to any transformations done in loaders.
This is a conceptual thing that cannot be changed - if this is your use case, fork-ts-checker-webpack-plugin might not be what you are looking for.
Sorry :disappointed:
But could I add a hook before each .ts file is accessed by the TSChecker to do some extra processing on it (eg. run ifdef-loader on it) ?
eg. (pseudocode)
new ForkTsCheckerWebpackPlugin ({
onBeforeFileCheck: (tsFile: string): string => {
return runLoader('ifdef-loader', tsFile);
}
});
or
new ForkTsCheckerWebpackPlugin ({
runLoadersOnFileBeforeCheck: ['ifdef-loader']
});
My use-case is that I want fast re-compilation time while developing, so I could have the type-checking delayed (and run ts-loader with transpileOnly), but I also need to run some extra loaders on my code before the type-checking can be done (which could also be done in a different thread than webpack).
There is a very big open PR by me to add the opportunity to run other extensions (e.g. vue) through loaders in #231. You could try that and add a loader for .ts https://github.com/TypeStrong/fork-ts-checker-webpack-plugin/pull/231/files#diff-5c49a678c54aafbfd2c33a29e20cbc89R17.
That might work, but honestly I'm not sure.
I will close it as there is no activity :)