|
1 | 1 | import deIndent from 'de-indent'
|
2 | 2 | import htmlMinifier from 'html-minifier'
|
3 | 3 | import parse5 from 'parse5'
|
4 |
| -import validateTemplate from 'vue-template-validator' |
| 4 | +import templateValidator from 'vue-template-validator' |
5 | 5 | import transpileVueTemplate from 'vue-template-es2015-compiler'
|
6 | 6 | import { compile } from './style/index'
|
7 | 7 | import templateProcessor from './template/index'
|
@@ -109,27 +109,31 @@ function injectTemplate (script, template, lang, options, modules) {
|
109 | 109 | throw new Error('[rollup-plugin-vue] could not find place to inject template in script.')
|
110 | 110 | }
|
111 | 111 |
|
| 112 | +var validateTemplate = function (code, content, id) { |
| 113 | + const warnings = templateValidator(code, content) |
| 114 | + if (warnings) { |
| 115 | + const relativePath = relative(process.cwd(), id) |
| 116 | + warnings.forEach((msg) => { |
| 117 | + console.warn(`\n Warning in ${relativePath}:\n ${msg}`) |
| 118 | + }) |
| 119 | + } |
| 120 | +} |
112 | 121 | /**
|
113 | 122 | * Compile template: DeIndent and minify html.
|
114 | 123 | */
|
115 | 124 | async function processTemplate (source, id, content, options, nodes, modules) {
|
116 | 125 | if (source === undefined) return undefined
|
117 | 126 |
|
| 127 | + const extras = { modules, id, lang: source.attrs.lang } |
118 | 128 | const { code } = source
|
119 | 129 | const template = deIndent(
|
120 | 130 | await (options.disableCssModuleStaticReplacement !== true
|
121 |
| - ? templateProcessor(code, { modules }, options) |
| 131 | + ? templateProcessor(code, extras, options) |
122 | 132 | : code)
|
123 | 133 | )
|
124 | 134 |
|
125 | 135 | if (!options.compileTemplate) {
|
126 |
| - const warnings = validateTemplate(code, content) |
127 |
| - if (warnings) { |
128 |
| - const relativePath = relative(process.cwd(), id) |
129 |
| - warnings.forEach((msg) => { |
130 |
| - console.warn(`\n Warning in ${relativePath}:\n ${msg}`) |
131 |
| - }) |
132 |
| - } |
| 136 | + validateTemplate(code, content, id) |
133 | 137 | }
|
134 | 138 |
|
135 | 139 | return htmlMinifier.minify(template, options.htmlMinifier)
|
|
0 commit comments