--- description: 'Control script tag placement with html.inject, including per-entry settings and manual HTML tag injection.' --- # html.inject - **Type:** `'head' | 'body' | boolean | Function` - **Default:** `'head'` Set the inject position of the `
``` ## Inject into body Add the following config to inject ` ``` ## Function usage - **Type:** ```ts type InjectFunction = (context: { value: ScriptInject; entryName: string; }) => ScriptInject | void | Promise; ``` When `html.inject` is of type Function, the function receives an object as its parameter, with the following properties: - `value`: the default inject configuration of Rsbuild. - `entryName`: the name of the current entry. In the context of MPA (Multi-Page Application), you can set different `inject` behaviors based on the entry name: ```ts title="rsbuild.config.ts" export default { html: { inject({ entryName }) { return entryName === 'foo' ? 'body' : 'head'; }, }, }; ``` ## Manual injection When `html.inject` is set to `false`, Rsbuild will not inject tags into the HTML, and the tags defined in [html.tags](/config/html/tags) will not take effect. At this time, you can access all the tags to be injected through the `htmlPlugin.tags` template parameter, and manually inject them into the specified position. For example, insert the ` <%= htmlPlugin.tags.headTags %>
<%= htmlPlugin.tags.bodyTags %> ``` ## Version history | Version | Changes | | ------- | -------------------------------------------------- | | v2.0.8 | Added support for async functions in `html.inject` |