-
-
Notifications
You must be signed in to change notification settings - Fork 420
/
config.ts
50 lines (46 loc) · 1.14 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { cosmiconfigSync } from 'cosmiconfig'
import type { Config, State } from '@svgr/core'
const explorer = cosmiconfigSync('svgo', {
searchPlaces: [
'package.json',
'.svgorc',
'.svgorc.js',
'.svgorc.json',
'.svgorc.yaml',
'.svgorc.yml',
'svgo.config.js',
'svgo.config.cjs',
'.svgo.yml',
],
transform: (result) => result && result.config,
cache: true,
})
const getSvgoConfigFromSvgrConfig = (config: Config): any => {
const params = { overrides: {} as any }
if (config.icon || config.dimensions === false) {
params.overrides.removeViewBox = false
}
if (config.native) {
params.overrides.inlineStyles = {
onlyMatchedOnce: false,
}
}
return {
plugins: [
{
name: 'preset-default',
params,
},
'prefixIds',
],
}
}
export const getSvgoConfig = (config: Config, state: State): any => {
const cwd = state.filePath || process.cwd()
if (config.svgoConfig) return config.svgoConfig
if (config.runtimeConfig) {
const userConfig = explorer.search(cwd)
if (userConfig) return userConfig
}
return getSvgoConfigFromSvgrConfig(config)
}