From 3e13e62390a04ddefab127283f76d91e676e7b05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juho=20Veps=C3=A4l=C3=A4inen?= Date: Wed, 30 Jun 2021 10:30:37 +0300 Subject: [PATCH] fix: Fix rebuild performance for webpack 5 This change adds the needed check for webpack 5 to avoid extra processing. Ported from https://github.com/hipstersmoothie/react-docgen-typescript-plugin/pull/45. --- src/plugin.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/plugin.ts b/src/plugin.ts index 9331c68..d0384cb 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -198,6 +198,30 @@ export default class DocgenPlugin implements webpack.WebpackPluginInstance { const nameForCondition = module.nameForCondition() || ""; + // Ignore already built modules for webpack 5 + if (!compilation.builtModules.has(module)) { + debugExclude(`Ignoring un-built module: ${nameForCondition}`); + return; + } + + // Ignore external modules + // eslint-disable-next-line + // @ts-ignore: Webpack 4 type + if (module.external) { + debugExclude(`Ignoring external module: ${nameForCondition}`); + return; + } + + // Ignore raw requests + // eslint-disable-next-line + // @ts-ignore: Webpack 4 type + if (!module.rawRequest) { + debugExclude( + `Ignoring module without "rawRequest": ${nameForCondition}` + ); + return; + } + if (isExcluded(nameForCondition)) { debugExclude( `Module not matched in "exclude": ${nameForCondition}`