Skip to content

Commit

Permalink
feat: add afterResolve hook usage (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
hardfist authored Sep 24, 2024
1 parent ec8e8d7 commit 6e47f9d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions rspack/hooks/after-resolve/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
16 changes: 16 additions & 0 deletions rspack/hooks/after-resolve/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "example-hooks-after-resolve",
"version": "1.0.0",
"private": true,
"license": "MIT",
"sideEffects": ["**/*.css", "**/*.less", "**/*.scss"],
"main": "index.js",
"scripts": {
"build": "rspack build",
"dev": "rspack serve"
},
"devDependencies": {
"@rspack/cli": "^1.0.3",
"@rspack/core": "^1.0.3"
}
}
24 changes: 24 additions & 0 deletions rspack/hooks/after-resolve/rspack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const rspack = require('@rspack/core');
/** @type {import('@rspack/cli').Configuration} */
const config = {
entry: './src/index.js',
plugins: [
new rspack.HtmlRspackPlugin({
template: './index.html',
}),
{
/**
*
* @param {import('@rspack/core').Compiler} compiler
*/
apply(compiler) {
compiler.hooks.normalModuleFactory.tap('nmf', (nmf) => {
nmf.hooks.afterResolve.tap('afterResolver', (data) => {
console.log('data:', data.createData?.resource);
});
});
},
},
],
};
module.exports = config;
1 change: 1 addition & 0 deletions rspack/hooks/after-resolve/src/answer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const answer = 42;
5 changes: 5 additions & 0 deletions rspack/hooks/after-resolve/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { answer } from './answer';
function render() {
document.getElementById('root').innerHTML = `the answer to the universe is ${answer}`;
}
render();

0 comments on commit 6e47f9d

Please sign in to comment.