-
-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emitted files should be added as assets to the compilation #813
Comments
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 :) |
Ah, you want to wait for the new version of files to be emitted, right? In that case, you will have to set |
Cool, thanks! I'll close the issue then. |
Hi @piotr-oles sorry for necroing this. I'm trying this path again and am still having deprecation warnings. It looks like |
I have faced a similar issue. Use case
WorkaroundFor now, I have come up with the following workaround:
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:
|
Feature motivation
Currently, if the checker emits files to the webpack outputPath, setting
{ output: { clean: true } }
will remove them. The reason is because Webpack does not know that emitted files, such as declarations and declaration maps, should be treated as assets generated by the bundle.At a minimum, it would be nice if the set of emitted files was available in a tapable hook that runs before the compilation finishes. It looks like you can sort of get this by tapping the
issues
hook and then globbing the output folder, but it seems like this hook fires too late. In Webpack 5, you'll getFeature description
It would be nice if the plugin just did this out of the box, but at a minimum, it would be nice to add a new hook that runs during the emit/processAsset phase and passes in the list of emitted files to the tap.
Feature implementation
Here's an example that uses the existing hooks, as well as
fast-glob
to grab the set of generated files and add them as assets. The problem is that it runs too late and throws deprecation warnings in Webpack 5.The text was updated successfully, but these errors were encountered: