Skip to content

Commit f7d9769

Browse files
committed
Move core to another package: svg-to-vue
1 parent 5122966 commit f7d9769

File tree

3 files changed

+132
-168
lines changed

3 files changed

+132
-168
lines changed

index.js

Lines changed: 7 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,14 @@
1-
const SVGO = require('svgo');
1+
const svgToVue = require('svg-to-vue');
22
const { getOptions } = require('loader-utils');
3-
const { compile } = require('vue-template-compiler');
4-
const stripWith = require('vue-template-es2015-compiler');
5-
6-
function getSvg(content, path, svgoConfig) {
7-
if (svgoConfig === false) {
8-
return Promise.resolve(content);
9-
}
10-
11-
return new SVGO(svgoConfig)
12-
.optimize(content, { path })
13-
.then(result => result.data);
14-
};
153

164
module.exports = function (content) {
17-
const path = this.resourcePath;
185
const callback = this.async();
19-
const options = getOptions(this) || {};
20-
21-
const {
22-
svgo: svgoConfig = {},
23-
functional = false,
24-
} = options;
25-
26-
getSvg(content, path, svgoConfig)
27-
.then((result) => {
28-
let { render: renderFn } = compile(result, {
29-
preserveWhitespace: false,
30-
modules: [
31-
!!functional && {
32-
transformNode: (el) => {
33-
if (el.tag === 'svg') {
34-
el.classBinding = '[data.class, data.staticClass]';
35-
el.styleBinding = '[data.style, data.staticStyle]';
36-
}
37-
},
38-
},
39-
],
40-
});
41-
42-
renderFn = `
43-
function render(${functional ? '_h, _vm' : ''}) {
44-
${renderFn};
45-
};
46-
`;
47-
48-
renderFn = stripWith(renderFn, {
49-
transforms: {
50-
stripWithFunctional: !!functional,
51-
},
52-
});
53-
54-
const component = `
55-
${renderFn}
56-
57-
module.exports = {
58-
${functional ? 'functional: true,' : ''}
59-
render: render,
60-
};
61-
`;
6+
const { svgo } = getOptions(this) || {};
627

63-
callback(null, component);
64-
})
8+
svgToVue(content, {
9+
svgoPath: this.resourcePath,
10+
svgoConfig: svgo,
11+
})
12+
.then(component => callback(null, component))
6513
.catch(callback);
6614
};

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
"main": "index.js",
2222
"dependencies": {
2323
"loader-utils": "^1.1.0",
24-
"svgo": "^1.1.1",
25-
"vue-template-compiler": "^2.5.17",
26-
"vue-template-es2015-compiler": "^1.6.0"
24+
"svg-to-vue": "^0.1.0"
2725
},
2826
"devDependencies": {
2927
"vue-tabs-component": "^1.5.0",

0 commit comments

Comments
 (0)