@@ -4,8 +4,12 @@ const compiler = require('vue-template-compiler');
4
4
const transpile = require ( 'vue-template-es2015-compiler' ) ;
5
5
6
6
module . exports = function ( content ) {
7
- const options = loaderUtils . getOptions ( this ) || { } ;
8
- const svg = new svgo ( options . svgo || { } ) ;
7
+ const {
8
+ svgo : svgoOptions = { } ,
9
+ functional = false ,
10
+ } = loaderUtils . getOptions ( this ) || { } ;
11
+
12
+ const svg = new svgo ( svgoOptions ) ;
9
13
const path = this . resourcePath ;
10
14
11
15
this . cacheable && this . cacheable ( true ) ;
@@ -19,19 +23,29 @@ module.exports = function (content) {
19
23
. then ( ( result ) => {
20
24
const compiled = compiler . compile ( result . data , {
21
25
preserveWhitespace : false ,
26
+ modules : [
27
+ ! ! functional && {
28
+ transformNode : ( el ) => {
29
+ if ( el . tag === 'svg' ) {
30
+ el . classBinding = '[data.class, data.staticClass]' ;
31
+ el . styleBinding = '[data.style, data.staticStyle]' ;
32
+ }
33
+ } ,
34
+ }
35
+ ] ,
22
36
} ) ;
23
37
24
- const transpileCode = `var render = function (${ options . functional ? '_h, _vm' : '' } ) { ${ compiled . render } };` ;
38
+ const transpileCode = `var render = function (${ functional ? '_h, _vm' : '' } ) { ${ compiled . render } };` ;
25
39
26
40
const transpileOptions = {
27
41
transforms : {
28
- stripWithFunctional : ! ! options . functional || false ,
42
+ stripWithFunctional : ! ! functional ,
29
43
} ,
30
44
} ;
31
45
32
46
component = `${ transpile ( transpileCode , transpileOptions ) } \n` ;
33
47
34
- if ( options . functional ) {
48
+ if ( functional ) {
35
49
component += 'module.exports = { functional: true, render: render };' ;
36
50
} else {
37
51
component += 'module.exports = { render: render };' ;
0 commit comments