Skip to content

Commit

Permalink
fix: generate params of runtime module
Browse files Browse the repository at this point in the history
  • Loading branch information
LingyuCoder committed Sep 26, 2024
1 parent 917cd92 commit cb8ac9d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/rspack/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14639,7 +14639,7 @@ export class RuntimeModule {
// (undocumented)
fullHash: boolean;
// (undocumented)
generate(compilation: Compilation): string;
generate(): string;
// (undocumented)
identifier(): string;
// (undocumented)
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack/src/RuntimeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class RuntimeModule {
return {
name: module.name,
stage: module.stage,
generator: () => module.generate(compilation),
generator: module.generate.bind(module),
cacheable: !(module.fullHash || module.dependentHash),
isolate: module.shouldIsolate()
};
Expand Down Expand Up @@ -67,7 +67,7 @@ export class RuntimeModule {
return true;
}

generate(compilation: Compilation): string {
generate(): string {
throw new Error(
`Should implement "generate" method of runtime module "${this.name}"`
);
Expand Down
3 changes: 2 additions & 1 deletion website/docs/en/api/javascript-api/compilation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ module.exports = {
super('custom');
}

generate(compilation) {
generate() {
const compilation = this.compilation;
return `
__webpack_require__.mock = function() {
// ...
Expand Down
3 changes: 2 additions & 1 deletion website/docs/en/api/plugin-api/compilation-hooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,8 @@ module.exports = {
super('custom');
}

generate(compilation) {
generate() {
const compilation = this.compilation;
return `
__webpack_require__.mock = function(file) {
return ${RuntimeGlobals.publicPath} + "/subpath/" + file;
Expand Down
3 changes: 2 additions & 1 deletion website/docs/zh/api/javascript-api/compilation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ module.exports = {
super('custom', RuntimeModule.STAGE_NORMAL);
}

generate(compilation) {
generate() {
const compilation = this.compilation;
return `
__webpack_require__.mock = function() {
// ...
Expand Down
3 changes: 2 additions & 1 deletion website/docs/zh/api/plugin-api/compilation-hooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@ module.exports = {
super('custom');
}

generate(compilation) {
generate() {
const compilation = this.compilation;
return `
__webpack_require__.mock = function(file) {
return ${RuntimeGlobals.publicPath} + "/subpath/" + file;
Expand Down

0 comments on commit cb8ac9d

Please sign in to comment.