@@ -5,19 +5,30 @@ var beautify = require('js-beautify').js_beautify
5
5
var normalize = require ( './normalize' )
6
6
var hotReloadAPIPath = normalize . dep ( 'vue-hot-reload-api' )
7
7
8
- // vue compiler module for using file-loader img src
8
+ // vue compiler module for using transforming `<tag>:<attribute>` to `require`
9
+ var defaultTransformToRequire = {
10
+ img : 'src'
11
+ }
12
+ var transformToRequire = Object . assign ( { } , defaultTransformToRequire )
9
13
var options = {
10
14
modules : [ {
11
15
postTransformNode ( el ) {
12
- if ( el . tag === 'img' ) {
13
- el . attrs && el . attrs . some ( rewrite )
16
+ for ( var tag in transformToRequire ) {
17
+ if ( el . tag === tag && el . attrs ) {
18
+ var attributes = transformToRequire [ tag ]
19
+ if ( typeof attributes === 'string' ) {
20
+ el . attrs . some ( attr => rewrite ( attr , attributes ) )
21
+ } else if ( Array . isArray ( attributes ) ) {
22
+ attributes . forEach ( item => el . attrs . some ( attr => rewrite ( attr , item ) ) )
23
+ }
24
+ }
14
25
}
15
26
}
16
27
} ]
17
28
}
18
29
19
- function rewrite ( attr ) {
20
- if ( attr . name === 'src' ) {
30
+ function rewrite ( attr , name ) {
31
+ if ( attr . name === name ) {
21
32
var value = attr . value
22
33
var isStatic = value . charAt ( 0 ) === '"' && value . charAt ( value . length - 1 ) === '"'
23
34
if ( ! isStatic ) {
@@ -38,6 +49,9 @@ module.exports = function (html) {
38
49
this . cacheable ( )
39
50
var query = loaderUtils . parseQuery ( this . query )
40
51
var isServer = this . options . target === 'node'
52
+ if ( this . options . vue && this . options . vue . transformToRequire ) {
53
+ Object . assign ( transformToRequire , this . options . vue . transformToRequire )
54
+ }
41
55
var compiled = compiler . compile ( html , options )
42
56
var code
43
57
if ( compiled . errors . length ) {
0 commit comments