Skip to content

Commit ae91e2e

Browse files
authored
feat(esm): add support for svgo.config.cjs (#879)
1 parent e612b6a commit ae91e2e

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
plugins: [
3+
{
4+
name: 'preset-default',
5+
params: {
6+
overrides: {
7+
removeTitle: false,
8+
},
9+
},
10+
},
11+
]
12+
}

packages/cli/src/__snapshots__/index.test.ts.snap

+13
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ export default SvgFile
6666
"
6767
`;
6868

69+
exports[`cli should support --svgo-config as file with .cjs extension 1`] = `
70+
"import * as React from 'react'
71+
const SvgFile = (props) => (
72+
<svg xmlns="http://www.w3.org/2000/svg" width={48} height={1} {...props}>
73+
<title>{'Rectangle 5'}</title>
74+
<path fill="#063855" fillRule="evenodd" d="M0 0h48v1H0z" />
75+
</svg>
76+
)
77+
export default SvgFile
78+
79+
"
80+
`;
81+
6982
exports[`cli should support --svgo-config as json 1`] = `
7083
"import * as React from 'react'
7184
const SvgFile = (props) => (

packages/cli/src/index.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ describe('cli', () => {
109109
expect(result).toMatchSnapshot()
110110
})
111111

112+
it('should support --svgo-config as file with .cjs extension', async () => {
113+
const result = await cli(
114+
`--svgo-config __fixtures__/withSvgoConfig/svgo.config.cjs __fixtures__/simple/file.svg`,
115+
)
116+
expect(result).toMatchSnapshot()
117+
})
118+
112119
it.each([
113120
['--no-dimensions'],
114121
['--jsx-runtime classic-preact'],

packages/cli/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const parseConfig = (name: string) => (arg: string) => {
3838
}
3939

4040
const ext = path.extname(arg)
41-
if (ext === '.js' || ext === '.json') {
41+
if (ext === '.js' || ext === '.json' || ext === '.cjs') {
4242
return require(path.join(process.cwd(), arg))
4343
}
4444

packages/plugin-svgo/src/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const explorer = cosmiconfigSync('svgo', {
1010
'.svgorc.yaml',
1111
'.svgorc.yml',
1212
'svgo.config.js',
13+
'svgo.config.cjs',
1314
'.svgo.yml',
1415
],
1516
transform: (result) => result && result.config,

website/pages/docs/configuration-files.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ expandProps: false
5454
5555
## SVGO
5656
57-
The recommended way to configure SVGO for SVGR is to use [`svgo.config.js`](https://github.com/svg/svgo/blob/main/README.md#configuration).
57+
The recommended way to configure SVGO for SVGR is to use [`svgo.config.js or svgo.config.cjs`](https://github.com/svg/svgo/blob/main/README.md#configuration).
5858

5959
Even if it is not recommended, you can also use `svgoConfig` option to specify your SVGO configuration. `svgoConfig` has precedence on `svgo.config.js`.
6060

0 commit comments

Comments
 (0)