1
1
import postcss , {
2
2
ProcessOptions ,
3
- LazyResult ,
4
3
Result ,
5
- ResultMap ,
6
- ResultMessage
4
+ SourceMap ,
5
+ Message ,
6
+ LazyResult
7
7
} from 'postcss'
8
8
import trimPlugin from './stylePluginTrim'
9
9
import scopedPlugin from './stylePluginScoped'
@@ -35,28 +35,33 @@ export interface SFCStyleCompileOptions {
35
35
map ?: RawSourceMap
36
36
}
37
37
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
+
38
53
export interface SFCAsyncStyleCompileOptions extends SFCStyleCompileOptions {
39
54
isAsync ?: boolean
40
55
// css modules support, note this requires async so that we can get the
41
56
// resulting json
42
57
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
54
59
}
55
60
56
61
export interface SFCStyleCompileResults {
57
62
code : string
58
63
map : RawSourceMap | undefined
59
- rawResult : LazyResult | Result | undefined
64
+ rawResult : Result | LazyResult | undefined
60
65
errors : Error [ ]
61
66
modules ?: Record < string , string >
62
67
dependencies : Set < string >
@@ -149,7 +154,7 @@ export function doCompileStyle(
149
154
150
155
let result : LazyResult | undefined
151
156
let code : string | undefined
152
- let outMap : ResultMap | undefined
157
+ let outMap : SourceMap | undefined
153
158
// stylus output include plain css. so need remove the repeat item
154
159
const dependencies = new Set (
155
160
preProcessedSource ? preProcessedSource . dependencies : [ ]
@@ -162,7 +167,7 @@ export function doCompileStyle(
162
167
errors . push ( ...preProcessedSource . errors )
163
168
}
164
169
165
- const recordPlainCssDependencies = ( messages : ResultMessage [ ] ) => {
170
+ const recordPlainCssDependencies = ( messages : Message [ ] ) => {
166
171
messages . forEach ( msg => {
167
172
if ( msg . type === 'dependency' ) {
168
173
// postcss output path is absolute position path
@@ -226,7 +231,7 @@ function preprocess(
226
231
227
232
return preprocessor (
228
233
options . source ,
229
- options . map ,
234
+ options . inMap || options . map ,
230
235
{
231
236
filename : options . filename ,
232
237
...options . preprocessOptions
0 commit comments