@@ -12,9 +12,8 @@ import {
12
12
loadConfig ,
13
13
getPostcssOptions ,
14
14
exec ,
15
- getSourceMapAbsolutePath ,
16
- getSourceMapRelativePath ,
17
15
normalizeSourceMap ,
16
+ normalizeSourceMapAfterPostcss ,
18
17
} from './utils' ;
19
18
20
19
/**
@@ -38,43 +37,40 @@ export default async function loader(content, sourceMap, meta = {}) {
38
37
baseDataPath : 'options' ,
39
38
} ) ;
40
39
41
- const file = this . resourcePath ;
42
- const configOptions =
40
+ const callback = this . async ( ) ;
41
+ const configOption =
43
42
typeof options . postcssOptions === 'undefined' ||
44
43
typeof options . postcssOptions . config === 'undefined'
45
44
? true
46
45
: options . postcssOptions . config ;
47
-
48
46
let loadedConfig = { } ;
49
47
50
- const callback = this . async ( ) ;
51
-
52
- if ( configOptions ) {
48
+ if ( configOption ) {
53
49
const dataForLoadConfig = {
54
- path : path . dirname ( file ) ,
50
+ path : path . dirname ( this . resourcePath ) ,
55
51
ctx : {
56
52
file : {
57
- extname : path . extname ( file ) ,
58
- dirname : path . dirname ( file ) ,
59
- basename : path . basename ( file ) ,
53
+ extname : path . extname ( this . resourcePath ) ,
54
+ dirname : path . dirname ( this . resourcePath ) ,
55
+ basename : path . basename ( this . resourcePath ) ,
60
56
} ,
61
57
options : { } ,
62
58
} ,
63
59
} ;
64
60
65
- if ( typeof configOptions . path !== 'undefined' ) {
66
- dataForLoadConfig . path = path . resolve ( configOptions . path ) ;
61
+ if ( typeof configOption . path !== 'undefined' ) {
62
+ dataForLoadConfig . path = path . resolve ( configOption . path ) ;
67
63
}
68
64
69
- if ( typeof configOptions . ctx !== 'undefined' ) {
70
- dataForLoadConfig . ctx . options = configOptions . ctx ;
65
+ if ( typeof configOption . ctx !== 'undefined' ) {
66
+ dataForLoadConfig . ctx . options = configOption . ctx ;
71
67
}
72
68
73
69
dataForLoadConfig . ctx . webpack = this ;
74
70
75
71
try {
76
72
loadedConfig = await loadConfig (
77
- configOptions ,
73
+ configOption ,
78
74
dataForLoadConfig . ctx ,
79
75
dataForLoadConfig . path ,
80
76
this
@@ -104,18 +100,12 @@ export default async function loader(content, sourceMap, meta = {}) {
104
100
105
101
if ( useSourceMap ) {
106
102
processOptions . map = { inline : false , annotation : false } ;
107
- // options.sourceMap === 'inline'
108
- // ? { inline: true, annotation: false }
109
- // : { inline: false, annotation: false };
110
103
111
104
if ( sourceMap ) {
112
- const sourceMapNormalized = normalizeSourceMap ( sourceMap ) ;
113
-
114
- sourceMapNormalized . sources = sourceMapNormalized . sources . map ( ( src ) =>
115
- getSourceMapRelativePath ( src , path . dirname ( file ) )
105
+ processOptions . map . prev = normalizeSourceMap (
106
+ sourceMap ,
107
+ this . resourcePath
116
108
) ;
117
-
118
- processOptions . map . prev = sourceMapNormalized ;
119
109
}
120
110
}
121
111
@@ -137,11 +127,11 @@ export default async function loader(content, sourceMap, meta = {}) {
137
127
return ;
138
128
}
139
129
140
- result . warnings ( ) . forEach ( ( warning ) => {
130
+ for ( const warning of result . warnings ( ) ) {
141
131
this . emitWarning ( new Warning ( warning ) ) ;
142
- } ) ;
132
+ }
143
133
144
- result . messages . forEach ( ( message ) => {
134
+ for ( const message of result . messages ) {
145
135
if ( message . type === 'dependency' ) {
146
136
this . addDependency ( message . file ) ;
147
137
}
@@ -154,16 +144,13 @@ export default async function loader(content, sourceMap, meta = {}) {
154
144
message . info
155
145
) ;
156
146
}
157
- } ) ;
147
+ }
158
148
159
- const map = result . map ? result . map . toJSON ( ) : null ;
149
+ // eslint-disable-next-line no-undefined
150
+ let map = result . map ? result . map . toJSON ( ) : undefined ;
160
151
161
152
if ( map && useSourceMap ) {
162
- if ( typeof map . file !== 'undefined' ) {
163
- delete map . file ;
164
- }
165
-
166
- map . sources = map . sources . map ( ( src ) => getSourceMapAbsolutePath ( src , file ) ) ;
153
+ map = normalizeSourceMapAfterPostcss ( map , this . resourcePath ) ;
167
154
}
168
155
169
156
const ast = {
0 commit comments