Skip to content

Commit 9ef3c31

Browse files
committed
Precompile templates into render functions
1 parent d7ec966 commit 9ef3c31

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var svg = require('svgo');
2+
var compiler = require('vue-template-compiler');
23

34
var svgo = new svg({
45
plugins: ['removeDoctype', 'removeComments'],
@@ -14,6 +15,8 @@ module.exports = function (content) {
1415
if (result.error) {
1516
return cb(result.error);
1617
}
17-
cb(null, "module.exports = {template: '" + result.data + "'};");
18+
19+
var compiled = compiler.compile(result.data, {preserveWhitespace: false});
20+
cb(null, "module.exports = {render: function () {" + compiled.render + "}};");
1821
});
1922
};

package-lock.json

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"author": "visualfanatic",
1616
"main": "index.js",
1717
"dependencies": {
18-
"svgo": "^0.7.1"
18+
"svgo": "^0.7.1",
19+
"vue-template-compiler": "^2.4.2"
1920
}
2021
}

0 commit comments

Comments
 (0)