@@ -7,21 +7,20 @@ var path = require('path')
7
7
8
8
var defaultLang = {
9
9
template : 'html' ,
10
- style : 'css' ,
10
+ styles : 'css' ,
11
11
script : 'js'
12
12
}
13
13
14
- var rewriterInjectRE = / \b ( ( c s s | ( v u e - ) ? h t m l ) ( - l o a d e r ) ? ( \? [ ^ ! ] + ) ? ) (?: ! | $ ) /
14
+ var rewriterInjectRE = / \b ( c s s ( - l o a d e r ) ? ( \? [ ^ ! ] + ) ? ) (?: ! | $ ) /
15
15
var rewriters = {
16
- template : require . resolve ( './template-rewriter' ) ,
17
- style : require . resolve ( './style-rewriter' )
16
+ styles : require . resolve ( './style-rewriter' )
18
17
}
19
18
20
19
var templateLoader = require . resolve ( './template-loader' )
21
20
22
21
module . exports = function ( content ) {
23
22
var defaultLoaders = {
24
- html : 'vue-html-loader' ,
23
+ html : require . resolve ( './template-compiler' ) ,
25
24
css : 'vue-style-loader!css-loader' ,
26
25
js : 'babel-loader?presets[]=es2015&plugins[]=transform-runtime&comments=false'
27
26
}
@@ -106,8 +105,8 @@ module.exports = function (content) {
106
105
// unknown lang, infer the loader to be used
107
106
switch ( type ) {
108
107
case 'template' :
109
- return defaultLoaders . html + '!' + rewriter + templateLoader + '?raw&engine=' + lang + '!'
110
- case 'style ' :
108
+ return defaultLoaders . html + '!' + templateLoader + '?raw&engine=' + lang + '!'
109
+ case 'styles ' :
111
110
return defaultLoaders . css + '!' + rewriter + lang + '!'
112
111
case 'script' :
113
112
return injectString + lang + '!'
@@ -143,35 +142,25 @@ module.exports = function (content) {
143
142
144
143
var parts = parse ( content , fileName , this . sourceMap )
145
144
var hasLocalStyles = false
146
- var output = 'var __vue_script__, __vue_template__\n'
147
-
148
- // check if there are any template syntax errors
149
- var templateWarnings = parts . template . length && parts . template [ 0 ] . warnings
150
- if ( templateWarnings ) {
151
- templateWarnings . forEach ( this . emitError )
152
- }
153
-
154
- // add requires for src imports
155
- parts . styleImports . forEach ( function ( impt ) {
156
- if ( impt . scoped ) hasLocalStyles = true
157
- output += getRequireForImport ( 'style' , impt , impt . scoped )
158
- } )
145
+ var output = ''
159
146
160
147
// add requires for styles
161
- parts . style . forEach ( function ( style , i ) {
162
- if ( style . scoped ) hasLocalStyles = true
163
- output += getRequire ( 'style' , style , i , style . scoped )
148
+ parts . styles . forEach ( function ( style , i ) {
149
+ var scoped = style . scoped
150
+ if ( scoped ) hasLocalStyles = true
151
+ output += style . src
152
+ ? getRequireForImport ( 'styles' , style . src , scoped )
153
+ : getRequire ( 'styles' , style , i , scoped )
164
154
} )
165
155
166
156
// add require for script
167
- var script
168
- if ( parts . script . length ) {
169
- script = parts . script [ 0 ]
157
+ var script = parts . script
158
+ if ( script ) {
170
159
output +=
171
- '__vue_script__ = ' + (
160
+ 'var __vue_script__ = ' + (
172
161
script . src
173
- ? getRequireForImport ( 'script' , script , 0 )
174
- : getRequire ( 'script' , script , 0 )
162
+ ? getRequireForImport ( 'script' , script )
163
+ : getRequire ( 'script' , script )
175
164
)
176
165
// check and warn named exports
177
166
if ( ! this . minimize ) {
@@ -187,68 +176,63 @@ module.exports = function (content) {
187
176
}
188
177
}
189
178
179
+ // plain require() compatibility
180
+ var exports = 'if (__exports__.__esModule) __exports__ = __exports__.default\n'
181
+
190
182
// add require for template
191
- var template
192
- if ( parts . template . length ) {
193
- template = parts . template [ 0 ]
194
- output += '__vue_template__ = ' + (
195
- template . src
196
- ? getRequireForImport ( 'template' , template , hasLocalStyles )
197
- : getRequire ( 'template' , template , 0 , hasLocalStyles )
198
- )
183
+ var template = parts . template
184
+ if ( template ) {
185
+ output += 'var __vue_template__ = ' + (
186
+ template . src
187
+ ? getRequireForImport ( 'template' , template , hasLocalStyles )
188
+ : getRequire ( 'template' , template , null , hasLocalStyles )
189
+ )
190
+ // attach render functions to exported options
191
+ exports +=
192
+ 'var __vue_options__ = (typeof __exports__ === "function" ' +
193
+ '? (__exports__.options || (__exports__.options = {})) ' +
194
+ ': __exports__)\n' +
195
+ '__vue_options__.render = __vue_template__.render\n' +
196
+ '__vue_options__.staticRenderFns = __vue_template__.staticRenderFns\n'
199
197
}
200
198
201
199
if ( ! query . inject ) {
202
- // attach template
203
200
output +=
204
- 'module.exports = __vue_script__ || {}\n' +
205
- 'if (module.exports.__esModule) module.exports = module.exports.default\n' +
206
- 'if (__vue_template__) {\n' +
207
- '(typeof module.exports === "function" ' +
208
- '? (module.exports.options || (module.exports.options = {})) ' +
209
- ': module.exports).template = __vue_template__\n' +
210
- '}\n'
201
+ 'var __exports__ = __vue_script__ || {}\n' +
202
+ exports +
203
+ 'module.exports = __exports__'
211
204
// hot reload
212
- if (
213
- ! this . minimize &&
214
- process . env . NODE_ENV !== 'production' &&
215
- ( parts . script . length || parts . template . length )
216
- ) {
217
- output +=
218
- 'if (module.hot) {(function () {' +
219
- ' module.hot.accept()\n' +
220
- ' var hotAPI = require("vue-hot-reload-api")\n' +
221
- ' hotAPI.install(require("vue"), false)\n' +
222
- ' if (!hotAPI.compatible) return\n' +
223
- ' var id = ' + loaderUtils . stringifyRequest ( loaderContext , filePath ) + '\n' +
224
- ' if (!module.hot.data) {\n' +
225
- // initial insert
226
- ' hotAPI.createRecord(id, module.exports)\n' +
227
- ' } else {\n' +
228
- // update
229
- ' hotAPI.update(id, module.exports, __vue_template__)\n' +
230
- ' }\n' +
231
- '})()}'
232
- }
205
+ // if (
206
+ // !this.minimize &&
207
+ // process.env.NODE_ENV !== 'production' &&
208
+ // (parts.script.length || parts.template.length)
209
+ // ) {
210
+ // output +=
211
+ // 'if (module.hot) {(function () {' +
212
+ // ' module.hot.accept()\n' +
213
+ // ' var hotAPI = require("vue-hot-reload-api")\n' +
214
+ // ' hotAPI.install(require("vue"), false)\n' +
215
+ // ' if (!hotAPI.compatible) return\n' +
216
+ // ' var id = ' + loaderUtils.stringifyRequest(loaderContext, filePath) + '\n' +
217
+ // ' if (!module.hot.data) {\n' +
218
+ // // initial insert
219
+ // ' hotAPI.createRecord(id, module.exports)\n' +
220
+ // ' } else {\n' +
221
+ // // update
222
+ // ' hotAPI.update(id, module.exports, __vue_template__)\n' +
223
+ // ' }\n' +
224
+ // '})() }'
225
+ // }
233
226
} else {
234
227
output +=
235
228
'module.exports = function (injections) {\n' +
236
- ' var mod = __vue_script__\n' +
229
+ ' var __exports__ = __vue_script__\n' +
237
230
' ? __vue_script__(injections)\n' +
238
- ' : {}\n' +
239
- ' if (mod.__esModule) mod = mod.default\n' +
240
- ' if (__vue_template__) { (typeof mod === "function" ? mod.options : mod).template = __vue_template__ }\n' +
241
- ' return mod\n' +
231
+ ' : {}\n' + exports +
232
+ ' return __exports__\n' +
242
233
'}'
243
234
}
244
235
245
236
// done
246
237
return output
247
238
}
248
-
249
- module . exports . withLoaders = function ( ) {
250
- throw new Error (
251
- 'vue.withLoaders has been deprecated in vue-loader 6.0. ' +
252
- 'Add a "vue" section to the webpack config instead.'
253
- )
254
- }
0 commit comments