Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit b7862c2

Browse files
authored
Compile .vue files without <template> section (#23)
fix #18
1 parent 0242a03 commit b7862c2

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

src/vueTransform.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,19 @@ export default function vueTransform(code, filePath, options) {
146146
}
147147

148148
// 3. Don't touch files that don't look like Vue components
149-
if (!nodes.template && !nodes.script) {
149+
if (!nodes.script) {
150150
throw new Error('There must be at least one script tag or one' +
151151
' template tag per *.vue file.');
152152
}
153153

154154
// 4. Process template
155-
const template = processTemplate(nodes.template, filePath, code, options);
155+
const template = nodes.template
156+
? processTemplate(nodes.template, filePath, code, options)
157+
: undefined;
156158
let js;
157159
if (options.compileTemplate) {
158160
/* eslint-disable */
159-
const render = require('vue-template-compiler').compile(template);
161+
const render = template ? require('vue-template-compiler').compile(template) : undefined;
160162
/* eslint-enable */
161163
js = processScript(nodes.script, filePath, code, { render });
162164
} else {

test/expects/noTemplate.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var noTemplate = {
2+
render(h, c) {
3+
return h('h1', c.data.title);
4+
},
5+
data() {
6+
return { title: 'Hello' };
7+
},
8+
};
9+
10+
export default noTemplate;

test/fixtures/noTemplate.vue

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script>
2+
export default {
3+
render(h, c) {
4+
return h('h1', c.data.title);
5+
},
6+
data() {
7+
return { title: 'Hello' };
8+
},
9+
};
10+
</script>

0 commit comments

Comments
 (0)