-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
169 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@svgr-rs/svgrs-plugin": patch | ||
--- | ||
|
||
support nodejs svgo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,40 @@ | ||
// polyfill for rollup-plugin-condition-exports | ||
/** | ||
* Based on @svgr/plugin-svgo | ||
* Copyright 2017 Smooth Code | ||
*/ | ||
|
||
import type { State } from '@svgr-rs/core' | ||
import type SvgoInstance from 'svgo' | ||
import type { Config } from './type' | ||
|
||
/** | ||
* @todo Load svgo config from config file | ||
*/ | ||
export const getSvgoConfig = (config: Config): any => { | ||
if (config.svgoConfig) { | ||
return config.svgoConfig | ||
} | ||
return {} | ||
} | ||
|
||
export const svgo = async (code: string, config: Config, state: State) => { | ||
if (!config.svgo) { | ||
return code | ||
} | ||
let svgoInstance: typeof SvgoInstance | ||
if (config.svgoImplementation) { | ||
svgoInstance = config.svgoImplementation | ||
} else { | ||
svgoInstance = await import('svgo') | ||
} | ||
const svgoConfig = getSvgoConfig(config) | ||
const result = svgoInstance.optimize(code, { ...svgoConfig, path: state.filePath }) | ||
|
||
// @ts-expect-error -- ignore | ||
if (result.modernError) { | ||
// @ts-expect-error -- ignore | ||
throw result.modernError | ||
} | ||
|
||
return result.data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { Config as SvgrsConfig } from '@svgr-rs/core' | ||
|
||
export interface Config extends SvgrsConfig { | ||
/** | ||
* @description Extended config options for @svgr-rs/core, load custom svgo implementation | ||
*/ | ||
svgoImplementation?: any | ||
// svgoConfig is hidden in @svgr-rs/core | ||
svgoConfig?: any | ||
} |