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

Commit 0fd3ea5

Browse files
committed
Add option compileTemplate
1 parent b3b4c3d commit 0fd3ea5

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default function vue(options = {}) {
77
const filter = createFilter(options.include, options.exclude);
88
const styles = {};
99
let dest = options.css;
10+
const compileTemplate = !!options.compileTemplate
1011

1112
return {
1213
name: 'vue',
@@ -19,7 +20,7 @@ export default function vue(options = {}) {
1920
return null;
2021
}
2122

22-
const { js, css } = vueTransform(source, id);
23+
const { js, css } = vueTransform(source, id, { compileTemplate });
2324

2425
// Map of every stylesheet
2526
styles[id] = css || {};

src/vueTransform.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function injectRender(script, render) {
5555
return `function(){${code.replace(/with\(this\)/g, 'if("__VUE_WITH__")')}}`;
5656
}
5757
return script.split(matches[1])
58-
.join(`${matches[1]} render: ${toFunction(render.render)}, staticRenderFns: [${render.staticRenderFns.map(toFunction).join(',')}],`);
58+
.join(`${matches[1]} \n /* istanbul ignore next */\n render: ${toFunction(render.render)},\n /* istanbul ignore next */\n staticRenderFns: [${render.staticRenderFns.map(toFunction).join(',')}],`);
5959
}
6060
throw new Error('[rollup-plugin-vue] could not find place to inject template in script.');
6161
}
@@ -114,11 +114,10 @@ function processScript(node, filePath, content, {template, render}) {
114114
}
115115
script = deIndent(script);
116116

117-
console.log(script)
118117
return script;
119118
}
120119

121-
export default function vueTransform(code, filePath) {
120+
export default function vueTransform(code, filePath, options) {
122121
// 1. Parse the file into an HTML tree
123122
const fragment = parse5.parseFragment(code, { locationInfo: true });
124123

@@ -136,11 +135,17 @@ export default function vueTransform(code, filePath) {
136135

137136
// 4. Process template
138137
const template = processTemplate(nodes.template, filePath, code);
138+
let js = null
139+
if (options.compileTemplate) {
139140
const render = compileTemplate(template);
141+
js = processScript(nodes.script, filePath, code, { render })
142+
} else {
143+
js = processScript(nodes.script, filePath, code, { template })
144+
}
140145

141146
// 5. Process script & style
142147
return {
143-
js: processScript(nodes.script, filePath, code, { render }),
148+
js,
144149
css: nodes.style && {
145150
content: parse5.serialize(nodes.style),
146151
lang: checkLang(nodes.style),

0 commit comments

Comments
 (0)