diff --git a/lib/compileTemplate.ts b/lib/compileTemplate.ts
index 679d7d2..912076c 100644
--- a/lib/compileTemplate.ts
+++ b/lib/compileTemplate.ts
@@ -40,6 +40,16 @@ export function compileTemplate (
return actuallyCompile(Object.assign({}, options, {
source: preprocess(options, preprocessor)
}))
+ } else if (preprocessLang) {
+ return {
+ code: (
+ `var render = function () {}\n` +
+ `var staticRenderFns = []\n`
+ ),
+ source: options.source,
+ tips: [`Component ${options.filename} uses lang ${preprocessLang} for template. Please install the language preprocessor.`],
+ errors: [`Component ${options.filename} uses lang ${preprocessLang} for template, however it is not installed.`]
+ };
} else {
return actuallyCompile(options)
}
diff --git a/test/compileTemplate.spec.ts b/test/compileTemplate.spec.ts
new file mode 100644
index 0000000..e638456
--- /dev/null
+++ b/test/compileTemplate.spec.ts
@@ -0,0 +1,45 @@
+import { parse } from '../lib/parse'
+import { compileTemplate } from '../lib/compileTemplate'
+import * as compiler from 'vue-template-compiler'
+
+test('preprocess pug', () => {
+ const template = parse({
+ source:
+ '\n' +
+ 'body\n' +
+ ' h1 Pug Examples\n' +
+ ' div.container\n' +
+ ' p Cool Pug example!\n' +
+ '\n',
+ filename: 'example.vue',
+ needMap: true
+ }).template
+
+ const result = compileTemplate({
+ filename: 'example.vue',
+ source: template.content,
+ preprocessLang: template.lang,
+ compiler: compiler
+ })
+
+ expect(result.errors.length).toBe(0)
+})
+
+test('warn missing preprocessor', () => {
+ const template = parse({
+ source:
+ '\n' +
+ '\n',
+ filename: 'example.vue',
+ needMap: true
+ }).template
+
+ const result = compileTemplate({
+ filename: 'example.vue',
+ source: template.content,
+ preprocessLang: template.lang,
+ compiler: compiler
+ })
+
+ expect(result.errors.length).toBe(1)
+})
\ No newline at end of file