facebook / facebook/docusaurus

Better SVGR / SVGO default configs

未关闭
#10,679 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
proposal
主要语言
TypeScript
星标
66.2k
派生
10k
平均合并
1 天 3 小时
30 天内合并 PR
52

描述

### Motivation

If you are an SVGR / SVGO expert, please help us find better defaults.

In https://github.com/facebook/docusaurus/pull/10677 we are creating a new `@docusaurus/plugin-svgr` plugin that you can now configure through plugin/preset options.

This plugin moves this core feature to a dedicated plugin:

```jsx
import DocusaurusSvg from './docusaurus.svg';

;
```

https://docusaurus.io/docs/markdown-features/assets#inline-svgs

This offers you escape hatches for when the default SVGR / SVGO config does not fit your needs.

But we'd still like to improve the Docusaurus SVGR / SVGO default configs

These configs define how you import and use SVG files in your React code, and changing those can break or fix existing sites by altering what gets rendered and how SVG components are converted to React components.

This would be a breaking change in an upcoming major version of Docusaurus (v4 for example).

We'd like to find defaults that work well for most sites and reduce the need for users to customize those configs. Optimizations should rather be safe and avoid potential SVG ids/class/whatever conflicts.

## Current configs

These are the historical configs we use in Docusaurus v3:

```ts
const DefaultSVGOConfig: SVGOConfig = {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeTitle: false,
removeViewBox: false,
},
},
},
],
};

const DefaultSVGRConfig: SVGRConfig = {
prettier: false,
svgo: true,
svgoConfig: DefaultSVGOConfig,
titleProp: true,
};
```

## Related links

- https://github.com/facebook/docusaurus/issues/8297
- https://github.com/facebook/docusaurus/issues/10636
- https://github.com/facebook/docusaurus/pull/10205
- https://github.com/facebook/docusaurus/pull/10211
- https://github.com/facebook/docusaurus/pull/10677

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。