@@ -9,6 +9,7 @@ This chapter introduces the plugin hooks available for Rsbuild plugins.
9
9
- [ modifyRsbuildConfig] ( #modifyrsbuildconfig ) : Modify the configuration object passed to Rsbuild.
10
10
- [ modifyRspackConfig] ( #modifyrspackconfig ) : Modify the configuration object passed to Rspack.
11
11
- [ modifyBundlerChain] ( #modifybundlerchain ) : Modify the configuration object of Rspack through the chain API.
12
+ - [ modifyHTMLTags] ( #modifyhtmltags ) : Modify the tags that are injected into the HTML.
12
13
- [ onBeforeCreateCompiler] ( #onbeforecreatecompiler ) : Called before creating a compiler instance.
13
14
- [ onAfterCreateCompiler] ( #onaftercreatecompiler ) : Called after creating a compiler instance and before building.
14
15
- [ onExit] ( #onexit ) : Called when the process is about to exit.
@@ -51,6 +52,7 @@ When the `rsbuild dev` command or `rsbuild.startDevServer()` method is executed,
51
52
- [ onBeforeCreateCompiler] ( #onbeforecreatecompiler )
52
53
- [ onAfterCreateCompiler] ( #onaftercreatecompiler )
53
54
- [ onAfterStartDevServer] ( #onafterstartdevserver )
55
+ - [ modifyHTMLTags] ( #modifyhtmltags )
54
56
- [ onDevCompileDone] ( #ondevcompiledone )
55
57
- [ onCloseDevServer] ( #onclosedevserver )
56
58
- [ onExit] ( #onexit )
@@ -65,6 +67,7 @@ When the `rsbuild build` command or `rsbuild.build()` method is executed, Rsbuil
65
67
- [ onBeforeCreateCompiler] ( #onbeforecreatecompiler )
66
68
- [ onAfterCreateCompiler] ( #onaftercreatecompiler )
67
69
- [ onBeforeBuild] ( #onbeforebuild )
70
+ - [ modifyHTMLTags] ( #modifyhtmltags )
68
71
- [ onAfterBuild] ( #onafterbuild )
69
72
- [ onExit] ( #onexit )
70
73
@@ -290,6 +293,55 @@ const myPlugin = () => ({
290
293
});
291
294
```
292
295
296
+ ### modifyHTMLTags
297
+
298
+ Modify the tags that are injected into the HTML.
299
+
300
+ - ** Type:**
301
+
302
+ ``` ts
303
+ type HtmlBasicTag = {
304
+ // Tag name
305
+ tag: string ;
306
+ // Attributes of the tag
307
+ attrs? : Record <string , string | boolean | null | undefined >;
308
+ // innerHTML of the tag
309
+ children? : string ;
310
+ };
311
+
312
+ type HTMLTags = {
313
+ // Tags group inserted into <head>
314
+ headTags: HtmlBasicTag [];
315
+ // Tags group inserted into <body>
316
+ bodyTags: HtmlBasicTag [];
317
+ };
318
+
319
+ function ModifyHTMLTags(
320
+ callback : (tags : HTMLTags ) => MaybePromise <HTMLTags >,
321
+ ): void ;
322
+ ```
323
+
324
+ - ** Example:**
325
+
326
+ ``` ts
327
+ const myPlugin = () => ({
328
+ setup : (api ) => {
329
+ api .modifyHTMLTags (({ headTags , bodyTags }) => {
330
+ headTags .push ({
331
+ tag: ' script' ,
332
+ attrs: { src: ' https://example.com/foo.js' },
333
+ });
334
+ bodyTags .push ({
335
+ tag: ' script' ,
336
+ children: ' console.log("hello world!");' ,
337
+ });
338
+
339
+ return { headTags , bodyTags };
340
+ });
341
+ },
342
+ });
343
+ ```
344
+
293
345
### onBeforeCreateCompiler
294
346
295
347
import OnBeforeCreateCompiler from ' @en/shared/onBeforeCreateCompiler.md' ;
0 commit comments