@@ -23,6 +23,7 @@ import {
23
23
import { selectBlock } from './select'
24
24
import { genHotReloadCode } from './hotReload'
25
25
import { genCSSModulesCode } from './cssModules'
26
+ import { formatError } from './formatError'
26
27
27
28
const VueLoaderPlugin = require ( './plugin' )
28
29
@@ -37,7 +38,7 @@ export interface VueLoaderOptions {
37
38
38
39
let errorEmitted = false
39
40
40
- const loader : webpack . loader . Loader = function ( source ) {
41
+ const loader : webpack . loader . Loader = function ( source : string ) {
41
42
const loaderContext = this
42
43
43
44
// check if plugin is installed
@@ -75,10 +76,17 @@ const loader: webpack.loader.Loader = function(source) {
75
76
const isServer = target === 'node'
76
77
const isProduction = mode === 'production'
77
78
78
- const descriptor = parse ( String ( source ) , {
79
- filename : resourcePath ,
80
- sourceMap
81
- } )
79
+ let descriptor
80
+ try {
81
+ descriptor = parse ( source , {
82
+ filename : resourcePath ,
83
+ sourceMap
84
+ } )
85
+ } catch ( e ) {
86
+ formatError ( e , source , resourcePath )
87
+ loaderContext . emitError ( e )
88
+ return ``
89
+ }
82
90
83
91
// if the query has a type field, this is a language block request
84
92
// e.g. foo.vue?type=template&id=xxxxx
0 commit comments