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

Commit e2faa2d

Browse files
committed
adjustments
1 parent 20f79f1 commit e2faa2d

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
@@ -196,15 +196,21 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
196196
if (preprocessLang) {
197197
preprocessOptions =
198198
preprocessOptions[preprocessLang] || preprocessOptions
199-
200-
if (
201-
['scss', 'sass'].includes(preprocessLang) &&
202-
!preprocessOptions.includePaths
203-
) {
204-
preprocessOptions = {
205-
includePaths: ['node_modules'],
206-
...preprocessOptions,
207-
}
199+
// include node_modules for imports by default
200+
switch (preprocessLang) {
201+
case 'scss':
202+
case 'sass':
203+
preprocessOptions = {
204+
includePaths: ['node_modules'],
205+
...preprocessOptions,
206+
}
207+
break
208+
case 'less':
209+
case 'stylus':
210+
preprocessOptions = {
211+
paths: ['node_modules'],
212+
...preprocessOptions,
213+
}
208214
}
209215
} else {
210216
preprocessOptions = {}
@@ -368,20 +374,14 @@ function getDescriptor(id: string) {
368374
throw new Error(`${id} is not parsed yet`)
369375
}
370376

371-
function parseSFC(
372-
code: string,
373-
id: string,
374-
sourceRoot: string
375-
): { descriptor: SFCDescriptor; errors: CompilerError[] } {
377+
function parseSFC(code: string, id: string, sourceRoot: string) {
376378
const { descriptor, errors } = parse(code, {
377379
sourceMap: true,
378380
filename: id,
379381
sourceRoot: sourceRoot,
380382
})
381-
382383
cache.set(id, descriptor)
383-
384-
return { descriptor, errors }
384+
return { descriptor, errors: errors }
385385
}
386386

387387
function transformVueSFC(
@@ -558,21 +558,33 @@ function getCustomBlock(
558558
return code
559559
}
560560

561-
function createRollupError(id: string, error: CompilerError): RollupError {
562-
return {
563-
id,
564-
plugin: 'vue',
565-
pluginCode: String(error.code),
566-
message: error.message,
567-
frame: error.loc!.source,
568-
parserError: error,
569-
loc: error.loc
570-
? {
571-
file: id,
572-
line: error.loc.start.line,
573-
column: error.loc.start.column,
574-
}
575-
: undefined,
561+
function createRollupError(
562+
id: string,
563+
error: CompilerError | SyntaxError
564+
): RollupError {
565+
if ('code' in error) {
566+
return {
567+
id,
568+
plugin: 'vue',
569+
pluginCode: String(error.code),
570+
message: error.message,
571+
frame: error.loc!.source,
572+
parserError: error,
573+
loc: error.loc
574+
? {
575+
file: id,
576+
line: error.loc.start.line,
577+
column: error.loc.start.column,
578+
}
579+
: undefined,
580+
}
581+
} else {
582+
return {
583+
id,
584+
plugin: 'vue',
585+
message: error.message,
586+
parserError: error,
587+
}
576588
}
577589
}
578590

0 commit comments

Comments
 (0)