@@ -192,18 +192,45 @@ function getPostcssOptions(loaderContext, config, postcssOptions = {}) {
192192
193193 const processOptionsFromConfig = { ...config } ;
194194
195+ if ( processOptionsFromConfig . from ) {
196+ processOptionsFromConfig . from = path . resolve (
197+ path . dirname ( config . file ) ,
198+ processOptionsFromConfig . from
199+ ) ;
200+ }
201+
202+ if ( processOptionsFromConfig . to ) {
203+ processOptionsFromConfig . to = path . resolve (
204+ path . dirname ( config . file ) ,
205+ processOptionsFromConfig . to
206+ ) ;
207+ }
208+
195209 // No need them for processOptions
196210 delete processOptionsFromConfig . plugins ;
197211 delete processOptionsFromConfig . file ;
198212
199213 const processOptionsFromOptions = { ...normalizedPostcssOptions } ;
200214
215+ if ( processOptionsFromOptions . from ) {
216+ processOptionsFromOptions . from = path . resolve (
217+ loaderContext . rootContext ,
218+ processOptionsFromOptions . from
219+ ) ;
220+ }
221+
222+ if ( processOptionsFromOptions . to ) {
223+ processOptionsFromOptions . to = path . resolve (
224+ loaderContext . rootContext ,
225+ processOptionsFromOptions . to
226+ ) ;
227+ }
228+
201229 // No need them for processOptions
202230 delete processOptionsFromOptions . config ;
203231 delete processOptionsFromOptions . plugins ;
204232
205233 const processOptions = {
206- // TODO path.resolve
207234 from : file ,
208235 to : file ,
209236 map : false ,
@@ -272,7 +299,7 @@ function getURLType(source) {
272299 return ABSOLUTE_SCHEME . test ( source ) ? 'absolute' : 'path-relative' ;
273300}
274301
275- function normalizeSourceMap ( map , resourcePath ) {
302+ function normalizeSourceMap ( map , resourceContext ) {
276303 let newMap = map ;
277304
278305 // Some loader emit source map as string
@@ -298,7 +325,7 @@ function normalizeSourceMap(map, resourcePath) {
298325 ? path . resolve ( sourceRoot , path . normalize ( source ) )
299326 : path . normalize ( source ) ;
300327
301- return path . relative ( path . dirname ( resourcePath ) , absoluteSource ) ;
328+ return path . relative ( resourceContext , absoluteSource ) ;
302329 }
303330
304331 return source ;
@@ -308,7 +335,7 @@ function normalizeSourceMap(map, resourcePath) {
308335 return newMap ;
309336}
310337
311- function normalizeSourceMapAfterPostcss ( map , resourcePath ) {
338+ function normalizeSourceMapAfterPostcss ( map , resourceContext ) {
312339 const newMap = map ;
313340
314341 // result.map.file is an optional property that provides the output filename.
@@ -329,9 +356,7 @@ function normalizeSourceMapAfterPostcss(map, resourcePath) {
329356
330357 // Do no touch `scheme-relative`, `path-absolute` and `absolute` types
331358 if ( sourceType === 'path-relative' ) {
332- const dirname = path . dirname ( resourcePath ) ;
333-
334- return path . resolve ( dirname , source ) ;
359+ return path . resolve ( resourceContext , source ) ;
335360 }
336361
337362 return source ;
0 commit comments