UNPKG

3.5 kBSource Map (JSON)View Raw
1{"version":3,"file":"index.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import { cosmiconfigSync } from 'cosmiconfig'\nimport type { Config, State } from '@svgr/core'\n\nconst explorer = cosmiconfigSync('svgo', {\n searchPlaces: [\n 'package.json',\n '.svgorc',\n '.svgorc.js',\n '.svgorc.json',\n '.svgorc.yaml',\n '.svgorc.yml',\n 'svgo.config.js',\n 'svgo.config.cjs',\n '.svgo.yml',\n ],\n transform: (result) => result && result.config,\n cache: true,\n})\n\nconst getSvgoConfigFromSvgrConfig = (config: Config): any => {\n const params = { overrides: {} as any }\n if (config.icon || config.dimensions === false) {\n params.overrides.removeViewBox = false\n }\n if (config.native) {\n params.overrides.inlineStyles = {\n onlyMatchedOnce: false,\n }\n }\n\n return {\n plugins: [\n {\n name: 'preset-default',\n params,\n },\n 'prefixIds',\n ],\n }\n}\n\nexport const getSvgoConfig = (config: Config, state: State): any => {\n const cwd = state.filePath || process.cwd()\n if (config.svgoConfig) return config.svgoConfig\n if (config.runtimeConfig) {\n const userConfig = explorer.search(cwd)\n if (userConfig) return userConfig\n }\n return getSvgoConfigFromSvgrConfig(config)\n}\n","import { optimize } from 'svgo'\nimport { getSvgoConfig } from './config'\nimport type { Plugin } from '@svgr/core'\n\nconst svgoPlugin: Plugin = (code, config, state) => {\n if (!config.svgo) return code\n const svgoConfig = getSvgoConfig(config, state)\n const result = optimize(code, { ...svgoConfig, path: state.filePath })\n\n // @ts-ignore\n if (result.modernError) {\n // @ts-ignore\n throw result.modernError\n }\n\n return result.data\n}\n\nexport default svgoPlugin\n"],"names":["cosmiconfigSync","optimize"],"mappings":";;;;;AAGA,MAAM,QAAA,GAAWA,4BAAgB,MAAQ,EAAA;AAAA,EACvC,YAAc,EAAA;AAAA,IACZ,cAAA;AAAA,IACA,SAAA;AAAA,IACA,YAAA;AAAA,IACA,cAAA;AAAA,IACA,cAAA;AAAA,IACA,aAAA;AAAA,IACA,gBAAA;AAAA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