Skip to content

Commit

Permalink
feat(plugin): allow to render external sprite without styles and usages
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #132
  • Loading branch information
kisenka committed Oct 16, 2017
1 parent 49bc381 commit fcf3939
Show file tree
Hide file tree
Showing 3 changed files with 510 additions and 8 deletions.
26 changes: 24 additions & 2 deletions lib/plugin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable import/no-extraneous-dependencies */
const merge = require('deepmerge');
const Promise = require('bluebird');
const Chunk = require('webpack/lib/Chunk');
const SVGCompiler = require('svg-baker');
const spriteFactory = require('svg-baker/lib/sprite-factory');
const Sprite = require('svg-baker/lib/sprite');
const { NAMESPACE } = require('./config');
const {
Expand All @@ -13,8 +15,25 @@ const {

const webpackVersion = parseInt(getWebpackVersion(), 10);

const defaultConfig = {
plainSprite: false
};

class SVGSpritePlugin {
constructor() {
constructor(config = {}) {
this.config = merge.all([defaultConfig, config]);
const { plainSprite } = this.config;

const spriteFactoryOptions = {
styles: plainSprite === false,
usages: plainSprite === false
};

this.factory = ({ symbols }) => {
const opts = merge.all([spriteFactoryOptions, { symbols }]);
return spriteFactory(opts);
};

this.svgCompiler = new SVGCompiler();
}

Expand Down Expand Up @@ -78,7 +97,10 @@ class SVGSpritePlugin {
return Promise.map(filenames, (filename) => {
const spriteSymbols = itemsBySprite[filename].map(item => item.symbol);

return Sprite.create({ symbols: spriteSymbols })
return Sprite.create({
symbols: spriteSymbols,
factory: plugin.factory
})
.then((sprite) => {
const content = sprite.render();
const chunkName = filename.replace(/\.svg$/, '');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"domready": "1.0.8",
"escape-string-regexp": "1.0.5",
"loader-utils": "^1.1.0",
"svg-baker": "^1.2.13",
"svg-baker": "^1.2.14",
"svg-baker-runtime": "^1.3.3",
"url-slug": "2.0.0"
},
Expand Down
Loading

0 comments on commit fcf3939

Please sign in to comment.