@@ -47,43 +47,43 @@ module.exports = function loader (css, map) {
47
47
48
48
validateOptions ( require ( './options.json' ) , options , 'PostCSS Loader' )
49
49
50
- const rc = {
51
- path : path . dirname ( file ) ,
52
- ctx : {
53
- file : {
54
- extname : path . extname ( file ) ,
55
- dirname : path . dirname ( file ) ,
56
- basename : path . basename ( file )
57
- } ,
58
- options : { }
59
- }
60
- }
50
+ const sourceMap = options . sourceMap
61
51
62
- if ( options . config ) {
63
- if ( options . config . path ) {
64
- rc . path = path . resolve ( options . config . path )
65
- }
52
+ Promise . resolve ( ) . then ( ( ) => {
53
+ const length = Object . keys ( options )
54
+ . filter ( ( option ) => {
55
+ // if (option === 'exec') return
56
+ if ( option === 'config' ) return
57
+ if ( option === 'sourceMap' ) return
66
58
67
- if ( options . config . ctx ) {
68
- rc . ctx . options = options . config . ctx
59
+ return option
60
+ } )
61
+ . length
62
+
63
+ if ( length ) {
64
+ return parseOptions . call ( this , options )
69
65
}
70
- }
71
66
72
- const sourceMap = options . sourceMap
67
+ const rc = {
68
+ path : path . dirname ( file ) ,
69
+ ctx : {
70
+ file : {
71
+ extname : path . extname ( file ) ,
72
+ dirname : path . dirname ( file ) ,
73
+ basename : path . basename ( file )
74
+ } ,
75
+ options : { }
76
+ }
77
+ }
73
78
74
- Promise . resolve ( ) . then ( ( ) => {
75
- const length = Object . keys ( options ) . length
79
+ if ( options . config ) {
80
+ if ( options . config . path ) {
81
+ rc . path = path . resolve ( options . config . path )
82
+ }
76
83
77
- // TODO
78
- // Refactor
79
- if ( ! options . config && ! sourceMap && length ) {
80
- return parseOptions . call ( this , options )
81
- } else if ( options . config && ! sourceMap && length > 1 ) {
82
- return parseOptions . call ( this , options )
83
- } else if ( ! options . config && sourceMap && length > 1 ) {
84
- return parseOptions . call ( this , options )
85
- } else if ( options . config && sourceMap && length > 2 ) {
86
- return parseOptions . call ( this , options )
84
+ if ( options . config . ctx ) {
85
+ rc . ctx . options = options . config . ctx
86
+ }
87
87
}
88
88
89
89
return postcssrc ( rc . ctx , rc . path , { argv : false } )
0 commit comments