feat(svgr): create new Docusaurus SVGR plugin (#10677)

This commit is contained in:
Sébastien Lorber 2024-11-29 17:26:34 +01:00 committed by GitHub
parent 750edc78ff
commit df6f53a2f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 1247 additions and 149 deletions

View file

@ -1,34 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {getFileLoaderUtils} from '../webpackUtils';
describe('getFileLoaderUtils()', () => {
it('plugin svgo/removeViewBox and removeTitle should be disabled', () => {
const {oneOf} = getFileLoaderUtils().rules.svg();
expect(oneOf![0]!.use).toContainEqual(
expect.objectContaining({
loader: require.resolve('@svgr/webpack'),
options: expect.objectContaining({
svgoConfig: {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeTitle: false,
removeViewBox: false,
},
},
},
],
},
}),
}),
);
});
});

View file

@ -45,7 +45,6 @@ type FileLoaderUtils = {
images: () => RuleSetRule;
fonts: () => RuleSetRule;
media: () => RuleSetRule;
svg: () => RuleSetRule;
otherAssets: () => RuleSetRule;
};
};
@ -134,45 +133,6 @@ function createFileLoaderUtils({
test: /\.(?:mp4|avi|mov|mkv|mpg|mpeg|vob|wmv|m4v|webm|ogv|wav|mp3|m4a|aac|oga|flac)$/i,
}),
svg: () => ({
test: /\.svg$/i,
oneOf: [
{
use: [
{
loader: require.resolve('@svgr/webpack'),
options: {
prettier: false,
svgo: true,
svgoConfig: {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeTitle: false,
removeViewBox: false,
},
},
},
],
},
titleProp: true,
},
},
],
// We don't want to use SVGR loader for non-React source code
// ie we don't want to use SVGR for CSS files...
issuer: {
and: [/\.(?:tsx?|jsx?|mdx?)$/i],
},
},
{
use: [loaders.url({folder: 'images'})],
},
],
}),
otherAssets: () => ({
use: [loaders.file({folder: 'files'})],
test: /\.(?:pdf|docx?|xlsx?|zip|rar)$/i,