@@ -23,6 +23,7 @@ import {
2323import { selectBlock } from './select'
2424import { genHotReloadCode } from './hotReload'
2525import { genCSSModulesCode } from './cssModules'
26+ import { formatError } from './formatError'
2627
2728const VueLoaderPlugin = require ( './plugin' )
2829
@@ -37,7 +38,7 @@ export interface VueLoaderOptions {
3738
3839let errorEmitted = false
3940
40- const loader : webpack . loader . Loader = function ( source ) {
41+ const loader : webpack . loader . Loader = function ( source : string ) {
4142 const loaderContext = this
4243
4344 // check if plugin is installed
@@ -75,10 +76,17 @@ const loader: webpack.loader.Loader = function(source) {
7576 const isServer = target === 'node'
7677 const isProduction = mode === 'production'
7778
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+ }
8290
8391 // if the query has a type field, this is a language block request
8492 // e.g. foo.vue?type=template&id=xxxxx
0 commit comments