diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index f63f16150b..d51e10da7f 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -104,6 +104,7 @@ const getDefaultSourceConfig = (): NormalizedSourceConfig => { }; const getDefaultHtmlConfig = (): NormalizedHtmlConfig => ({ + lang: 'en', meta: { charset: { charset: 'UTF-8' }, viewport: 'width=device-width, initial-scale=1.0', diff --git a/packages/core/src/plugins/html.ts b/packages/core/src/plugins/html.ts index 6a37563299..00df5bb9ef 100644 --- a/packages/core/src/plugins/html.ts +++ b/packages/core/src/plugins/html.ts @@ -41,8 +41,8 @@ function getInject(entryName: string, config: NormalizedEnvironmentConfig) { }); } -const getDefaultTemplateContent = (mountId: string) => - `
`; +const getDefaultTemplateContent = (mountId: string, lang: string) => + `
`; const existTemplatePath = new Set(); @@ -63,7 +63,10 @@ export async function getTemplate( if (!templatePath) { return { templatePath: undefined, - templateContent: getDefaultTemplateContent(config.html.mountId), + templateContent: getDefaultTemplateContent( + config.html.mountId, + config.html.lang, + ), }; } diff --git a/packages/core/src/types/config.ts b/packages/core/src/types/config.ts index 8637ff7c4c..57bce5e81f 100644 --- a/packages/core/src/types/config.ts +++ b/packages/core/src/types/config.ts @@ -1331,9 +1331,15 @@ export interface HtmlConfig { * @default 'defer' */ scriptLoading?: ScriptLoading; + /** + * Set the html attribute language + * @default 'en' + */ + lang?: string; } export type NormalizedHtmlConfig = HtmlConfig & { + lang: string; meta: ChainedHtmlOption; title: ChainedHtmlOption; mountId: string; diff --git a/packages/core/tests/html.test.ts b/packages/core/tests/html.test.ts index 1f57d25a4f..039053488c 100644 --- a/packages/core/tests/html.test.ts +++ b/packages/core/tests/html.test.ts @@ -215,4 +215,13 @@ describe('plugin-html', () => { expect(config).toMatchSnapshot(); }, ); + + it('should have "lang" attribute', async () => { + const rsbuild = await createStubRsbuild({ + plugins: [pluginEntry(), pluginHtml()], + rsbuildConfig: { html: { lang: 'en' } }, + }); + const config = await rsbuild.unwrapConfig(); + expect(config).toMatchSnapshot(); + }); }); diff --git a/packages/plugin-svgr/src/index.ts b/packages/plugin-svgr/src/index.ts index 4c8ac41012..c1c8bd0e8f 100644 --- a/packages/plugin-svgr/src/index.ts +++ b/packages/plugin-svgr/src/index.ts @@ -164,7 +164,7 @@ export const pluginSvgr = (options: PluginSvgrOptions = {}): RsbuildPlugin => ({ options.svgrOptions || {}, ); - svgrOptions.svgoConfig = dedupeSvgoPlugins(svgrOptions.svgoConfig); + svgrOptions.svgoConfig = dedupeSvgoPlugins(svgrOptions.svgoConfig!); // force to url: "foo.svg?url", rule diff --git a/website/docs/en/config/html/lang.mdx b/website/docs/en/config/html/lang.mdx new file mode 100644 index 0000000000..60858d1de0 --- /dev/null +++ b/website/docs/en/config/html/lang.mdx @@ -0,0 +1,28 @@ +# html.lang + +- **Type:** `string` +- **Default:** `en` + +Configure the HTML language attribute. + +```html + +``` + +## Example + +For example to set HTML language to `zh-CN`: + +```js +export default { + html: { + lang: 'zn-CN', + }, +}; +``` + +Result: + +```html + +``` diff --git a/website/docs/en/config/html/template.mdx b/website/docs/en/config/html/template.mdx index 72799af3db..b0b0fc0ed3 100644 --- a/website/docs/en/config/html/template.mdx +++ b/website/docs/en/config/html/template.mdx @@ -8,7 +8,7 @@ If `template` is not specified, the built-in HTML template of Rsbuild will be us ```html - +
diff --git a/website/docs/zh/config/html/template.mdx b/website/docs/zh/config/html/template.mdx index 83537dec42..624e53de83 100644 --- a/website/docs/zh/config/html/template.mdx +++ b/website/docs/zh/config/html/template.mdx @@ -8,7 +8,7 @@ ```html - +