Skip to content

Commit

Permalink
Support compiling svg files by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfarljw committed Feb 4, 2017
1 parent db9dfa4 commit 57f842a
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 3 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)/
}
);

Expand Down Expand Up @@ -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;
27 changes: 26 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}
);
}
);
}
);

});
92 changes: 92 additions & 0 deletions test_files/turtle1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 57f842a

Please sign in to comment.