-
-
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.
* feat: add buildModule hook * feat: use object assign --------- Co-authored-by: Hana <[email protected]>
- Loading branch information
1 parent
2783534
commit b940b48
Showing
11 changed files
with
82 additions
and
9 deletions.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { JsModule } from "@rspack/binding"; | ||
|
||
export interface NormalizedJsModule extends JsModule { | ||
identifier: () => string; | ||
} | ||
|
||
export function normalizeJsModule(m: JsModule): NormalizedJsModule { | ||
return Object.assign(m, { | ||
identifier: () => m.moduleIdentifier | ||
}); | ||
} |
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 @@ | ||
export const a = 3; |
5 changes: 5 additions & 0 deletions
5
packages/rspack/tests/configCases/hooks/build-module/index.js
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,5 @@ | ||
import { a } from "./a.js"; | ||
|
||
it("should compile successfully with build-module", () => { | ||
expect(a).toBe(3); | ||
}); |
23 changes: 23 additions & 0 deletions
23
packages/rspack/tests/configCases/hooks/build-module/webpack.config.js
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,23 @@ | ||
const { strict } = require("assert"); | ||
const pluginName = "plugin"; | ||
|
||
class Plugin { | ||
apply(compiler) { | ||
let identifiers = []; | ||
compiler.hooks.compilation.tap(pluginName, compilation => { | ||
compilation.hooks.buildModule.tap(pluginName, m => { | ||
identifiers.push(m.identifier()); | ||
}); | ||
}); | ||
compiler.hooks.done.tap(pluginName, () => { | ||
strict(identifiers.some(i => i.endsWith("index.js"))); | ||
strict(identifiers.some(i => i.endsWith("a.js"))); | ||
}); | ||
} | ||
} | ||
|
||
/**@type {import('@rspack/cli').Configuration}*/ | ||
module.exports = { | ||
context: __dirname, | ||
plugins: [new Plugin()] | ||
}; |