fix(v2): don't remove viewBox from svg

This commit is contained in:
Bogdan Doroschenko 2020-12-14 18:17:03 +03:00 committed by GitHub
parent 4d7ebcfc56
commit 3570aa06c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 6 deletions

View File

@ -7,7 +7,13 @@
import path from 'path';
import {excludeJS, clientDir, getDocusaurusAliases} from '../base';
import {
excludeJS,
clientDir,
getDocusaurusAliases,
createBaseConfig,
} from '../base';
import * as utils from '../utils';
import {mapValues} from 'lodash';
describe('babel transpilation exclude logic', () => {
@ -69,3 +75,28 @@ describe('getDocusaurusAliases()', () => {
expect(relativeDocusaurusAliases).toMatchSnapshot();
});
});
describe('base webpack config', () => {
const props = {
outDir: '',
siteDir: '',
baseUrl: '',
generatedFilesDir: '',
routesPaths: '',
};
afterEach(() => {
jest.restoreAllMocks();
});
test('should use svg rule', () => {
const fileLoaderUtils = utils.getFileLoaderUtils();
const mockSvg = jest.spyOn(fileLoaderUtils.rules, 'svg');
jest
.spyOn(utils, 'getFileLoaderUtils')
.mockImplementation(() => fileLoaderUtils);
createBaseConfig(props, false, false);
expect(mockSvg).toBeCalled();
});
});

View File

@ -12,7 +12,7 @@ import {
} from 'webpack';
import path from 'path';
import {applyConfigureWebpack} from '../utils';
import {applyConfigureWebpack, getFileLoaderUtils} from '../utils';
import {
ConfigureWebpackFn,
ConfigureWebpackFnMergeStrategy,
@ -132,3 +132,19 @@ describe('extending generated webpack config', () => {
});
});
});
describe('getFileLoaderUtils()', () => {
test('plugin svgo/removeViewBox should be disabled', () => {
const use = getFileLoaderUtils().rules.svg().use;
expect(use).toContainEqual(
expect.objectContaining({
loader: '@svgr/webpack',
options: expect.objectContaining({
svgoConfig: {
plugins: [{removeViewBox: false}],
},
}),
}),
);
});
});

View File

@ -151,6 +151,7 @@ export function createBaseConfig(
rules: [
fileLoaderUtils.rules.images(),
fileLoaderUtils.rules.media(),
fileLoaderUtils.rules.svg(),
fileLoaderUtils.rules.otherAssets(),
{
test: /\.(j|t)sx?$/,
@ -183,10 +184,6 @@ export function createBaseConfig(
onlyLocals: isServer,
}),
},
{
test: /\.svg$/,
use: '@svgr/webpack?-prettier,+svgo,+titleProp,+ref![path]',
},
],
},
plugins: [

View File

@ -298,6 +298,26 @@ export function getFileLoaderUtils(): Record<string, any> {
};
},
svg: (): RuleSetRule => {
return {
use: [
{
loader: '@svgr/webpack',
options: {
prettier: false,
svgo: true,
svgoConfig: {
plugins: [{removeViewBox: false}],
},
titleProp: true,
ref: ![path],
},
},
],
test: /\.svg$/,
};
},
otherAssets: (): RuleSetRule => {
return {
use: [loaders.file({folder: 'files'})],