diff --git a/packages/webpack5/src/loaders/xml-namespace-loader/index.ts b/packages/webpack5/src/loaders/xml-namespace-loader/index.ts index edb3fbf68..585f989a7 100644 --- a/packages/webpack5/src/loaders/xml-namespace-loader/index.ts +++ b/packages/webpack5/src/loaders/xml-namespace-loader/index.ts @@ -75,16 +75,22 @@ async function parseXML(content: string): Promise { const resolvePaths = [ localNamespacePath, localModulePath, - `${localModulePath}.xml`, moduleName, namespace, - `${moduleName}.xml`, `~/${moduleName}`, `~/${namespace}`, + ]; + + // fallbacks for codeless namespaces + const fallbackResolvePaths = [ + `${localModulePath}.xml`, + `${moduleName}.xml`, `~/${moduleName}.xml`, ]; - DEBUG && console.log({ resolvePaths }); + + DEBUG && console.log({ resolvePaths, fallbackResolvePaths }); let resolvedPath; + let isFallbackPath = false; for (const p of resolvePaths) { resolvedPath = await resolveAsync(this.context, p).catch(noop); @@ -95,7 +101,23 @@ async function parseXML(content: string): Promise { } } - DEBUG && console.log({ resolvedPath }); + if (!resolvedPath) { + for (const p of fallbackResolvePaths) { + resolvedPath = await resolveAsync(this.context, p).catch(noop); + + // break on first match + if (resolvedPath) { + isFallbackPath = true; + break; + } + } + } + + DEBUG && + console.log({ + resolvedPath, + isFallbackPath, + }); // bail if we haven't resolved a path if (!resolvedPath) { @@ -104,10 +126,15 @@ async function parseXML(content: string): Promise { const { dir, name } = parse(resolvedPath); - // register resolved path + short name - namespaces.push({ name: namespace, path: resolvedPath }); - namespaces.push({ name: moduleName, path: resolvedPath }); - this.addDependency(resolvedPath); + DEBUG && console.log({ namespace, moduleName }); + + // check if we are not in a fallback path, in which case we shouldn't register it as a namespace + if (!isFallbackPath) { + // register resolved path + short name + namespaces.push({ name: namespace, path: resolvedPath }); + namespaces.push({ name: moduleName, path: resolvedPath }); + this.addDependency(resolvedPath); + } const noExtFilename = join(dir, name);