From 94251925655cdb3fe804ae35027b7dae3a3b9804 Mon Sep 17 00:00:00 2001 From: Jay Jaeho Lee Date: Fri, 16 Sep 2016 18:56:23 +0700 Subject: [PATCH 01/15] 0.7.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 35e23f0..050f6f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svg-inline-loader", - "version": "0.6.1", + "version": "0.7.0", "description": "Cleans up and inlines your SVG files into Webpack module.", "main": "index.js", "scripts": { From 5bc999e53cec2d529664b56ee324f78eb8de4277 Mon Sep 17 00:00:00 2001 From: Richard Date: Sun, 25 Sep 2016 17:08:50 +0200 Subject: [PATCH 02/15] add missing idPrefix as default value to config, close #36 --- config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/config.js b/config.js index 9c65dcf..993e670 100644 --- a/config.js +++ b/config.js @@ -9,4 +9,5 @@ module.exports = { ], removingTagAttrs: [], classPrefix: false, + idPrefix: false, }; From ca7ef2da4595cb5e0900f331d3e8464ad3292374 Mon Sep 17 00:00:00 2001 From: Jay Jaeho Lee Date: Wed, 28 Sep 2016 18:43:30 +0900 Subject: [PATCH 03/15] 0.7.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 050f6f5..48444f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svg-inline-loader", - "version": "0.7.0", + "version": "0.7.1", "description": "Cleans up and inlines your SVG files into Webpack module.", "main": "index.js", "scripts": { From 2ffa1c01cdc286015f219e881c70b557ea7f85c7 Mon Sep 17 00:00:00 2001 From: nick serebrennikov Date: Wed, 28 Sep 2016 22:36:38 +0300 Subject: [PATCH 04/15] warnTags and warnTagAttrs --- README.md | 11 ++++++++++ config.js | 2 ++ index.js | 2 +- karma.conf.js | 12 +++++------ lib/conditions.js | 7 +++++++ lib/transformer.js | 35 ++++++++++++++++++++++++++++++-- package.json | 1 + tests/svg-inline-loader.test.js | 36 ++++++++++++++++++++++++++++++++- 8 files changed, 96 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 19b6eeb..8866c5b 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,12 @@ warning: this won't work unless you specify `removeTags: true` default: `removingTags: ['title', 'desc', 'defs', 'style']` +#### `warnTags: [...string]` + +warns about tags, ex: ['title', 'desc', 'defs', 'style'] + +default: `warnTags: []` + #### `removeSVGTagAttrs: boolean` Removes `width` and `height` attributes from ``. @@ -43,6 +49,11 @@ Removes attributes from inside the ``. default: `removingTagAttrs: []` +#### `warnTagAttrs: [...string]` + +Warns to console about attributes from inside the ``. + +default: `warnTagAttrs: []` #### `classPrefix: boolean || string` Adds a prefix to class names to avoid collision across svg files. diff --git a/config.js b/config.js index 993e670..5dde54f 100644 --- a/config.js +++ b/config.js @@ -10,4 +10,6 @@ module.exports = { removingTagAttrs: [], classPrefix: false, idPrefix: false, + warnTags: [], + warnTagAttrs: [] }; diff --git a/index.js b/index.js index 419ff36..73cc790 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,7 @@ var regexSequences = [ // SVG XML -> HTML5 [/\<([A-Za-z]+)([^\>]*)\/\>/g, "<$1$2>"], // convert self-closing XML SVG nodes to explicitly closed HTML5 SVG nodes [/\s+/g, " "], // replace whitespace sequences with a single space - [/\> \<"], // remove whitespace between tags + [/\> \<"] // remove whitespace between tags ]; function getExtractedSVG(svgStr, query) { diff --git a/karma.conf.js b/karma.conf.js index 352f746..e830121 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -6,8 +6,8 @@ var webpackConf = { loaders: [ { test: /\.json$/, - loaders: ['json'], - }, + loaders: ['json'] + } ] }, entry: [ @@ -15,7 +15,7 @@ var webpackConf = { ], resolve: { extensions: ["", ".js", ".jsx"], - }, + } }; module.exports = function(config) { @@ -23,11 +23,11 @@ module.exports = function(config) { basePath: '.', frameworks: ['mocha'], files: [ - './tests/**/*.js', + './tests/**/*.js' ], exclude: [], preprocessors: { - './tests/**/*.js': ['webpack'], + './tests/**/*.js': ['webpack'] }, reporters: ['spec'], port: 9876, @@ -39,7 +39,7 @@ module.exports = function(config) { 'karma-spec-reporter', 'karma-mocha', 'karma-chrome-launcher', - 'karma-webpack', + 'karma-webpack' ], webpack: webpackConf, autoWatch: true, diff --git a/lib/conditions.js b/lib/conditions.js index 8f049fa..9157319 100644 --- a/lib/conditions.js +++ b/lib/conditions.js @@ -26,11 +26,18 @@ function createHasNoAttributes(attributes) { } } +function createHasAttributes(attributes) { + return function hasAttributes(attributeToken) { + return attributes.indexOf(attributeToken[0]) > -1; + } +} + module.exports = { isSVGToken: isSVGToken, isStyleToken: isStyleToken, isFilledObject: isFilledObject, hasNoWidthHeight: hasNoWidthHeight, createHasNoAttributes: createHasNoAttributes, + createHasAttributes: createHasAttributes, isStartTag: isStartTag }; diff --git a/lib/transformer.js b/lib/transformer.js index 989df92..2063335 100644 --- a/lib/transformer.js +++ b/lib/transformer.js @@ -20,11 +20,30 @@ function createRemoveTagAttrs(removingTagAttrs) { return tag; }; } - +function createWarnTagAttrs(warnTagAttrs) { + warnTagAttrs = warnTagAttrs || []; + var hasNoAttributes = conditions.createHasAttributes(warnTagAttrs); + return function warnTagAttrs(tag) { + if (conditions.isStartTag(tag)) { + var attrs=tag.attributes.filter(hasNoAttributes); + if(attrs.length > 0) { + var attrList=[]; + for(var i=0;i -1; } - +function isWarningTag(warningTags, tag) { + return warningTags.indexOf(tag.tagName) > -1; +} // FIXME: Due to limtation of parser, we need to implement our // very own little state machine to express tree structure @@ -46,6 +65,16 @@ function createRemoveTags(removingTags) { }; } +function createWarnTags(warningTags) { + warningTags = warningTags || []; + + return function warnTags(tag) { + if (conditions.isStartTag(tag) && isWarningTag(warningTags, tag)) { + console.warn('svg-inline-loader: forbidden tag ' + tag.tagName); + } + return tag; + }; +} function getAttributeIndex (tag, attr) { if( tag.attributes !== undefined && tag.attributes.length > 0 ) { for(var i = 0; i < tag.attributes.length; i++) { @@ -131,7 +160,9 @@ function runTransform(tokens, configOverride) { if (config.classPrefix !== false) transformations.push(createClassPrefix(config.classPrefix)); if (config.idPrefix !== false) transformations.push(createIdPrefix(config.idPrefix)); if (config.removeSVGTagAttrs === true) transformations.push(removeSVGTagAttrs); + if (config.warnTags.length > 0) transformations.push(createWarnTags(config.warnTags)); if (config.removeTags === true) transformations.push(createRemoveTags(config.removingTags)); + if (config.warnTagAttrs.length > 0) transformations.push(createWarnTagAttrs(config.warnTagAttrs)); if (config.removingTagAttrs.length > 0) transformations.push(createRemoveTagAttrs(config.removingTagAttrs)); transformations.forEach(function (transformation) { diff --git a/package.json b/package.json index 48444f8..4adcf7d 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ }, "devDependencies": { "chai": "^3.0.0", + "chai-spies": "^0.7.1", "json-loader": "^0.5.4", "karma": "^1.0.0", "karma-chrome-launcher": "^1.0.1", diff --git a/tests/svg-inline-loader.test.js b/tests/svg-inline-loader.test.js index 977d17f..676440c 100644 --- a/tests/svg-inline-loader.test.js +++ b/tests/svg-inline-loader.test.js @@ -2,7 +2,12 @@ var simpleHTMLTokenizer = require('simple-html-tokenizer'); var tokenize = simpleHTMLTokenizer.tokenize; var SVGInlineLoader = require('../index'); -var assert = require('chai').assert; +var chai = require('chai'); +var assert = chai.assert; +var expect = chai.expect; +var spies = require('chai-spies'); +chai.use(spies); +var createSpy = chai.spy; var _ = require('lodash'); var svgWithRect = require('raw!./fixtures/xml-rect.svg'); @@ -117,5 +122,34 @@ describe('getExtractedSVG()', function(){ } }); }); + it('should be able to warn about tagsAttrs to be removed listed in `warnTagAttrs` option via console.log', function () { + var svg = require('raw!./fixtures/with-ids.svg'); + var tobeWarned = ['id']; + var oldConsoleWarn = console.warn; + var warnings=[]; + console.warn=createSpy(function (str) { + warnings.push(str); + }); + var processedSVG = SVGInlineLoader.getExtractedSVG(svg, { warnTagAttrs: tobeWarned }); + var reTokenizedSVG = tokenize(processedSVG); + expect(console.warn).to.have.been.called.with('svg-inline-loader: tag path has forbidden attrs: id'); + console.warn = oldConsoleWarn; // reset console back + }); + it('should be able to specify tags to be warned about by `warnTags` option', function () { + var svg = require('raw!./fixtures/removing-tags.svg'); + var tobeWarnedAbout = ['title', 'desc', 'defs', 'style', 'image']; + var oldConsoleWarn = console.warn; + var warnings=[]; + console.warn=createSpy(function (str) { + warnings.push(str); + }); + var processedStyleInsertedSVG = SVGInlineLoader.getExtractedSVG(svg, { warnTags: tobeWarnedAbout }); + var reTokenizedStyleInsertedSVG = tokenize(processedStyleInsertedSVG); + + expect(console.warn).to.have.been.called(); + expect(console.warn).to.have.been.called.min(3); + expect(console.warn).to.have.been.called.with('svg-inline-loader: forbidden tag style'); + console.warn = oldConsoleWarn; // reset console back + }); }); From 6a2fb4a3b9101321ddc732f7ae1d9ddad276d203 Mon Sep 17 00:00:00 2001 From: Nick Serebrennikov Date: Thu, 29 Sep 2016 09:50:50 +0300 Subject: [PATCH 05/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8866c5b..2f70657 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ default: `removingTags: ['title', 'desc', 'defs', 'style']` #### `warnTags: [...string]` -warns about tags, ex: ['title', 'desc', 'defs', 'style'] +warns about tags, ex: ['desc', 'defs', 'style'] default: `warnTags: []` From 779f77ec915f1218cce636cfa8d62ed58abbf317 Mon Sep 17 00:00:00 2001 From: alok pepakayala Date: Tue, 18 Oct 2016 18:19:13 +0530 Subject: [PATCH 06/15] multiple classes in class string fix Multiple classses in class attribute not prefixed when using classPrefix --- lib/transformer.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/transformer.js b/lib/transformer.js index 989df92..99bbae8 100644 --- a/lib/transformer.js +++ b/lib/transformer.js @@ -83,7 +83,17 @@ function createClassPrefix(classPrefix) { else { var classIdx = getAttributeIndex(tag,'class'); if(classIdx >= 0) { - tag.attributes[classIdx][1] = classPrefix + tag.attributes[classIdx][1]; + //Prefix classes when multiple classes are present + var classes = tag.attributes[classIdx][1]; + var prefixedClassString = ""; + + classes = classes.replace(/[ ]+/,' '); + classes = classes.split(' '); + classes.forEach(function(classI){ + prefixedClassString += classPrefix + classI + ' '; + }); + + tag.attributes[classIdx][1] = prefixedClassString; } } return tag; From 851316af0af90c546cdd9ff37ec74cd88e606cfc Mon Sep 17 00:00:00 2001 From: alok pepakayala Date: Sat, 22 Oct 2016 03:36:26 +0530 Subject: [PATCH 07/15] Fix #41 corrupted css properties in style tag For CSS properties that contain '.' in the value. --- lib/transformer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/transformer.js b/lib/transformer.js index 99bbae8..2326c95 100644 --- a/lib/transformer.js +++ b/lib/transformer.js @@ -58,7 +58,8 @@ function getAttributeIndex (tag, attr) { } function createClassPrefix(classPrefix) { - var re = /\.[\w\-]+/g; + //http://stackoverflow.com/questions/12391760/regex-match-css-class-name-from-single-string-containing-multiple-classes + var re = /\.(-?[_a-zA-Z]+[_a-zA-Z0-9-]*)(?![^\{]*\})/g; var inStyleTag = false; return function prefixClasses(tag) { From 9b4e8a39464a867cb5c7f5547a2f0cac6081b9fd Mon Sep 17 00:00:00 2001 From: Andrew Gerard Date: Fri, 18 Nov 2016 16:28:47 -0700 Subject: [PATCH 08/15] [fix] don't transform webpack2 query objects --- index.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 419ff36..752877b 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ var simpleHTMLTokenizer = require('simple-html-tokenizer'); var tokenize = simpleHTMLTokenizer.tokenize; var generate = simpleHTMLTokenizer.generate; var loaderUtils = require('loader-utils'); +var assign = require('object-assign'); var conditions = require('./lib/conditions'); var transformer = require('./lib/transformer'); @@ -20,15 +21,20 @@ var regexSequences = [ ]; function getExtractedSVG(svgStr, query) { + var config; // interpolate hashes in classPrefix - if(!!query && !!query.classPrefix) { - const name = query.classPrefix === true ? '__[hash:base64:7]__' : query.classPrefix; - query.classPrefix = loaderUtils.interpolateName({}, name, {content: svgStr}); - } + if(!!query) { + config = assign({}, query); + + if (!!config.classPrefix) { + const name = config.classPrefix === true ? '__[hash:base64:7]__' : config.classPrefix; + config.classPrefix = loaderUtils.interpolateName({}, name, { content: svgStr }); + } - if (!!query && !!query.idPrefix) { - const id_name = query.idPrefix === true ? '__[hash:base64:7]__' : query.idPrefix; - query.idPrefix = loaderUtils.interpolateName({}, id_name, {content: svgStr}); + if (!!config.idPrefix) { + const id_name = config.idPrefix === true ? '__[hash:base64:7]__' : config.idPrefix; + config.idPrefix = loaderUtils.interpolateName({}, id_name, { content: svgStr }); + } } // Clean-up XML crusts like comments and doctype, etc. @@ -47,7 +53,7 @@ function getExtractedSVG(svgStr, query) { } // If the token is start-tag, then remove width and height attributes. - return generate(transformer.runTransform(tokens, query)); + return generate(transformer.runTransform(tokens, config)); } function SVGInlineLoader(content) { From 4a0e589669c9d7dc667caac24df8effeb096c260 Mon Sep 17 00:00:00 2001 From: Stuart Knightley Date: Fri, 27 Jan 2017 13:40:21 -0800 Subject: [PATCH 09/15] Add license file --- LICENSE | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ba47863 --- /dev/null +++ b/LICENSE @@ -0,0 +1,18 @@ +Copyright 2015-2017 Jaeho Lee + +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 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. From 7183d48aacafc1e5f705cb9c9c36e3b2cee39ebd Mon Sep 17 00:00:00 2001 From: Jaeho Lee Date: Tue, 7 Mar 2017 16:28:06 +0900 Subject: [PATCH 10/15] Update license to js foundation license (fixes #49) --- LICENSE | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/LICENSE b/LICENSE index ba47863..8c11fc7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,18 +1,20 @@ -Copyright 2015-2017 Jaeho Lee +Copyright JS Foundation and other contributors -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. From 4d34db6490787f2b8f1ae46b1da18769eba990a9 Mon Sep 17 00:00:00 2001 From: Joshua Wiens Date: Tue, 7 Mar 2017 01:58:35 -0600 Subject: [PATCH 11/15] docs(readme): contrib standard readme (#50) --- README.md | 90 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 76 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 2f70657..a9d8e2d 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,27 @@ -**NOTICE [2016-06-26]: I'm not using or developing this lib anymore. Therefore I'm closing issues (which I cannot handle anymore), but you can send PR to improve or fix problems you facing with this lib.** - -# SVG Inline Loader for Webpack - -This Webpack loader inlines SVG as module. If you use Adobe suite or Sketch to export SVGs, you will get auto-generated, unneeded crusts. This loader removes it for you, too. +[![npm][npm]][npm-url] +[![deps][deps]][deps-url] +[![test][test]][test-url] +[![coverage][cover]][cover-url] +[![quality][quality]][quality-url] +[![chat][chat]][chat-url] + +
+ + + + +

SVG Inline Loader for Webpack

+

This Webpack loader inlines SVG as module. If you use Adobe suite or Sketch to export SVGs, you will get auto-generated, unneeded crusts. This loader removes it for you, too.

+

+ +

Install

+ +```bash +npm install svg-inline-loader --save-dev +``` -## Config +

Configuration

Simply add configuration object to `module.loaders` like this. @@ -15,9 +32,9 @@ Simply add configuration object to `module.loaders` like this. } ``` -warning: You should configure this loader only once via `module.loaders` or `require('!...')`. See [#15](https://github.com/sairion/svg-inline-loader/issues/15) for detail. +warning: You should configure this loader only once via `module.loaders` or `require('!...')`. See [#15](https://github.com/webpack-contrib/svg-inline-loader/issues/15) for detail. -### query options +

Query Options

#### `removeTags: boolean` @@ -66,8 +83,8 @@ Adds a prefix to ids to avoid collision across svg files. default: `idPrefix: false` +

Example Usage

-##### Example Usage ```js // Using default hashed prefix (__[hash:base64:7]__) var logoTwo = require('svg-inline?classPrefix!./logo_two.svg'); @@ -88,8 +105,53 @@ Preferred usage is via a `module.loaders`: } ``` -## Notes - -- `` React Component is **DEPRECATED**, use `svg-inline-react` package instead. -- Known problems: - - currently inlining SVG in css is unable. See #22 +

Maintainers

+ + + + + + + + + + +
+ +
+ Juho Vepsäläinen +
+ +
+ Joshua Wiens +
+ +
+ Kees Kluskens +
+ +
+ Sean Larkin +
+ +[npm]: https://img.shields.io/npm/v/svg-inline-loader.svg +[npm-url]: https://npmjs.com/package/svg-inline-loader + +[deps]: https://david-dm.org/webpack-contrib/svg-inline-loader.svg +[deps-url]: https://david-dm.org/webpack-contrib/svg-inline-loader + +[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg +[chat-url]: https://gitter.im/webpack/webpack + +[test]: https://travis-ci.org/webpack-contrib/svg-inline-loader.svg?branch=master +[test-url]: https://travis-ci.org/webpack-contrib/svg-inline-loader + +[cover]: https://codecov.io/gh/webpack-contrib/svg-inline-loader/branch/master/graph/badge.svg +[cover-url]: https://codecov.io/gh/webpack-contrib/svg-inline-loader + +[quality]: https://www.bithound.io/github/webpack-contrib/svg-inline-loader/badges/score.svg +[quality-url]: https://www.bithound.io/github/webpack-contrib/svg-inline-loader From 41fd170b827ea1d5f74ced5b69a765058cd4df00 Mon Sep 17 00:00:00 2001 From: Joshua Wiens Date: Tue, 7 Mar 2017 01:59:15 -0600 Subject: [PATCH 12/15] docs(readme): remove bithound badge --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index a9d8e2d..b041b11 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![deps][deps]][deps-url] [![test][test]][test-url] [![coverage][cover]][cover-url] -[![quality][quality]][quality-url] [![chat][chat]][chat-url]
@@ -152,6 +151,3 @@ Preferred usage is via a `module.loaders`: [cover]: https://codecov.io/gh/webpack-contrib/svg-inline-loader/branch/master/graph/badge.svg [cover-url]: https://codecov.io/gh/webpack-contrib/svg-inline-loader - -[quality]: https://www.bithound.io/github/webpack-contrib/svg-inline-loader/badges/score.svg -[quality-url]: https://www.bithound.io/github/webpack-contrib/svg-inline-loader From 162af5b75d9faf82c539430d9147dea9cf0c07cd Mon Sep 17 00:00:00 2001 From: Jaeho Lee Date: Thu, 30 Mar 2017 03:31:24 +0900 Subject: [PATCH 13/15] docs: Update usage documentation (#54) closes #53 --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b041b11..5285eb5 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Simply add configuration object to `module.loaders` like this. ```javascript { test: /\.svg$/, - loader: 'svg-inline' + loader: 'svg-inline-loader' } ``` @@ -86,13 +86,13 @@ default: `idPrefix: false` ```js // Using default hashed prefix (__[hash:base64:7]__) -var logoTwo = require('svg-inline?classPrefix!./logo_two.svg'); +var logoTwo = require('svg-inline-loader?classPrefix!./logo_two.svg'); // Using custom string -var logoOne = require('svg-inline?classPrefix=my-prefix-!./logo_one.svg'); +var logoOne = require('svg-inline-loader?classPrefix=my-prefix-!./logo_one.svg'); // Using custom string and hash -var logoThree = require('svg-inline?classPrefix=__prefix-[sha512:hash:hex:5]__!./logo_three.svg'); +var logoThree = require('svg-inline-loader?classPrefix=__prefix-[sha512:hash:hex:5]__!./logo_three.svg'); ``` See [loader-utils](https://github.com/webpack/loader-utils#interpolatename) for hash options. @@ -100,7 +100,7 @@ Preferred usage is via a `module.loaders`: ```js { test: /\.svg$/, - loader: 'svg-inline?classPrefix' + loader: 'svg-inline-loader?classPrefix' } ``` From 36a3eb0c8634d26e2123e34a2433efd4f5883f3a Mon Sep 17 00:00:00 2001 From: Omri Gilad Date: Tue, 6 Jun 2017 18:13:12 +0300 Subject: [PATCH 14/15] add raw mode support --- index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 584d278..1558352 100644 --- a/index.js +++ b/index.js @@ -62,7 +62,13 @@ function SVGInlineLoader(content) { // Configuration var query = loaderUtils.parseQuery(this.query); - return "module.exports = " + JSON.stringify(getExtractedSVG(content, query)); + var extractedSVG = getExtractedSVG(content, query); + + if (query.raw) { + return extractedSVG; + } else { + return "module.exports = " + JSON.stringify(extractedSVG); + } } SVGInlineLoader.getExtractedSVG = getExtractedSVG; From 4e9bd4006586e67e7d1c1c234b5a0a0b40be2cc5 Mon Sep 17 00:00:00 2001 From: Omri Gilad Date: Tue, 6 Jun 2017 18:16:46 +0300 Subject: [PATCH 15/15] add documentation for raw option --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 5285eb5..1e3d4ba 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,13 @@ Adds a prefix to ids to avoid collision across svg files. default: `idPrefix: false` +#### `raw: boolean` + +Returns the content of the cleaned up SVG as a string instead of a module. Useful if you plan on passing +the output on to file-loader, etc. + +default: `raw: false` +

Example Usage

```js