Skip to content

Commit 3e8c586

Browse files
committed
Initial commit
0 parents  commit 3e8c586

File tree

5 files changed

+144
-0
lines changed

5 files changed

+144
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Dependency directory
2+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
3+
node_modules

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Vladimir Kutepov
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# svg-to-jsx-loader
2+
3+
Simple [Webpack](http://webpack.github.io/) loader that allows to load SVG files as [React](http://facebook.github.io/react/) components with [svg-to-jsx](https://github.com/janjakubnanista/svg-to-jsx).
4+
5+
## Installation
6+
7+
```shell
8+
$ npm install svg-to-jsx-loader --save-dev
9+
```
10+
11+
## Usage
12+
13+
Webpack documentation: [Using loaders](http://webpack.github.io/docs/using-loaders.html)
14+
15+
In your `webpack.config.js`, add the `svg-to-jsx-loader`, chained with the [`babel-loader`](https://babeljs.io/docs/setup/#webpack):
16+
17+
```js
18+
loaders: [
19+
{
20+
test: /\.svg$/,
21+
loaders: [
22+
'babel-loader',
23+
'svg-to-jsx-loader'
24+
]
25+
}
26+
]
27+
```
28+
29+
### Input example
30+
31+
```svg
32+
<!-- forward-icon.svg -->
33+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
34+
<path d="M21 11l-7-7v4C7 9 4 14 3 19c2.5-3.5 6-5.1 11-5.1V18l7-7z"/>
35+
</svg>
36+
```
37+
38+
### Output example
39+
40+
```js
41+
import React from 'react';
42+
43+
class Svg extends React.Component {
44+
render() {
45+
return (
46+
<svg width="24" height="24" viewBox="0 0 24 24" {...this.props}>
47+
<path d="M21 11l-7-7v4C7 9 4 14 3 19c2.5-3.5 6-5.1 11-5.1V18l7-7z"/>
48+
</svg>
49+
);
50+
}
51+
};
52+
53+
export default Svg;
54+
```
55+
56+
## Inspiration
57+
58+
- [svg-jsx-loader](https://github.com/janjakubnanista/svg-jsx-loader)
59+
- [react-svg-loader](https://github.com/boopathi/react-svg-loader)
60+
- [svg-to-jsx](https://github.com/janjakubnanista/svg-to-jsx)
61+
62+
## License
63+
64+
MIT (http://www.opensource.org/licenses/mit-license.php)

index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var svgtojsx = require('svg-to-jsx');
2+
3+
module.exports = function (content) {
4+
this.cacheable && this.cacheable();
5+
6+
var callback = this.async();
7+
8+
svgtojsx(content, {passProps: true}, function (err, jsx) {
9+
if (err) {
10+
callback(err);
11+
} else {
12+
callback(null,
13+
'import React from "react";' +
14+
15+
'class Svg extends React.Component {' +
16+
' render() {' +
17+
' return (' + jsx + ');' +
18+
' }' +
19+
'};' +
20+
21+
'export default Svg;'
22+
);
23+
}
24+
});
25+
};
26+
27+
module.exports.raw = true;

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "svg-to-jsx-loader",
3+
"version": "1.0.0",
4+
"description": "SVG to JSX loader module for webpack",
5+
"author": "Vladimir Kutepov",
6+
"license": "MIT",
7+
"homepage": "https://github.com/frenzzy/svg-to-jsx-loader#readme",
8+
"main": "index.js",
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/frenzzy/svg-to-jsx-loader.git"
12+
},
13+
"bugs": {
14+
"url": "https://github.com/frenzzy/svg-to-jsx-loader/issues"
15+
},
16+
"keywords": [
17+
"WebPack",
18+
"Loader",
19+
"SVG",
20+
"JSX",
21+
"React"
22+
],
23+
"dependencies": {
24+
"svg-to-jsx": "0.0.13"
25+
},
26+
"scripts": {
27+
"test": "echo \"Error: no test specified\" && exit 1"
28+
}
29+
}

0 commit comments

Comments
 (0)