Skip to content

Commit 9de53bf

Browse files
author
Eduardo García Sanz
committed
working
1 parent 6c0043f commit 9de53bf

2 files changed

Lines changed: 47 additions & 4 deletions

File tree

index.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,43 @@
1-
module.exports = function reactify(filename, options) {
1+
var through = require('through'),
2+
SVGO = require('svgo'),
3+
react = require('react-tools');
24

3-
5+
var isSVG = function (filename) {
6+
7+
return (/\.svg$/i).test(filename);
8+
};
9+
10+
var svgo = new SVGO();
11+
12+
module.exports = function (filename) {
13+
14+
var write = function (buffer) {
15+
16+
data += buffer;
17+
};
18+
19+
var end = function () {
20+
21+
svgo.optimize(data, out);
22+
};
23+
24+
var out = function (svg) {
25+
26+
var source = "var React = require('react');module.exports = React.createClass({render: function () { return (" + svg.data + "); }});",
27+
output = react.transform(source, {
28+
es5 : true,
29+
sourceMap : false,
30+
sourceFilename: filename,
31+
stripTypes : false,
32+
harmony : false
33+
});
34+
35+
stream.queue(output);
36+
stream.queue(null);
37+
};
38+
39+
var data = '',
40+
stream = isSVG(filename) ? through(write, end) : through();
41+
42+
return stream;
443
};

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"homepage" : "https://github.com/coma/svg-reactify",
55
"repository" : "https://github.com/coma/svg-reactify",
66
"main" : "./index.js",
7-
"version" : "0.0.0",
7+
"version" : "0.2.0",
88
"license" : "MIT",
99
"private" : false,
1010
"authors" : [
@@ -16,7 +16,11 @@
1616
"svg",
1717
"browserify-transform"
1818
],
19-
"dependencies" : {},
19+
"dependencies" : {
20+
"through" : "^2.3",
21+
"react-tools": "^0.13",
22+
"svgo" : "^0.5"
23+
},
2024
"devDependencies": {},
2125
"scripts" : {},
2226
"engines" : {}

0 commit comments

Comments
 (0)