@@ -10,6 +10,7 @@ var selectorPath = normalize.lib('selector')
10
10
var templateLoaderPath = normalize . lib ( 'template-loader' )
11
11
var templateCompilerPath = normalize . lib ( 'template-compiler' )
12
12
var styleRewriterPath = normalize . lib ( 'style-rewriter' )
13
+ var componentNormalizerPath = normalize . lib ( 'component-normalizer' )
13
14
14
15
// dep loaders
15
16
var styleLoaderPath = normalize . dep ( 'vue-style-loader' )
@@ -33,10 +34,6 @@ var defaultLang = {
33
34
script : 'js'
34
35
}
35
36
36
- var checkNamedExports =
37
- 'if (Object.keys(__vue_exports__).some(function (key) { return key !== "default" && key !== "__esModule" })) {' +
38
- 'console.error("named exports are not supported in *.vue files.")}\n'
39
-
40
37
module . exports = function ( content ) {
41
38
this . cacheable ( )
42
39
var isServer = this . options . target === 'node'
@@ -69,7 +66,7 @@ module.exports = function (content) {
69
66
function getRequire ( type , part , index , scoped ) {
70
67
return 'require(' +
71
68
getRequireString ( type , part , index , scoped ) +
72
- ')\n '
69
+ ')'
73
70
}
74
71
75
72
function getRequireString ( type , part , index , scoped ) {
@@ -88,7 +85,7 @@ module.exports = function (content) {
88
85
function getRequireForImport ( type , impt , scoped ) {
89
86
return 'require(' +
90
87
getRequireForImportString ( type , impt , scoped ) +
91
- ')\n '
88
+ ')'
92
89
}
93
90
94
91
function getRequireForImportString ( type , impt , scoped ) {
@@ -196,9 +193,9 @@ module.exports = function (content) {
196
193
}
197
194
}
198
195
196
+ var output = ''
199
197
var parts = parse ( content , fileName , this . sourceMap )
200
198
var hasScoped = parts . styles . some ( function ( s ) { return s . scoped } )
201
- var output = 'var __vue_exports__, __vue_options__\n'
202
199
203
200
// css modules
204
201
var cssModules = { }
@@ -220,7 +217,7 @@ module.exports = function (content) {
220
217
if ( moduleName ) {
221
218
if ( ! hasModules ) {
222
219
hasModules = true
223
- output += 'var __vue_styles__ = {}\n'
220
+ output += 'var cssModules = {}\n'
224
221
}
225
222
if ( moduleName in cssModules ) {
226
223
loaderContext . emitError ( 'CSS module name "' + moduleName + '" is not unique!' )
@@ -235,81 +232,89 @@ module.exports = function (content) {
235
232
requireString += '.locals'
236
233
}
237
234
238
- output += '__vue_styles__ ["' + moduleName + '"] = ' + requireString + '\n'
235
+ output += 'cssModules ["' + moduleName + '"] = ' + requireString + '\n'
239
236
}
240
237
} else {
241
- output += requireString
238
+ output += requireString + '\n'
242
239
}
243
240
} )
241
+ output += '\n'
244
242
}
245
243
246
- // add require for script
244
+ // we require the component normalizer function, and call it like so:
245
+ // normalizeComponent(
246
+ // name,
247
+ // scriptExports,
248
+ // compiledTemplate,
249
+ // scopeId,
250
+ // cssModules
251
+ // )
252
+ output += 'var Component = require("' + componentNormalizerPath + '")(\n'
253
+
254
+ // name
255
+ output += ' /* name */\n ' + JSON . stringify ( path . parse ( filePath ) . name ) + ',\n'
256
+
257
+ // <script>
258
+ output += ' /* script */\n '
247
259
var script = parts . script
248
260
if ( script ) {
249
- output += '\n/* script */\n'
250
- output +=
251
- '__vue_exports__ = ' + (
252
- script . src
253
- ? getRequireForImport ( 'script' , script )
254
- : getRequire ( 'script' , script )
255
- )
261
+ output += script . src
262
+ ? getRequireForImport ( 'script' , script )
263
+ : getRequire ( 'script' , script )
264
+ // inject loader interop
265
+ if ( query . inject ) {
266
+ output += '(injections)'
267
+ }
268
+ } else {
269
+ output += 'null'
256
270
}
271
+ output += ',\n'
257
272
258
- var exports =
259
- '__vue_options__ = __vue_exports__ = __vue_exports__ || {}\n' +
260
- // ES6 modules interop
261
- 'if (\n' +
262
- ' typeof __vue_exports__.default === "object" ||\n' +
263
- ' typeof __vue_exports__.default === "function"\n' +
264
- ') {\n' +
265
- ( isProduction ? '' : checkNamedExports ) +
266
- '__vue_options__ = __vue_exports__ = __vue_exports__.default\n' +
267
- '}\n' +
268
- // constructor export interop
269
- 'if (typeof __vue_options__ === "function") {\n' +
270
- ' __vue_options__ = __vue_options__.options\n' +
271
- '}\n' +
272
- // add filename in dev
273
- ( isProduction ? '' : ( '__vue_options__.__file = ' + JSON . stringify ( filePath ) ) ) + '\n'
274
-
275
- // add component name based on the filename
276
- exports +=
277
- 'if(typeof __vue_options__.name === "undefined") {\n' +
278
- ' __vue_options__.name = ' + JSON . stringify ( path . parse ( filePath ) . name ) + '\n' +
279
- '}'
280
-
281
- // add require for template
273
+ // <template>
274
+ output += ' /* template */\n '
282
275
var template = parts . template
283
276
if ( template ) {
284
- output += '\n/* template */\n'
285
- output += 'var __vue_template__ = ' + (
286
- template . src
287
- ? getRequireForImport ( 'template' , template )
288
- : getRequire ( 'template' , template )
289
- )
290
- // attach render functions to exported options
291
- exports +=
292
- '__vue_options__.render = __vue_template__.render\n' +
293
- '__vue_options__.staticRenderFns = __vue_template__.staticRenderFns\n'
277
+ output += template . src
278
+ ? getRequireForImport ( 'template' , template )
279
+ : getRequire ( 'template' , template )
280
+ } else {
281
+ output += 'null'
294
282
}
283
+ output += ',\n'
295
284
296
- // attach scoped id
297
- if ( hasScoped ) {
298
- exports += '__vue_options__._scopeId = "' + moduleId + '"\n'
299
- }
285
+ // scopeId
286
+ output += ' /* scopeId */\n '
287
+ output += ( hasScoped ? JSON . stringify ( moduleId ) : 'null' ) + ',\n'
300
288
289
+ // cssModules
290
+ output += ' /* cssModules */\n '
301
291
if ( Object . keys ( cssModules ) . length ) {
302
292
// inject style modules as computed properties
303
- exports +=
304
- 'if (!__vue_options__.computed) __vue_options__.computed = {}\n' +
305
- 'Object.keys(__vue_styles__).forEach(function (key) {\n' +
306
- 'var module = __vue_styles__[key]\n' +
307
- '__vue_options__.computed[key] = function () { return module }\n' +
308
- '})\n'
293
+ output += 'cssModules'
294
+ } else {
295
+ output += 'null'
296
+ }
297
+ output += '\n'
298
+
299
+ // close normalizeComponent call
300
+ output += ')\n'
301
+
302
+ // development-only code
303
+ if ( ! isProduction ) {
304
+ // add filename in dev
305
+ output += 'Component.options.__file = ' + JSON . stringify ( filePath ) + '\n'
306
+ // check functional components used with templates
307
+ if ( template ) {
308
+ output +=
309
+ 'if (Component.options.functional) {' +
310
+ 'console.error("' +
311
+ '[vue-loader] ' + fileName + ': functional components are not ' +
312
+ 'supported with templates, they should use render functions.' +
313
+ '")}\n'
314
+ }
309
315
}
310
316
311
317
if ( ! query . inject ) {
312
- output += exports
313
318
// hot reload
314
319
if (
315
320
! isServer &&
@@ -325,37 +330,25 @@ module.exports = function (content) {
325
330
' module.hot.accept()\n' +
326
331
' if (!module.hot.data) {\n' +
327
332
// initial insert
328
- ' hotAPI.createRecord("' + moduleId + '", __vue_options__ )\n' +
333
+ ' hotAPI.createRecord("' + moduleId + '", Component.options )\n' +
329
334
' } else {\n' +
330
335
// update
331
- ' hotAPI.reload("' + moduleId + '", __vue_options__ )\n' +
336
+ ' hotAPI.reload("' + moduleId + '", Component.options )\n' +
332
337
' }\n' +
333
338
'})()}\n'
334
339
}
335
- // check functional components used with templates
336
- if ( ! isProduction ) {
337
- output +=
338
- 'if (__vue_options__.functional && typeof __vue_template__ !== "undefined") {' +
339
- 'console.error("' +
340
- `[vue-loader] ${ fileName } : functional components are not ` +
341
- 'supported with templates, they should use render functions.' +
342
- '")}\n'
343
- }
344
340
// final export
345
341
if ( options . esModule ) {
346
- output += '\nexports.__esModule = true;\nexports["default"] = __vue_exports__ \n'
342
+ output += '\nexports.__esModule = true;\nexports["default"] = Component.exports \n'
347
343
} else {
348
- output += '\nmodule.exports = __vue_exports__ \n'
344
+ output += '\nmodule.exports = Component.exports \n'
349
345
}
350
346
} else {
351
347
// inject-loader support
352
- output + =
348
+ output =
353
349
'\n/* dependency injection */\n' +
354
- 'module.exports = function (injections) {\n' +
355
- ' __vue_exports__ = __vue_exports__(injections)\n' +
356
- exports +
357
- ' return __vue_exports__\n' +
358
- '}'
350
+ 'module.exports = function (injections) {\n' + output + '\n' +
351
+ '\nreturn Component.exports\n}'
359
352
}
360
353
361
354
// done
0 commit comments