fix(v2): don't remove viewBox from svg
This commit is contained in:
parent
4d7ebcfc56
commit
3570aa06c8
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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}],
|
||||
},
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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: [
|
||||
|
|
|
|||
|
|
@ -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'})],
|
||||
|
|
|
|||
Loading…
Reference in New Issue