Skip to content

Commit 1b59bc6

Browse files
committed
v0.5.0
1 parent de918c7 commit 1b59bc6

File tree

4 files changed

+22
-28
lines changed

4 files changed

+22
-28
lines changed

.jshintrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2016 Damian
3+
Copyright (c) 2016-2018 Damian Stasik <[email protected]>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

index.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
1-
const svg = require('svgo');
1+
const svgo = require('svgo');
22
const loaderUtils = require('loader-utils');
33
const compiler = require('vue-template-compiler');
4+
const transpile = require('vue-template-es2015-compiler');
45

56
module.exports = function (content) {
67
const options = loaderUtils.getOptions(this) || {};
7-
const query = loaderUtils.parseQuery(this.resourceQuery || '?');
8-
const svgo = new svg(options.svgo || {
9-
plugins: [{ removeDoctype: true }, { removeComments: true }],
10-
});
8+
const svg = new svgo(options.svgo || {});
9+
const path = this.resourcePath;
1110

1211
this.cacheable && this.cacheable(true);
1312
this.addDependency(this.resourcePath);
1413

1514
const cb = this.async();
15+
let component;
1616

17-
svgo.optimize(content, (result) => {
18-
if (result.error) {
19-
return cb(result.error);
20-
}
17+
svg
18+
.optimize(content, { path: path })
19+
.then((result) => {
20+
const compiled = compiler.compile(result.data, { preserveWhitespace: false });
2121

22-
const compiled = compiler.compile(result.data, { preserveWhitespace: false });
23-
let component = `render: function () {${compiled.render}}`;
22+
component = transpile(`var render = function () {${compiled.render}};`);
23+
component += `var toString = function () {return ${JSON.stringify(path)}};`;
24+
component += `module.exports = { render: render, toString: toString };`;
2425

25-
if (options.includePath || query.includePath) {
26-
const filename = loaderUtils.interpolateName(this, '[path][name].[ext]', { context: this.options.context });
27-
component = `${component}, path:${JSON.stringify(filename)}`;
28-
}
29-
30-
cb(null, `module.exports = {${component}};`);
31-
});
26+
cb(null, component);
27+
})
28+
.catch(cb);
3229
};

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
22
"name": "vue-svg-loader",
33
"description": "Use SVG files as Vue Components",
4-
"version": "0.4.0",
4+
"version": "0.5.0",
55
"keywords": [
66
"vue-svg-loader",
77
"svg",
8+
"svgo",
89
"loader",
910
"webpack",
1011
"vue"
1112
],
1213
"bugs": "https://github.com/visualfanatic/vue-svg-loader/issues",
1314
"repository": "visualfanatic/vue-svg-loader",
1415
"license": "MIT",
15-
"author": "visualfanatic",
16+
"author": "Damian Stasik <[email protected]>",
1617
"main": "index.js",
17-
"peerDependencies": {
18-
"vue-template-compiler": "^2.0.0"
19-
},
2018
"dependencies": {
2119
"loader-utils": "^1.1.0",
22-
"svgo": "^0.7.2"
20+
"svgo": "^1.0.4",
21+
"vue-template-es2015-compiler": "^1.6.0",
22+
"vue-template-compiler": "^2.5.13"
2323
}
2424
}

0 commit comments

Comments
 (0)