Skip to content

Commit

Permalink
perf: Improved module resolution time
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Nov 27, 2021
1 parent ec26274 commit f63778b
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ export function injectLoader(): void {
]);
}

const pureComponentMap = new Map<string, boolean>();

export function isReactComponent(moduleId: string) {
if (pureComponentMap.has(moduleId)) {
return pureComponentMap.get(moduleId);
}

const ignoreRE = /\w+\.(Pure)?Component\s*\{/;

const source = webpackRequire.m[moduleId].toString();

const isPure = ignoreRE.test(source);

pureComponentMap.set(moduleId, isPure);
return isPure;
}

/**
* Return the webpack module id from a search function
* @param condition Function for compare the modules
Expand All @@ -126,11 +143,8 @@ export function searchId(
debug(`Searching for: ${condition.toString()}`);
}, 500);

const ignoreRE = /\w+\.PureComponent\s*\{/;

for (const moduleId of ids) {
const source = webpackRequire.m[moduleId].toString();
if (ignoreRE.test(source)) {
if (isReactComponent(moduleId)) {
continue;
}

Expand Down Expand Up @@ -184,6 +198,10 @@ export function modules(
ids = ids.reverse();
}
for (const moduleId of ids) {
if (isReactComponent(moduleId)) {
continue;
}

try {
const module = webpackRequire(moduleId);

Expand Down

0 comments on commit f63778b

Please sign in to comment.