Skip to content

Commit e5ac671

Browse files
committed
fix: compile root templates only
ref #11
1 parent 5098bf7 commit e5ac671

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

index.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,16 @@ module.exports = function markdownToVueLoader(source, map) {
127127
switch (language) {
128128
case 'vue': {
129129
const $$ = cheerio.load($code.text(), cheerioLoadOptions);
130+
const $body = $$('body');
130131
const $style = $$('style');
131132

132133
component = $$('script').html() || 'export default {};';
133134
scoped = $style.attr('scoped');
134135
style = $style.html();
135-
$$('template').each((i, element) => {
136+
137+
// Move <template> from <head> to <body>
138+
$body.append($$('head > template'));
139+
$body.children('template').each((i, element) => {
136140
template += $(element).html();
137141
});
138142
break;
@@ -151,8 +155,8 @@ module.exports = function markdownToVueLoader(source, map) {
151155
$style.remove();
152156

153157
// Move <template> from <head> to <body>
154-
$body.append($$('head template'));
155-
$body.find('template').each((i, element) => {
158+
$body.append($$('head > template'));
159+
$body.children('template').each((i, element) => {
156160
const $element = $(element);
157161

158162
$element.replaceWith($element.html());
@@ -241,15 +245,15 @@ module.exports = function markdownToVueLoader(source, map) {
241245
const $$ = cheerio.load('<template></template>');
242246
const $body = $$('body');
243247

244-
$body.append($$('head template'));
245-
246248
$('style').each((index, style) => {
247249
const $style = $(style);
248250

249251
$body.append($style);
250252
});
251253

252-
$$('template').html(`<div><div class="${options.componentNamespace}-${normalizedResourceName}">${$('body').html()}</div></div>`);
254+
// Move <template> from <head> to <body>
255+
$body.append($$('head > template'));
256+
$body.children('template').html(`<div><div class="${options.componentNamespace}-${normalizedResourceName}">${$('body').html()}</div></div>`);
253257

254258
if (options.exportSource || components.length > 0) {
255259
$body.append(`<script>

0 commit comments

Comments
 (0)