@@ -108,6 +108,10 @@ module.exports = function (content) {
108108 ')'
109109 }
110110
111+ function getImport ( type , part , index , scoped ) {
112+ return 'import __vue_' + type + '__ from ' + getRequireString ( type , part , index , scoped )
113+ }
114+
111115 function getRequireString ( type , part , index , scoped ) {
112116 return loaderUtils . stringifyRequest ( loaderContext ,
113117 // disable all configuration loaders
@@ -127,6 +131,10 @@ module.exports = function (content) {
127131 ')'
128132 }
129133
134+ function getImportForImport ( type , impt , scoped ) {
135+ return 'import __vue_' + type + '__ from ' + getRequireForImportString ( type , impt , scoped )
136+ }
137+
130138 function getRequireForImportString ( type , impt , scoped ) {
131139 return loaderUtils . stringifyRequest ( loaderContext ,
132140 '!!' +
@@ -421,52 +429,74 @@ module.exports = function (content) {
421429 // scopeId,
422430 // moduleIdentifier (server only)
423431 // )
424- output += 'var Component = require(' +
425- loaderUtils . stringifyRequest ( loaderContext , '!' + componentNormalizerPath ) +
426- ')(\n'
432+ if ( options . esModule ) {
433+ output += 'import normalizeComponent from ' +
434+ loaderUtils . stringifyRequest ( loaderContext , '!' + componentNormalizerPath ) +
435+ '\n'
436+ } else {
437+ output += 'var normalizeComponent = require(' +
438+ loaderUtils . stringifyRequest ( loaderContext , '!' + componentNormalizerPath ) +
439+ ')\n'
440+ }
427441
428442 // <script>
429- output += ' /* script */\n '
443+ output += '/* script */\n'
430444 var script = parts . script
431445 if ( script ) {
432- output += script . src
433- ? getRequireForImport ( 'script' , script )
434- : getRequire ( 'script' , script )
446+ if ( options . esModule ) {
447+ output += script . src
448+ ? getImportForImport ( 'script' , script )
449+ : getImport ( 'script' , script ) + '\n'
450+ } else {
451+ output += 'var __vue_script__ = ' + ( script . src
452+ ? getRequireForImport ( 'script' , script )
453+ : getRequire ( 'script' , script ) ) + '\n'
454+ }
435455 // inject loader interop
436456 if ( query . inject ) {
437- output += '(injections)'
457+ output += '__vue_script__ = __vue_script__ (injections)\n '
438458 }
439459 } else {
440- output += 'null'
460+ output += 'var __vue_script__ = null\n '
441461 }
442- output += ',\n'
443462
444463 // <template>
445- output += ' /* template */\n '
464+ output += '/* template */\n'
446465 var template = parts . template
447466 if ( template ) {
448- output += template . src
449- ? getRequireForImport ( 'template' , template )
450- : getRequire ( 'template' , template )
467+ if ( options . esModule ) {
468+ output += ( template . src
469+ ? getImportForImport ( 'template' , template )
470+ : getImport ( 'template' , template ) ) + '\n'
471+ } else {
472+ output += 'var __vue_template__ = ' + ( template . src
473+ ? getRequireForImport ( 'template' , template )
474+ : getRequire ( 'template' , template ) ) + '\n'
475+ }
451476 } else {
452- output += 'null'
477+ output += 'var __vue_template__ = null\n '
453478 }
454- output += ',\n'
455479
456480 // style
457- output += ' /* styles */\n '
458- output += ( parts . styles . length ? 'injectStyle' : 'null' ) + ', \n'
481+ output += '/* styles */\n'
482+ output += 'var __vue_styles__ = ' + ( parts . styles . length ? 'injectStyle' : 'null' ) + '\n'
459483
460484 // scopeId
461- output += ' /* scopeId */\n '
462- output += ( hasScoped ? JSON . stringify ( moduleId ) : 'null' ) + ', \n'
485+ output += '/* scopeId */\n'
486+ output += 'var __vue_scopeId__ = ' + ( hasScoped ? JSON . stringify ( moduleId ) : 'null' ) + '\n'
463487
464488 // moduleIdentifier (server only)
465- output += ' /* moduleIdentifier (server only) */\n '
466- output += ( isServer ? JSON . stringify ( hash ( this . request ) ) : 'null' ) + '\n'
489+ output += '/* moduleIdentifier (server only) */\n'
490+ output += 'var __vue_module_identifier__ = ' + ( isServer ? JSON . stringify ( hash ( this . request ) ) : 'null' ) + '\n'
467491
468492 // close normalizeComponent call
469- output += ')\n'
493+ output += 'var Component = normalizeComponent(\n' +
494+ ' __vue_script__,\n' +
495+ ' __vue_template__,\n' +
496+ ' __vue_styles__,\n' +
497+ ' __vue_scopeId__,\n' +
498+ ' __vue_module_identifier__\n' +
499+ ')\n'
470500
471501 // development-only code
472502 if ( ! isProduction ) {
@@ -552,7 +582,7 @@ module.exports = function (content) {
552582 }
553583 // final export
554584 if ( options . esModule ) {
555- output += '\nexports.__esModule = true;\nexports[" default"] = Component.exports\n'
585+ output += '\nexport default Component.exports\n'
556586 } else {
557587 output += '\nmodule.exports = Component.exports\n'
558588 }
0 commit comments