@@ -4,6 +4,7 @@ import MagicString from 'magic-string';
4
4
5
5
import vueTransform from './vueTransform' ;
6
6
import DEFAULT_OPTIONS from './options' ;
7
+ import debug from './debug' ;
7
8
8
9
function mergeOptions ( options , defaults ) {
9
10
Object . keys ( defaults ) . forEach ( ( key ) => {
@@ -22,6 +23,7 @@ function mergeOptions(options, defaults) {
22
23
}
23
24
24
25
export default function vue ( options = { } ) {
26
+ debug ( 'Yo! rolling vue!' ) ;
25
27
const filter = createFilter ( options . include , options . exclude ) ;
26
28
27
29
delete options . include ;
@@ -32,6 +34,7 @@ export default function vue(options = {}) {
32
34
const vueVersion = require ( 'vue' ) . version ;
33
35
if ( parseInt ( vueVersion . split ( '.' ) [ 0 ] , 10 ) >= 2 ) {
34
36
if ( ! ( 'compileTemplate' in options ) ) {
37
+ debug ( 'Vue 2.0 detected. Compiling template.' ) ;
35
38
options . compileTemplate = true ;
36
39
}
37
40
} else {
@@ -47,14 +50,15 @@ export default function vue(options = {}) {
47
50
options = mergeOptions ( options , DEFAULT_OPTIONS ) ;
48
51
49
52
const styles = { } ;
50
- let rollupOptions = { } ;
53
+ let rollupOptions ;
51
54
let generated = false ;
52
55
const generateStyleBundle = ( ) => {
53
56
if ( options . css === false ) {
54
57
return ;
55
58
}
56
59
57
60
if ( generated ) {
61
+ debug ( 'Style already generated!' ) ;
58
62
return ;
59
63
}
60
64
@@ -99,38 +103,51 @@ export default function vue(options = {}) {
99
103
return {
100
104
name : 'vue' ,
101
105
options ( o ) {
102
- rollupOptions = o ;
103
- return o ;
106
+ if ( rollupOptions === undefined ) {
107
+ rollupOptions = o ;
108
+ debug ( 'Set options.' ) ;
109
+ }
104
110
} ,
105
111
transform ( source , id ) {
106
112
if ( ! filter ( id ) || ! id . endsWith ( '.vue' ) ) {
113
+ debug ( `Ignore: ${ id } ` ) ;
107
114
return null ;
108
115
}
109
116
117
+ debug ( `Transform: ${ id } ` ) ;
110
118
const { js, css, map } = vueTransform ( source , id , options ) ;
111
119
112
120
// Map of every stylesheet
113
121
styles [ id ] = css || { } ;
114
122
115
123
// Component javascript with inlined html template
116
- return {
124
+ const result = {
117
125
code : js ,
118
126
map : map . generateMap ( { hires : true } ) ,
119
127
} ;
128
+
129
+ debug ( `Transformed: ${ id } ` ) ;
130
+
131
+ return result ;
120
132
} ,
121
133
transformBundle ( source ) {
134
+ debug ( 'Replace window.__VUE_WITH_STATEMENT__ with with(this) and generate style.' ) ;
122
135
generateStyleBundle ( ) ;
123
136
const map = new MagicString ( source ) ;
124
-
125
- return {
137
+ const result = {
126
138
code : source . replace ( / i f [ \s ] * \( w i n d o w \. _ _ V U E _ W I T H _ S T A T E M E N T _ _ \) / g, 'with(this)' ) ,
127
139
map : map . generateMap ( { hires : true } ) ,
128
140
} ;
141
+ debug ( 'with(this) fixed!' ) ;
142
+
143
+ return result ;
129
144
} ,
130
145
ongenerate ( opts , rendered ) {
146
+ debug ( 'on generate!' ) ;
131
147
generateStyleBundle ( ) ;
132
148
rendered . code = rendered . code . replace (
133
- / i f [ \s ] * \( w i n d o w \. _ _ V U E _ W I T H _ S T A T E M E N T _ _ \) / g, 'with(this)' ) ;
149
+ / i f [ \s ] * \( w i n d o w \. _ _ V U E _ W I T H _ S T A T E M E N T _ _ \) / g, 'with(this)' ) ;
150
+ debug ( 'with(this) fixed!' ) ;
134
151
} ,
135
152
} ;
136
153
}
0 commit comments