-
-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/rspack/src/builtin-plugin/ContextReplacementPlugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
BuiltinPluginName, | ||
type RawContextReplacementPluginOptions | ||
} from "@rspack/binding"; | ||
|
||
import { create } from "./base"; | ||
|
||
export const ContextReplacementPlugin = create( | ||
BuiltinPluginName.ContextReplacementPlugin, | ||
( | ||
resourceRegExp: RegExp, | ||
newContentResource?: any, | ||
newContentRecursive?: any, | ||
newContentRegExp?: any | ||
) => { | ||
const rawOptions: RawContextReplacementPluginOptions = { | ||
resourceRegExp | ||
}; | ||
if (typeof newContentResource === "function") { | ||
// rawOptions.newContentCallback = newContentResource; | ||
} else if ( | ||
typeof newContentResource === "string" && | ||
typeof newContentRecursive === "object" | ||
) { | ||
rawOptions.newContentResource = newContentResource; | ||
// rawOptions.newContentCreateContextMap = (fs, callback) => { | ||
// callback(null, newContentRecursive); | ||
// }; | ||
} else if ( | ||
typeof newContentResource === "string" && | ||
typeof newContentRecursive === "function" | ||
) { | ||
rawOptions.newContentResource = newContentResource; | ||
// rawOptions.newContentCreateContextMap = newContentRecursive; | ||
} else { | ||
if (typeof newContentResource !== "string") { | ||
// biome-ignore lint/style/noParameterAssign: based on webpack's logic | ||
newContentRegExp = newContentRecursive; | ||
// biome-ignore lint/style/noParameterAssign: based on webpack's logic | ||
newContentRecursive = newContentResource; | ||
// biome-ignore lint/style/noParameterAssign: based on webpack's logic | ||
newContentResource = undefined; | ||
} | ||
if (typeof newContentRecursive !== "boolean") { | ||
// biome-ignore lint/style/noParameterAssign: based on webpack's logic | ||
newContentRegExp = newContentRecursive; | ||
// biome-ignore lint/style/noParameterAssign: based on webpack's logic | ||
newContentRecursive = undefined; | ||
} | ||
rawOptions.newContentResource = newContentResource; | ||
rawOptions.newContentRecursive = newContentRecursive; | ||
rawOptions.newContentRegExp = newContentRegExp; | ||
} | ||
return rawOptions; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters