@@ -107,6 +107,10 @@ module.exports = function (content) {
107
107
')'
108
108
}
109
109
110
+ function getImport ( type , part , index , scoped ) {
111
+ return 'import __vue_' + type + '__ from ' + getRequireString ( type , part , index , scoped )
112
+ }
113
+
110
114
function getRequireString ( type , part , index , scoped ) {
111
115
return loaderUtils . stringifyRequest ( loaderContext ,
112
116
// disable all configuration loaders
@@ -126,6 +130,10 @@ module.exports = function (content) {
126
130
')'
127
131
}
128
132
133
+ function getImportForImport ( type , impt , scoped ) {
134
+ return 'import __vue_' + type + '__ from ' + getRequireForImportString ( type , impt , scoped )
135
+ }
136
+
129
137
function getRequireForImportString ( type , impt , scoped ) {
130
138
return loaderUtils . stringifyRequest ( loaderContext ,
131
139
'!!' +
@@ -420,52 +428,74 @@ module.exports = function (content) {
420
428
// scopeId,
421
429
// moduleIdentifier (server only)
422
430
// )
423
- output += 'var Component = require(' +
424
- loaderUtils . stringifyRequest ( loaderContext , '!' + componentNormalizerPath ) +
425
- ')(\n'
431
+ if ( options . esModule ) {
432
+ output += 'import normalizeComponent from ' +
433
+ loaderUtils . stringifyRequest ( loaderContext , '!' + componentNormalizerPath ) +
434
+ '\n'
435
+ } else {
436
+ output += 'var normalizeComponent = require(' +
437
+ loaderUtils . stringifyRequest ( loaderContext , '!' + componentNormalizerPath ) +
438
+ ')\n'
439
+ }
426
440
427
441
// <script>
428
- output += ' /* script */\n '
442
+ output += '/* script */\n'
429
443
var script = parts . script
430
444
if ( script ) {
431
- output += script . src
432
- ? getRequireForImport ( 'script' , script )
433
- : getRequire ( 'script' , script )
445
+ if ( options . esModule ) {
446
+ output += script . src
447
+ ? getImportForImport ( 'script' , script )
448
+ : getImport ( 'script' , script ) + '\n'
449
+ } else {
450
+ output += 'var __vue_script__ = ' + ( script . src
451
+ ? getRequireForImport ( 'script' , script )
452
+ : getRequire ( 'script' , script ) ) + '\n'
453
+ }
434
454
// inject loader interop
435
455
if ( query . inject ) {
436
- output += '(injections)'
456
+ output += '__vue_script__ = __vue_script__ (injections)\n '
437
457
}
438
458
} else {
439
- output += 'null'
459
+ output += 'var __vue_script__ = null\n '
440
460
}
441
- output += ',\n'
442
461
443
462
// <template>
444
- output += ' /* template */\n '
463
+ output += '/* template */\n'
445
464
var template = parts . template
446
465
if ( template ) {
447
- output += template . src
448
- ? getRequireForImport ( 'template' , template )
449
- : getRequire ( 'template' , template )
466
+ if ( options . esModule ) {
467
+ output += ( template . src
468
+ ? getImportForImport ( 'template' , template )
469
+ : getImport ( 'template' , template ) ) + '\n'
470
+ } else {
471
+ output += 'var __vue_template__ = ' + ( template . src
472
+ ? getRequireForImport ( 'template' , template )
473
+ : getRequire ( 'template' , template ) ) + '\n'
474
+ }
450
475
} else {
451
- output += 'null'
476
+ output += 'var __vue_template__ = null\n '
452
477
}
453
- output += ',\n'
454
478
455
479
// style
456
- output += ' /* styles */\n '
457
- output += ( parts . styles . length ? 'injectStyle' : 'null' ) + ', \n'
480
+ output += '/* styles */\n'
481
+ output += 'var __vue_styles__ = ' + ( parts . styles . length ? 'injectStyle' : 'null' ) + '\n'
458
482
459
483
// scopeId
460
- output += ' /* scopeId */\n '
461
- output += ( hasScoped ? JSON . stringify ( moduleId ) : 'null' ) + ', \n'
484
+ output += '/* scopeId */\n'
485
+ output += 'var __vue_scopeId__ = ' + ( hasScoped ? JSON . stringify ( moduleId ) : 'null' ) + '\n'
462
486
463
487
// moduleIdentifier (server only)
464
- output += ' /* moduleIdentifier (server only) */\n '
465
- output += ( isServer ? JSON . stringify ( hash ( this . request ) ) : 'null' ) + '\n'
488
+ output += '/* moduleIdentifier (server only) */\n'
489
+ output += 'var __vue_module_identifier__ = ' + ( isServer ? JSON . stringify ( hash ( this . request ) ) : 'null' ) + '\n'
466
490
467
491
// close normalizeComponent call
468
- output += ')\n'
492
+ output += 'var Component = normalizeComponent(\n' +
493
+ ' __vue_script__,\n' +
494
+ ' __vue_template__,\n' +
495
+ ' __vue_styles__,\n' +
496
+ ' __vue_scopeId__,\n' +
497
+ ' __vue_module_identifier__\n' +
498
+ ')\n'
469
499
470
500
// development-only code
471
501
if ( ! isProduction ) {
0 commit comments