Skip to content

Commit df5f3d3

Browse files
authored
fix(browser): rename and ignore requests with match resource and inline loaders (#11469)
* Rename * Check protocol and ignore match resource * Ignore
1 parent 9795fc8 commit df5f3d3

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

packages/rspack/src/browser/BrowserImportEsmPlugin.ts renamed to packages/rspack/src/browser/BrowserHttpImportEsmPlugin.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface BrowserHttpImportPluginOptions {
2424
/**
2525
* Convert imports of dependencies in node modules to http imports from esm cdn.
2626
*/
27-
export class BrowserImportEsmPlugin {
27+
export class BrowserHttpImportEsmPlugin {
2828
constructor(private options: BrowserHttpImportPluginOptions = {}) {}
2929

3030
apply(compiler: Compiler) {
@@ -33,6 +33,12 @@ export class BrowserImportEsmPlugin {
3333
const request = resolveData.request;
3434
const packageName = getPackageName(request);
3535

36+
// We don't consider match resource and inline loaders
37+
// Because usually they are not used with dependent modules like `sass-loader?react`
38+
if (request.includes("!")) {
39+
return;
40+
}
41+
3642
// If dependencyUrl is provided, use it to resolve the request
3743
if (this.options.dependencyUrl) {
3844
if (typeof this.options.dependencyUrl === "function") {
@@ -51,7 +57,7 @@ export class BrowserImportEsmPlugin {
5157
}
5258

5359
// If the issuer is a URL, request must be relative to that URL too
54-
const issuerUrl = toUrl(resolveData.contextInfo.issuer);
60+
const issuerUrl = toHttpUrl(resolveData.contextInfo.issuer);
5561
if (issuerUrl) {
5662
resolveData.request = this.resolveWithUrlIssuer(request, issuerUrl);
5763
return;
@@ -85,7 +91,7 @@ export class BrowserImportEsmPlugin {
8591

8692
isNodeModule(request: string) {
8793
// Skip requests like "http://xxx"
88-
if (toUrl(request)) {
94+
if (toHttpUrl(request)) {
8995
return false;
9096
}
9197

@@ -137,10 +143,12 @@ function getRequestWithVersion(request: string, version: string) {
137143
}
138144
}
139145

140-
function toUrl(request: string): URL | undefined {
146+
function toHttpUrl(request: string): URL | undefined {
141147
try {
142148
const url = new URL(request);
143-
return url;
149+
if (url.protocol === "http:" || url.protocol === "https:") {
150+
return url;
151+
}
144152
} catch {
145153
return undefined;
146154
}

packages/rspack/src/browser/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export * from "../index";
2-
export { BrowserImportEsmPlugin } from "./BrowserImportEsmPlugin";
2+
export { BrowserHttpImportEsmPlugin } from "./BrowserHttpImportEsmPlugin";
33

44
import { fs, volume } from "./fs";
55
export const builtinMemFs = {

0 commit comments

Comments
 (0)