-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
756c08d
commit 7177c71
Showing
7 changed files
with
396 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = tab | ||
indent_size = 4 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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,2 @@ | ||
node_modules/* | ||
package-lock.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/* | ||
package-lock.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,7 @@ | ||
MIT License | ||
Copyright 2018 Oliver Findl | ||
|
||
Copyright (c) 2018 Oliver Findl | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,2 +1,130 @@ | ||
|
||
|
||
# vue-svg-inline-loader | ||
Webpack loader used for inline replacement of SVG images with actual content of SVG files in Vue projects. | ||
|
||
[](https://www.npmjs.com/package/vue-svg-inline-loader) | ||
[](https://www.npmjs.com/package/vue-svg-inline-loader) | ||
[](https://www.npmjs.com/package/vue-svg-inline-loader) | ||
[](https://paypal.me/oliverfindl) | ||
|
||
[Webpack](https://github.com/webpack/webpack) loader used for inline replacement of SVG images with actual content of SVG files in [Vue](https://github.com/vuejs/vue) projects. | ||
|
||
> Sprites works only with [Vue](https://github.com/vuejs/vue) [Single File Component](https://vuejs.org/guide/single-file-components.html) approach and only with HTML template format. | ||
> Loader has built-in [SVGO](https://github.com/svg/svgo) support for SVG optimization. | ||
--- | ||
|
||
## Install | ||
|
||
Via [npm](https://npmjs.com/) [[package](https://www.npmjs.com/package/vue-svg-inline-loader)]: | ||
> `npm install vue-svg-inline-loader --save-dev` | ||
Via [yarn](https://yarnpkg.com/en/) [[package](https://yarnpkg.com/en/package/vue-svg-inline-loader)]: | ||
> `yarn add vue-svg-inline-loader --save-dev` | ||
## Usage | ||
|
||
In webpack config: | ||
```javascript | ||
{ | ||
test: /\.vue$/, | ||
use: [ | ||
{ | ||
loader: "vue-svg-inline-loader", | ||
options: { /* ... */ } | ||
}, | ||
// ... | ||
] | ||
} | ||
``` | ||
|
||
Inline replacement: | ||
```html | ||
<img svg-inline class="icon" src="./images/example.svg" alt="example" /> | ||
``` | ||
|
||
Which replaces into inline SVG: | ||
```xml | ||
<svg svg-inline class="icon" role="presentation" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="..."> | ||
<path d="..."></path> | ||
</svg> | ||
``` | ||
|
||
Or if you want to use inline sprites: | ||
```html | ||
<img svg-inline svg-sprite class="icon" src="./images/example.svg" alt="example" /> | ||
``` | ||
|
||
Which replaces into inline SVG using inline sprites: | ||
```xml | ||
<!-- will get injected right after root opening tag in Vue component --> | ||
<div style="display:none!important;"> | ||
<svg> | ||
<symbols> | ||
<symbol id="svg-sprite-example"> | ||
<path d="..."></path> | ||
</symbol> | ||
<!-- ... --> | ||
</symbols> | ||
</svg> | ||
</div> | ||
<!-- ... --> | ||
<!-- later in code --> | ||
<svg svg-inline svg-sprite class="icon" role="presentation" focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="..."> | ||
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#svg-sprite-example"></use> | ||
</svg> | ||
``` | ||
|
||
## Configuration | ||
|
||
Default options: | ||
```javascript | ||
{ | ||
inlineKeyword: "svg-inline", | ||
inlineStrict: true, | ||
spriteKeyword: "svg-sprite", | ||
spriteStrict: true, | ||
removeAttributes: ["alt", "src"], | ||
xhtml: false, | ||
svgo: { | ||
plugins: [ | ||
{ | ||
cleanupAttrs: true | ||
}, | ||
// ... | ||
] | ||
} | ||
} | ||
``` | ||
Explanation: | ||
* **inlineKeyword:** | ||
Defines keyword, which marks images you want to replace with inline SVG. Keyword has to be wrapped with whitespace characters (e.g. space). | ||
In case of some conflicts, you can also use data version of your keyword (e.g. `data-keyword`). | ||
|
||
* **inlineStrict:** | ||
In strict mode loader replaces only images with defined keyword. If strict mode is disabled, loader replaces all images. | ||
|
||
* **spriteKeyword:** | ||
Defines keyword, which marks images you want to replace with inline SVG using inline sprites. Keyword has to be wrapped with whitespace characters (e.g. space). | ||
In case of some conflicts, you can also use data version of your keyword (e.g. `data-keyword`). | ||
|
||
* **spriteStrict:** | ||
In strict mode loader replaces only images with defined keyword. If strict mode is disabled, loader replaces all images. | ||
|
||
* **removeAttributes:** | ||
Array of attributes which will be removed from image tag and won't be transferred to inline SVG replacement. | ||
|
||
* **xhtml:** | ||
In XHTML mode attribute minimization is forbidden. Empty attributes are filled with their names to be XHTML-compliant (e.g. `disabled="disabled"`). | ||
|
||
* **svgo:** | ||
[SVGO](https://github.com/svg/svgo) configuration object. Documentation can be found [here](https://github.com/svg/svgo). | ||
|
||
Notes: User-defined options are not deep-merged with default options. | ||
|
||
--- | ||
|
||
## License | ||
|
||
[MIT](http://opensource.org/licenses/MIT) |
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,34 @@ | ||
{ | ||
"name": "vue-svg-inline-loader", | ||
"version": "1.0.0", | ||
"description": "Webpack loader used for inline replacement of SVG images with actual content of SVG files in Vue projects.", | ||
"main": "src/index.js", | ||
"files": [ | ||
"src/*.js" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/oliverfindl/vue-svg-inline-loader.git" | ||
}, | ||
"keywords": [ | ||
"webpack", | ||
"loader", | ||
"vue", | ||
"svg", | ||
"inline", | ||
"sprites", | ||
"symbols", | ||
"vue-svg-inline-loader" | ||
], | ||
"author": "Oliver Findl", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/oliverfindl/vue-svg-inline-loader/issues" | ||
}, | ||
"homepage": "https://github.com/oliverfindl/vue-svg-inline-loader#readme", | ||
"dependencies": { | ||
"loader-utils": "^1.1.0", | ||
"schema-utils": "^0.4.5", | ||
"svgo": "^1.0.5" | ||
} | ||
} |
Oops, something went wrong.