Skip to content

Commit

Permalink
fix: relay correct error message on vue-template-compiler version mis…
Browse files Browse the repository at this point in the history
…match
  • Loading branch information
yyx990803 committed Jan 25, 2019
1 parent 9beed01 commit fdd0338
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ const { NS } = require('./plugin')

let errorEmitted = false

function loadTemplateCompiler () {
function loadTemplateCompiler (loaderContext) {
try {
return require('vue-template-compiler')
} catch (e) {
throw new Error(
`[vue-loader] vue-template-compiler must be installed as a peer dependency, ` +
`or a compatible compiler implementation must be passed via options.`
)
if (/version mismatch/.test(e.toString())) {
loaderContext.emitError(e)
} else {
loaderContext.emitError(new Error(
`[vue-loader] vue-template-compiler must be installed as a peer dependency, ` +
`or a compatible compiler implementation must be passed via options.`
))
}
}
}

Expand Down Expand Up @@ -62,7 +66,7 @@ module.exports = function (source) {

const descriptor = parse({
source,
compiler: options.compiler || loadTemplateCompiler(),
compiler: options.compiler || loadTemplateCompiler(loaderContext),
filename,
sourceRoot,
needMap: sourceMap
Expand Down

0 comments on commit fdd0338

Please sign in to comment.