Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit c50fd25

Browse files
committed
adjustments
1 parent a83d2dd commit c50fd25

File tree

1 file changed

+44
-32
lines changed

1 file changed

+44
-32
lines changed

Diff for: src/index.ts

+44-32
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,21 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
192192
if (preprocessLang) {
193193
preprocessOptions =
194194
preprocessOptions[preprocessLang] || preprocessOptions
195-
196-
if (
197-
['scss', 'sass'].includes(preprocessLang) &&
198-
!preprocessOptions.includePaths
199-
) {
200-
preprocessOptions = {
201-
includePaths: ['node_modules'],
202-
...preprocessOptions,
203-
}
195+
// include node_modules for imports by default
196+
switch (preprocessLang) {
197+
case 'scss':
198+
case 'sass':
199+
preprocessOptions = {
200+
includePaths: ['node_modules'],
201+
...preprocessOptions,
202+
}
203+
break
204+
case 'less':
205+
case 'stylus':
206+
preprocessOptions = {
207+
paths: ['node_modules'],
208+
...preprocessOptions,
209+
}
204210
}
205211
} else {
206212
preprocessOptions = {}
@@ -363,21 +369,15 @@ function getDescriptor(id: string) {
363369
throw new Error(`${id} is not parsed yet`)
364370
}
365371

366-
function parseSFC(
367-
code: string,
368-
id: string,
369-
sourceRoot: string
370-
): { descriptor: SFCDescriptor; errors: CompilerError[] } {
372+
function parseSFC(code: string, id: string, sourceRoot: string) {
371373
const { descriptor, errors } = parse(code, {
372374
sourceMap: true,
373375
filename: id,
374376
sourceRoot: sourceRoot,
375377
pad: 'line',
376378
})
377-
378379
cache.set(id, descriptor)
379-
380-
return { descriptor, errors }
380+
return { descriptor, errors: errors }
381381
}
382382

383383
function transformVueSFC(
@@ -548,21 +548,33 @@ function getCustomBlock(
548548
return code
549549
}
550550

551-
function createRollupError(id: string, error: CompilerError): RollupError {
552-
return {
553-
id,
554-
plugin: 'vue',
555-
pluginCode: String(error.code),
556-
message: error.message,
557-
frame: error.loc!.source,
558-
parserError: error,
559-
loc: error.loc
560-
? {
561-
file: id,
562-
line: error.loc.start.line,
563-
column: error.loc.start.column,
564-
}
565-
: undefined,
551+
function createRollupError(
552+
id: string,
553+
error: CompilerError | SyntaxError
554+
): RollupError {
555+
if ('code' in error) {
556+
return {
557+
id,
558+
plugin: 'vue',
559+
pluginCode: String(error.code),
560+
message: error.message,
561+
frame: error.loc!.source,
562+
parserError: error,
563+
loc: error.loc
564+
? {
565+
file: id,
566+
line: error.loc.start.line,
567+
column: error.loc.start.column,
568+
}
569+
: undefined,
570+
}
571+
} else {
572+
return {
573+
id,
574+
plugin: 'vue',
575+
message: error.message,
576+
parserError: error,
577+
}
566578
}
567579
}
568580

0 commit comments

Comments
 (0)