This repository has been archived by the owner on Jan 24, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docz-plugin-svgr): add initial version of plugin
- Loading branch information
1 parent
011baad
commit 1ac1ea8
Showing
8 changed files
with
888 additions
and
14 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,46 @@ | ||
# docz-plugin-svgr | ||
|
||
This plugin allow you to use [svgr](https://github.com/smooth-code/svgr/tree/master/packages/webpack) as loader for svg images together with default `file-loader` | ||
|
||
## Install | ||
|
||
```bash | ||
$ yarn add docz-plugin-svgr | ||
``` | ||
|
||
## Usage | ||
|
||
Just import the plugin and add it on your `doczrc.js` | ||
|
||
```js | ||
import { svgr } from 'docz-plugin-svgr' | ||
|
||
export default { | ||
plugins: [svgr()] | ||
} | ||
``` | ||
|
||
Then just use named imports to import using svgr | ||
|
||
```jsx | ||
import starUrl, { ReactComponent as Star } from './star.svg' | ||
|
||
const App = () => ( | ||
<div> | ||
<img src={starUrl} alt="star" /> | ||
<Star /> | ||
</div> | ||
) | ||
``` | ||
|
||
## Custom options | ||
|
||
If you want to pass [custom options](https://github.com/smooth-code/svgr/tree/master/packages/webpack#passing-options) for `@svgr/webpack` just pass as first argument of the functio | ||
|
||
```js | ||
import { svgr } from 'docz-plugin-svgr' | ||
|
||
export default { | ||
plugins: [svgr({ native: true })] | ||
} | ||
``` |
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,28 @@ | ||
{ | ||
"name": "docz-plugin-svgr", | ||
"version": "0.8.0", | ||
"description": "Use svgr as loader for svg images", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"umd:main": "dist/index.umd.js", | ||
"module": "dist/index.m.js", | ||
"typings": "dist/index.d.ts", | ||
"source": "src/index.ts", | ||
"files": [ | ||
"dist/", | ||
"package.json", | ||
"README.md" | ||
], | ||
"scripts": { | ||
"dev": "libundler watch --ts -e all", | ||
"build": "libundler build --ts -e all --c", | ||
"fix": "run-s fix:*", | ||
"fix:prettier": "prettier \"src/**/*.{ts,tsx}\" --write", | ||
"fix:tslint": "tslint --fix --project .", | ||
"tslint": "tslint --project ." | ||
}, | ||
"dependencies": { | ||
"@svgr/webpack": "^2.1.1", | ||
"docz-core": "^0.8.0" | ||
} | ||
} |
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,25 @@ | ||
import { createPlugin } from 'docz-core' | ||
|
||
export interface Options { | ||
[key: string]: any | ||
} | ||
|
||
const defaultOptions = { | ||
icon: true, | ||
} | ||
|
||
export const svgr = (options: Options = defaultOptions) => | ||
createPlugin({ | ||
modifyBundlerConfig: config => { | ||
const rule = config.module.rules.find( | ||
(rule: any) => rule.test.toString() === '/\\.(svg)(\\?.*)?$/' | ||
) | ||
|
||
rule.use.unshift({ | ||
loader: '@svgr/webpack', | ||
options, | ||
}) | ||
|
||
return config | ||
}, | ||
}) |
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,12 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"rootDir": "src", | ||
"declaration": true, | ||
"types": ["node"], | ||
"typeRoots": ["node_modules/@types"] | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["node_modules/**"] | ||
} |
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,3 @@ | ||
{ | ||
"extends": "../../tslint.json" | ||
} |
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
Oops, something went wrong.