@@ -39,6 +39,10 @@ export interface Options
39
39
target : 'node' | 'browser'
40
40
exposeFilename : boolean
41
41
42
+ // if true, handle preprocessors directly instead of delegating to other
43
+ // rollup plugins
44
+ preprocessStyles ?: boolean
45
+
42
46
// TODO this will be exposed via SFCAsyncStyleCompileOptions which we forgot
43
47
// to export in @vue /compiler-sfc
44
48
cssModulesOptions ?: {
@@ -194,7 +198,9 @@ export default function PluginVue(userOptions: Partial<Options> = {}): Plugin {
194
198
scoped : block . scoped ,
195
199
modules : ! ! block . module ,
196
200
modulesOptions : options . cssModulesOptions ,
197
- preprocessLang : block . lang as any ,
201
+ preprocessLang : options . preprocessStyles
202
+ ? ( block . lang as any )
203
+ : undefined ,
198
204
preprocessCustomRequire : options . preprocessCustomRequire ,
199
205
} )
200
206
@@ -355,7 +361,12 @@ function transformVueSFC(
355
361
hasScoped
356
362
)
357
363
const scriptImport = getScriptCode ( descriptor , resourcePath )
358
- const stylesCode = getStyleCode ( descriptor , resourcePath , id )
364
+ const stylesCode = getStyleCode (
365
+ descriptor ,
366
+ resourcePath ,
367
+ id ,
368
+ options . preprocessStyles
369
+ )
359
370
const output = [
360
371
scriptImport ,
361
372
templateImport ,
@@ -412,7 +423,8 @@ function getScriptCode(descriptor: SFCDescriptor, resourcePath: string) {
412
423
function getStyleCode (
413
424
descriptor : SFCDescriptor ,
414
425
resourcePath : string ,
415
- id : string
426
+ id : string ,
427
+ preprocessStyles ?: boolean
416
428
) {
417
429
let stylesCode = ``
418
430
let hasCSSModules = false
@@ -421,7 +433,7 @@ function getStyleCode(
421
433
const src = style . src || resourcePath
422
434
// do not include module in default query, since we use it to indicate
423
435
// that the module needs to export the modules json
424
- const attrsQuery = attrsToQuery ( style . attrs , 'css' )
436
+ const attrsQuery = attrsToQuery ( style . attrs , 'css' , preprocessStyles )
425
437
const attrsQueryWithoutModule = attrsQuery . replace ( / & m o d u l e ( = t r u e ) ? / , '' )
426
438
// make sure to only pass id when necessary so that we don't inject
427
439
// duplicate tags when multiple components import the same css file
@@ -471,7 +483,11 @@ function createRollupError(id: string, error: CompilerError): RollupError {
471
483
// these are built-in query parameters so should be ignored
472
484
// if the user happen to add them as attrs
473
485
const ignoreList = [ 'id' , 'index' , 'src' , 'type' ]
474
- function attrsToQuery ( attrs : SFCBlock [ 'attrs' ] , langFallback ?: string ) : string {
486
+ function attrsToQuery (
487
+ attrs : SFCBlock [ 'attrs' ] ,
488
+ langFallback ?: string ,
489
+ forceLangFallback = false
490
+ ) : string {
475
491
let query = ``
476
492
for ( const name in attrs ) {
477
493
const value = attrs [ name ]
@@ -482,7 +498,12 @@ function attrsToQuery(attrs: SFCBlock['attrs'], langFallback?: string): string {
482
498
}
483
499
}
484
500
if ( langFallback ) {
485
- query += `lang` in attrs ? `.${ langFallback } ` : `&lang.${ langFallback } `
501
+ query +=
502
+ `lang` in attrs
503
+ ? forceLangFallback
504
+ ? `.${ langFallback } `
505
+ : ``
506
+ : `&lang.${ langFallback } `
486
507
}
487
508
return query
488
509
}
0 commit comments