Comments (5)
I think you can use regular webpack hooks to do that. In the example, you don't use data emitted by the plugin, so you can simply tap into webpack's hooks :)
from fork-ts-checker-webpack-plugin.
Ah, you want to wait for the new version of files to be emitted, right? In that case, you will have to set async: false
in plugin options. This way webpack will wait for the plugin to finish type checking. The issues
hook is called on afterCompile
in async: false
mode
from fork-ts-checker-webpack-plugin.
Cool, thanks! I'll close the issue then.
from fork-ts-checker-webpack-plugin.
Hi @piotr-oles sorry for necroing this. I'm trying this path again and am still having deprecation warnings. It looks like afterCompile
is too late. In Webpack 4 you can modify the emitted assets at this hook, but in Webpack 5+ it is now an error to do so (I assume in Webpack 6 it will be blocked entirely). There is now an earlier hook, compilation.hooks.processAssets
that is meant for modifying the set of emitted assets. Ideally it would be great if async: false
tapped this hook.
from fork-ts-checker-webpack-plugin.
I have faced a similar issue.
Use case
- React library
ts-loader
replaced withesbuild-loader
to speedup buildd.ts
generation delegated fromts-loader
toForkTsCheckerWebpackPlugin
Workaround
For now, I have come up with the following workaround:
- Configure
types
to be emitted into a separate folder (so, it's easier to control them) - Use
CleanWebpackPlugin
to clean build assets - Skip cleanup of
types
- Clean
types
only once at theinit
phase using a custom plugin
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const { rmSync, existsSync } = require('fs');
// Custom plugin that cleanup only definition files
class DefinitionsCleanupPlugin {
apply(compiler) {
const outputPath = compiler.options.output.path;
if (!outputPath) {
throw new Error('[DefinitionsCleanupPlugin]: No output path provided');
}
compiler.hooks.initialize.tap('DefinitionsCleanupPlugin', () => {
const typesPath = `${outputPath}/types`;
if (existsSync(typesPath)) {
rmSync(typesPath, { force: true, recursive: true });
}
});
}
}
...
plugins: [
new ForkTsCheckerWebpackPlugin({
typescript: {
mode: 'write-dts',
},
}),
new DefinitionsCleanupPlugin(),
new CleanWebpackPlugin({
// Skip cleanup of types
cleanOnceBeforeBuildPatterns: ['**/*', '!types/**/*', '!types'],
}),
]
Cons:
- In
watch
mode, definitions are not cleaned during rebuilds (probably can be tuned by tapping other hooks in custom plugin, but it's ok for my scenario) - It still would be better to have some
beforeEmit
hook in theForkTsCheckerWebpackPlugin
itself and tap into it to perform a cleanup
from fork-ts-checker-webpack-plugin.
Related Issues (20)
- Configuration has an unknown property 'resolveTypeReferenceDirectiveModule'. HOT 1
- Incremental mode is not working in webpack devServer
- Solution Builder should set reportDiagnostic on build mode
- error: debug failure. false expression HOT 3
- Update `minimatch` to Latest and Update Import
- Uncaught Exception in yaml - A dependency update is required for `cosmiconfig`
- Use specific lerna module tsconfig on type checking HOT 2
- Getting ERROR in compiler.getInfrastructureLogger is not a function HOT 2
- Issues when importing plugin in TypeScript (`index.d.ts` vs `plugin.d.ts`)
- TypeError: config.logger.log is not a function HOT 3
- extends should be an array in typescript 5.0 HOT 2
- Github Actions module 'Ajv' not found HOT 1
- overlay: false not working HOT 1
- Does it respect @ts-nocheck ? HOT 1
- Performance loss between latest and v6.5.3
- class IssueWebpackError extends webpack_1.default.WebpackError when run webpack build
- Type check is slow in incremental mode on watch mode's subsequent runs (not on the first run).
- Fork-ts-checker >= 6 hangs on windows
- `TypeError: Cannot set property mark of #<Object> which has only a getter` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fork-ts-checker-webpack-plugin.