@@ -4,6 +4,7 @@ import MagicString from 'magic-string';
44
55import vueTransform from './vueTransform' ;
66import DEFAULT_OPTIONS from './options' ;
7+ import debug from './debug' ;
78
89function mergeOptions ( options , defaults ) {
910 Object . keys ( defaults ) . forEach ( ( key ) => {
@@ -22,6 +23,7 @@ function mergeOptions(options, defaults) {
2223}
2324
2425export default function vue ( options = { } ) {
26+ debug ( 'Yo! rolling vue!' ) ;
2527 const filter = createFilter ( options . include , options . exclude ) ;
2628
2729 delete options . include ;
@@ -32,6 +34,7 @@ export default function vue(options = {}) {
3234 const vueVersion = require ( 'vue' ) . version ;
3335 if ( parseInt ( vueVersion . split ( '.' ) [ 0 ] , 10 ) >= 2 ) {
3436 if ( ! ( 'compileTemplate' in options ) ) {
37+ debug ( 'Vue 2.0 detected. Compiling template.' ) ;
3538 options . compileTemplate = true ;
3639 }
3740 } else {
@@ -47,14 +50,15 @@ export default function vue(options = {}) {
4750 options = mergeOptions ( options , DEFAULT_OPTIONS ) ;
4851
4952 const styles = { } ;
50- let rollupOptions = { } ;
53+ let rollupOptions ;
5154 let generated = false ;
5255 const generateStyleBundle = ( ) => {
5356 if ( options . css === false ) {
5457 return ;
5558 }
5659
5760 if ( generated ) {
61+ debug ( 'Style already generated!' ) ;
5862 return ;
5963 }
6064
@@ -99,38 +103,51 @@ export default function vue(options = {}) {
99103 return {
100104 name : 'vue' ,
101105 options ( o ) {
102- rollupOptions = o ;
103- return o ;
106+ if ( rollupOptions === undefined ) {
107+ rollupOptions = o ;
108+ debug ( 'Set options.' ) ;
109+ }
104110 } ,
105111 transform ( source , id ) {
106112 if ( ! filter ( id ) || ! id . endsWith ( '.vue' ) ) {
113+ debug ( `Ignore: ${ id } ` ) ;
107114 return null ;
108115 }
109116
117+ debug ( `Transform: ${ id } ` ) ;
110118 const { js, css, map } = vueTransform ( source , id , options ) ;
111119
112120 // Map of every stylesheet
113121 styles [ id ] = css || { } ;
114122
115123 // Component javascript with inlined html template
116- return {
124+ const result = {
117125 code : js ,
118126 map : map . generateMap ( { hires : true } ) ,
119127 } ;
128+
129+ debug ( `Transformed: ${ id } ` ) ;
130+
131+ return result ;
120132 } ,
121133 transformBundle ( source ) {
134+ debug ( 'Replace window.__VUE_WITH_STATEMENT__ with with(this) and generate style.' ) ;
122135 generateStyleBundle ( ) ;
123136 const map = new MagicString ( source ) ;
124-
125- return {
137+ const result = {
126138 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)' ) ,
127139 map : map . generateMap ( { hires : true } ) ,
128140 } ;
141+ debug ( 'with(this) fixed!' ) ;
142+
143+ return result ;
129144 } ,
130145 ongenerate ( opts , rendered ) {
146+ debug ( 'on generate!' ) ;
131147 generateStyleBundle ( ) ;
132148 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!' ) ;
134151 } ,
135152 } ;
136153}
0 commit comments