diff --git a/lib/loader.js b/lib/loader.js index 177ddf0b0..6eba9fe6e 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -59,16 +59,20 @@ module.exports = function (content) { ) } - function getRequireForImport (impt) { + function getRequireForImport (type, impt, scoped) { return 'require(' + - loaderUtils.stringifyRequest(self, - '-!' + - getLoaderString('style', impt, impt.scoped) + - impt.src - ) + + getRequireForImportString(type, impt, scoped) + ')\n' } + function getRequireForImportString (type, impt, scoped) { + return loaderUtils.stringifyRequest(self, + '-!' + + getLoaderString(type, impt, scoped) + + impt.src + ) + } + function getLoaderString (type, part, scoped) { var lang = part.lang || defaultLang[type] var loader = loaders[lang] @@ -135,7 +139,7 @@ module.exports = function (content) { // add requires for src imports parts.styleImports.forEach(function (impt) { if (impt.scoped) hasLocalStyles = true - output += getRequireForImport(impt) + output += getRequireForImport('style', impt, impt.scoped) }) // add requires for styles @@ -152,11 +156,16 @@ module.exports = function (content) { } // add require for template + var template if (parts.template.length) { + template = parts.template[0] output += ';(typeof module.exports === "function" ' + '? module.exports.options ' + - ': module.exports).template = ' + - getRequire('template', parts.template[0], 0, hasLocalStyles) + ': module.exports).template = ' + ( + template.src + ? getRequireForImport('template', template, hasLocalStyles) + : getRequire('template', template, 0, hasLocalStyles) + ) } // hot reload @@ -165,7 +174,11 @@ module.exports = function (content) { (parts.script.length || parts.template.length) ) { var scriptString = parts.script.length ? getRequireString('script', parts.script[0], 0) : '' - var templateString = parts.template.length ? getRequireString('template', parts.template[0], 0, hasLocalStyles) : '' + var templateString = template + ? template.src + ? getRequireForImportString('template', template, hasLocalStyles) + : getRequireString('template', template, 0, hasLocalStyles) + : '' var accepted = [] if (scriptString) { accepted.push(scriptString.slice(1, -1)) diff --git a/lib/parser.js b/lib/parser.js index 7cb36bdc1..8302fb4fe 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -19,17 +19,36 @@ module.exports = function (content) { var src = getAttribute(node, 'src') var scoped = getAttribute(node, 'scoped') != null + // node count check + if ( + (type === 'script' || type === 'template') && + output[type].length > 0 + ) { + return cb(new Error( + '[vue-loader] Only one