11import postcss , {
22 ProcessOptions ,
3- LazyResult ,
43 Result ,
5- ResultMap ,
6- ResultMessage
4+ SourceMap ,
5+ Message ,
6+ LazyResult
77} from 'postcss'
88import trimPlugin from './stylePluginTrim'
99import scopedPlugin from './stylePluginScoped'
@@ -35,28 +35,33 @@ export interface SFCStyleCompileOptions {
3535 map ?: RawSourceMap
3636}
3737
38+ /**
39+ * Aligns with postcss-modules
40+ * https://github.com/css-modules/postcss-modules
41+ */
42+ export interface CSSModulesOptions {
43+ scopeBehaviour ?: 'global' | 'local'
44+ generateScopedName ?:
45+ | string
46+ | ( ( name : string , filename : string , css : string ) => string )
47+ hashPrefix ?: string
48+ localsConvention ?: 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly'
49+ exportGlobals ?: boolean
50+ globalModulePaths ?: string [ ]
51+ }
52+
3853export interface SFCAsyncStyleCompileOptions extends SFCStyleCompileOptions {
3954 isAsync ?: boolean
4055 // css modules support, note this requires async so that we can get the
4156 // resulting json
4257 modules ?: boolean
43- // maps to postcss-modules options
44- // https://github.com/css-modules/postcss-modules
45- modulesOptions ?: {
46- scopeBehaviour ?: 'global' | 'local'
47- globalModulePaths ?: string [ ]
48- generateScopedName ?:
49- | string
50- | ( ( name : string , filename : string , css : string ) => string )
51- hashPrefix ?: string
52- localsConvention ?: 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly'
53- }
58+ modulesOptions ?: CSSModulesOptions
5459}
5560
5661export interface SFCStyleCompileResults {
5762 code : string
5863 map : RawSourceMap | undefined
59- rawResult : LazyResult | Result | undefined
64+ rawResult : Result | LazyResult | undefined
6065 errors : Error [ ]
6166 modules ?: Record < string , string >
6267 dependencies : Set < string >
@@ -149,7 +154,7 @@ export function doCompileStyle(
149154
150155 let result : LazyResult | undefined
151156 let code : string | undefined
152- let outMap : ResultMap | undefined
157+ let outMap : SourceMap | undefined
153158 // stylus output include plain css. so need remove the repeat item
154159 const dependencies = new Set (
155160 preProcessedSource ? preProcessedSource . dependencies : [ ]
@@ -162,7 +167,7 @@ export function doCompileStyle(
162167 errors . push ( ...preProcessedSource . errors )
163168 }
164169
165- const recordPlainCssDependencies = ( messages : ResultMessage [ ] ) => {
170+ const recordPlainCssDependencies = ( messages : Message [ ] ) => {
166171 messages . forEach ( msg => {
167172 if ( msg . type === 'dependency' ) {
168173 // postcss output path is absolute position path
@@ -226,7 +231,7 @@ function preprocess(
226231
227232 return preprocessor (
228233 options . source ,
229- options . map ,
234+ options . inMap || options . map ,
230235 {
231236 filename : options . filename ,
232237 ...options . preprocessOptions
0 commit comments