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

Lines changed: 5 additions & 3 deletions
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

Lines changed: 10 additions & 0 deletions
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

Lines changed: 10 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy