2
2
MIT License http://www.opensource.org/licenses/mit-license.php
3
3
Author Tobias Koppers @sokra
4
4
*/
5
+ import path from 'path' ;
6
+
5
7
import { getOptions , stringifyRequest } from 'loader-utils' ;
6
8
import postcss from 'postcss' ;
7
9
import postcssPkg from 'postcss/package.json' ;
@@ -26,6 +28,7 @@ import {
26
28
getModulesPlugins ,
27
29
normalizeSourceMap ,
28
30
sort ,
31
+ getSourceMapRelativePath ,
29
32
} from './utils' ;
30
33
31
34
export default async function loader ( content , map , meta ) {
@@ -151,6 +154,14 @@ export default async function loader(content, map, meta) {
151
154
}
152
155
}
153
156
157
+ const sourceMap = map ? normalizeSourceMap ( map ) : null ;
158
+
159
+ if ( sourceMap ) {
160
+ sourceMap . sources = sourceMap . sources . map ( ( src ) =>
161
+ getSourceMapRelativePath ( src , path . dirname ( this . resourcePath ) )
162
+ ) ;
163
+ }
164
+
154
165
let result ;
155
166
156
167
try {
@@ -160,7 +171,7 @@ export default async function loader(content, map, meta) {
160
171
map : options . sourceMap
161
172
? {
162
173
// Some loaders (example `"postcss-loader": "1.x.x"`) always generates source map, we should remove it
163
- prev : map ? normalizeSourceMap ( map ) : null ,
174
+ prev : sourceMap ,
164
175
inline : false ,
165
176
annotation : false ,
166
177
}
@@ -198,7 +209,14 @@ export default async function loader(content, map, meta) {
198
209
}
199
210
200
211
const importCode = getImportCode ( imports , options ) ;
201
- const moduleCode = getModuleCode ( result , api , replacements , options ) ;
212
+ const moduleCode = getModuleCode (
213
+ result ,
214
+ api ,
215
+ replacements ,
216
+ options ,
217
+ this . resourcePath ,
218
+ this . rootContext
219
+ ) ;
202
220
const exportCode = getExportCode ( exports , replacements , options ) ;
203
221
204
222
callback ( null , `${ importCode } ${ moduleCode } ${ exportCode } ` ) ;
0 commit comments