Skip to content

Commit 5916c72

Browse files
committed
Compatibility with webpack v2
1 parent 4f53eb1 commit 5916c72

16 files changed

+3571
-93
lines changed

.editorconfig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
root = true
66

77
[*]
8+
9+
# Change these settings to your own preference
10+
indent_style = space
11+
indent_size = 2
12+
13+
# We recommend you to keep these unchanged
814
end_of_line = lf
915
charset = utf-8
1016
trim_trailing_whitespace = true
1117
insert_final_newline = true
12-
indent_style = space
13-
indent_size = 2

.eslintrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"extends": "airbnb",
3+
"env": {
4+
"browser": true,
5+
"node": true,
6+
"es6": true
7+
},
8+
"rules": {
9+
"comma-dangle": ["error", {
10+
"arrays": "always-multiline",
11+
"objects": "always-multiline",
12+
"imports": "always-multiline",
13+
"exports": "always-multiline",
14+
"functions": "never"
15+
}],
16+
"no-console": ["error", { "allow": ["warn", "error", "info", "assert"] }],
17+
"quotes": ["error", "single", { "allowTemplateLiterals": true }],
18+
"react/jsx-filename-extension": "off"
19+
}
20+
}

.gitignore

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
# Include your project-specific ignores in this file
2+
# Read about how to use .gitignore: https://help.github.com/articles/ignoring-files
3+
14
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5+
npm-debug.log
6+
yarn-error.log
57

6-
# Compiled binary addons (http://nodejs.org/api/addons.html)
8+
# Compiled addons (http://nodejs.org/api/addons.html)
9+
coverage
710
build
811

912
# Dependency directory

.travis.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
language: node_js
22
sudo: false
33
node_js:
4-
- stable
4+
- '7'
5+
- '6'
56
install:
6-
- npm install
7+
- yarn install
78
script:
8-
- npm test
9+
- yarn run lint
10+
- yarn run test:cover
11+
after_success:
12+
- yarn run coveralls

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Vladimir Kutepov
3+
Copyright (c) 2015-present Vladimir Kutepov
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
# svg-to-jsx-loader
22

3-
[Webpack](http://webpack.github.io/) loader that allows to load SVG files as [stateless functional](https://facebook.github.io/react/blog/2015/10/07/react-v0.14.html#stateless-functional-components) [React](http://facebook.github.io/react/) components with [svg-to-jsx](https://github.com/janjakubnanista/svg-to-jsx).
3+
[Webpack](https://webpack.js.org/) loader that allows to load SVG files as [stateless functional](https://facebook.github.io/react/blog/2015/10/07/react-v0.14.html#stateless-functional-components) [React](http://facebook.github.io/react/) components with [svg-to-jsx](https://github.com/janjakubnanista/svg-to-jsx).
44

5-
[![Build Status](https://travis-ci.org/frenzzy/svg-to-jsx-loader.svg?branch=master)](https://travis-ci.org/frenzzy/svg-to-jsx-loader)
5+
[![NPM version](http://img.shields.io/npm/v/svg-to-jsx-loader.svg?style=flat-square)](https://www.npmjs.com/package/svg-to-jsx-loader)
6+
[![NPM downloads](http://img.shields.io/npm/dm/svg-to-jsx-loader.svg?style=flat-square)](https://www.npmjs.com/package/svg-to-jsx-loader)
7+
[![Build Status](http://img.shields.io/travis/frenzzy/svg-to-jsx-loader/master.svg?style=flat-square)](https://travis-ci.org/frenzzy/svg-to-jsx-loader)
8+
[![Coverage Status](https://img.shields.io/coveralls/frenzzy/svg-to-jsx-loader.svg?style=flat-square)](https://coveralls.io/github/frenzzy/svg-to-jsx-loader)
9+
[![Dependency Status](http://img.shields.io/david/frenzzy/svg-to-jsx-loader.svg?style=flat-square)](https://david-dm.org/frenzzy/svg-to-jsx-loader)
610

711
## Installation
812

13+
Using [npm](https://www.npmjs.com/):
14+
915
```shell
1016
$ npm install svg-to-jsx-loader --save-dev
1117
```
1218

1319
## Usage
1420

15-
Webpack documentation: [Using loaders](http://webpack.github.io/docs/using-loaders.html)
21+
Webpack documentation: [Using loaders](https://webpack.js.org/concepts/loaders/)
1622

17-
In your `webpack.config.js`, add the `svg-to-jsx-loader`, chained with the [`babel-loader`](https://babeljs.io/docs/setup/#webpack):
23+
In your `webpack.config.js`, add the `svg-to-jsx-loader`, chained with the [`babel-loader`](https://babeljs.io/docs/setup/#webpack2):
1824

1925
```js
20-
loaders: [
26+
rules: [
2127
{
2228
test: /\.svg$/,
2329
loaders: [
@@ -31,14 +37,13 @@ loaders: [
3137
Or you can find a working example in [test/webpack.config.js](https://github.com/frenzzy/svg-to-jsx-loader/blob/master/test/webpack.config.js) file:
3238

3339
```js
34-
loaders: [
40+
rules: [
3541
{
3642
test: /\.(js|svg)$/i,
3743
loader: 'babel-loader', // v6 or later
3844
exclude: /node_modules/,
3945
query: {
40-
presets: ['react', 'es2015'],
41-
plugins: ['transform-runtime']
46+
presets: ['react']
4247
}
4348
},
4449
{
@@ -52,7 +57,7 @@ loaders: [
5257

5358
```svg
5459
<?xml version="1.0" encoding="iso-8859-1"?>
55-
<!-- forward-icon.svg -->
60+
<!-- 001-forward-icon.svg -->
5661
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 24 24" width="24" height="24">
5762
<path d="M21 11l-7-7v4C7 9 4 14 3 19c2.5-3.5 6-5.1 11-5.1V18l7-7z"/>
5863
</svg>
@@ -63,11 +68,13 @@ loaders: [
6368
```js
6469
import React from 'react';
6570

66-
const ForwardIcon = (props) => (
67-
<svg height="24" width="24" version="1.1" viewBox="0 0 24 24" {...props}>
68-
<path d="M21 11l-7-7v4C7 9 4 14 3 19c2.5-3.5 6-5.1 11-5.1V18l7-7z"/>
69-
</svg>
70-
);
71+
function ForwardIcon(props) {
72+
return (
73+
<svg height="24" width="24" version="1.1" viewBox="0 0 24 24" {...props}>
74+
<path d="M21 11l-7-7v4C7 9 4 14 3 19c2.5-3.5 6-5.1 11-5.1V18l7-7z"/>
75+
</svg>
76+
);
77+
}
7178

7279
export default ForwardIcon;
7380
```

index.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
1-
var svgtojsx = require('svg-to-jsx');
2-
var path = require('path');
1+
const path = require('path');
2+
const svgToJsx = require('svg-to-jsx');
33

44
function toUpperCamelCase(string) {
5-
return string.split(/[^a-zA-Z]+/).map(function (str) {
6-
return str[0].toUpperCase() + str.slice(1);
7-
}).join('');
5+
return string.split(/[^a-zA-Z]+/).map(word =>
6+
word && word[0].toUpperCase() + word.slice(1)
7+
).join('');
88
}
99

10-
module.exports = function (content) {
10+
module.exports = function loader(content) {
1111
this.cacheable();
1212

13-
var callback = this.async();
14-
var fileName = path.basename(this.resourcePath, '.svg');
15-
var componentName = toUpperCamelCase(fileName) || 'Svg';
13+
const callback = this.async();
14+
const fileName = path.basename(this.resourcePath, '.svg');
15+
const componentName = toUpperCamelCase(fileName) || 'Svg';
1616

17-
svgtojsx(content, function (err, jsx) {
18-
if (err) return callback(err);
17+
svgToJsx(content, (err, jsx) => {
18+
if (err) {
19+
callback(err);
20+
return;
21+
}
1922

2023
callback(null,
21-
'import React from \'react\';\n\n' +
24+
`import React from 'react';\n` +
2225

23-
'const ' + componentName + ' = (props) => (' +
24-
jsx.replace(/(<svg[^>]*)(>)/i, '$1 {...props}$2') +
25-
');\n\n' +
26+
`function ${componentName}(props) {` +
27+
` return (${jsx.replace(/(<svg[^>]*)(>)/i, '$1 {...props}$2')});` +
28+
`}\n` +
2629

27-
'export default ' + componentName + ';\n'
30+
`export default ${componentName};`
2831
);
2932
});
3033
};

package.json

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
{
22
"name": "svg-to-jsx-loader",
3-
"version": "1.1.0",
3+
"version": "2.0.0",
44
"description": "SVG to JSX loader module for webpack",
55
"author": "Vladimir Kutepov",
66
"license": "MIT",
77
"homepage": "https://github.com/frenzzy/svg-to-jsx-loader#readme",
88
"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-
},
9+
"repository": "frenzzy/svg-to-jsx-loader",
1610
"keywords": [
1711
"WebPack",
1812
"Loader",
@@ -22,20 +16,29 @@
2216
"Babel"
2317
],
2418
"dependencies": {
25-
"svg-to-jsx": "0.0.13"
19+
"svg-to-jsx": "0.0.20"
2620
},
2721
"devDependencies": {
28-
"babel-core": "^6.3.13",
29-
"babel-loader": "^6.2.0",
30-
"babel-plugin-transform-runtime": "^6.3.13",
31-
"babel-preset-es2015": "^6.3.13",
32-
"babel-preset-react": "^6.3.13",
33-
"html-webpack-plugin": "^1.7.0",
34-
"react": "^0.14.3",
35-
"react-dom": "^0.14.3",
36-
"webpack": "^1.12.9"
22+
"babel-core": "^6.24.1",
23+
"babel-loader": "^7.0.0",
24+
"babel-preset-react": "^6.24.1",
25+
"coveralls": "^2.13.1",
26+
"eslint": "^3.19.0",
27+
"eslint-config-airbnb": "^14.1.0",
28+
"eslint-plugin-import": "^2.2.0",
29+
"eslint-plugin-jsx-a11y": "^4.0.0",
30+
"eslint-plugin-react": "^6.10.3",
31+
"html-webpack-plugin": "^2.28.0",
32+
"istanbul": "1.1.0-alpha.1",
33+
"react": "^15.5.4",
34+
"react-dom": "^15.5.4",
35+
"rimraf": "^2.6.1",
36+
"webpack": "^2.4.1"
3737
},
3838
"scripts": {
39-
"test": "webpack --config test/webpack.config.js"
39+
"lint": "eslint index.js test",
40+
"test": "node test/webpack.config.js",
41+
"test:cover": "istanbul cover test/webpack.config.js",
42+
"coveralls": "cat coverage/lcov.info | coveralls"
4043
}
4144
}

test/001-forward-icon.svg

Lines changed: 5 additions & 0 deletions
Loading

test/002-f0rward-ic0n.svg

Lines changed: 5 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)