diff --git a/index.js b/index.js index 72371a9..1d9edad 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,7 @@ class DataUriCompiler { this.config = lodash.defaultsDeep( lodash.cloneDeep(config && config.plugins && config.plugins.datauri || {}), { - pattern: /\.(gif|jpg|png)/ + pattern: /\.(gif|jpg|png|svg)/ } ); @@ -59,7 +59,7 @@ class DataUriCompiler { } DataUriCompiler.prototype.brunchPlugin = true; -DataUriCompiler.prototype.pattern = /\.(gif|jpg|png)/; +DataUriCompiler.prototype.pattern = /\.(gif|jpg|png|svg)/; DataUriCompiler.prototype.type = 'template'; module.exports = DataUriCompiler; diff --git a/test.js b/test.js index ce53fb9..b6b58ff 100644 --- a/test.js +++ b/test.js @@ -8,7 +8,7 @@ describe('DataUriPlugin', function() { it('should use gif, jpg and png file patterns by default', () => { const plugin = new Plugin(); - const pattern = /\.(gif|jpg|png)/.toString(); + const pattern = /\.(gif|jpg|png|svg)/.toString(); expect(plugin.pattern.toString()).to.equal(pattern); } @@ -89,4 +89,29 @@ describe('DataUriPlugin', function() { } ); + it('should compile svg files to data uri format', + () => { + const plugin = new Plugin(); + + return new Promise( + (resolve, reject) => { + const result = plugin.compile({path: 'test_files/turtle1.svg'}); + + result.catch( + (error) => { + reject(error); + } + ); + + result.then( + (data) => { + expect(data.indexOf('data:image/svg+xml;base64,')).to.not.equal(-1); + resolve(); + } + ); + } + ); + } + ); + }); diff --git a/test_files/turtle1.svg b/test_files/turtle1.svg new file mode 100644 index 0000000..2704eb8 --- /dev/null +++ b/test_files/turtle1.svg @@ -0,0 +1,92 @@ + + + + +Created by potrace 1.10, written by Peter Selinger 2001-2011 + + + + + + +