@@ -93,9 +93,16 @@ function proxyCustomImporters(importers, loaderContext) {
93
93
* @param {object } loaderOptions
94
94
* @param {string } content
95
95
* @param {object } implementation
96
+ * @param {boolean } useSourceMap
96
97
* @returns {Object }
97
98
*/
98
- function getSassOptions ( loaderContext , loaderOptions , content , implementation ) {
99
+ function getSassOptions (
100
+ loaderContext ,
101
+ loaderOptions ,
102
+ content ,
103
+ implementation ,
104
+ useSourceMap
105
+ ) {
99
106
const options = klona (
100
107
loaderOptions . sassOptions
101
108
? typeof loaderOptions . sassOptions === 'function'
@@ -143,23 +150,19 @@ function getSassOptions(loaderContext, loaderOptions, content, implementation) {
143
150
options . outputStyle = 'compressed' ;
144
151
}
145
152
146
- const useSourceMap =
147
- typeof loaderOptions . sourceMap === 'boolean'
148
- ? loaderOptions . sourceMap
149
- : loaderContext . sourceMap ;
150
-
151
153
if ( useSourceMap ) {
152
154
// Deliberately overriding the sourceMap option here.
153
155
// node-sass won't produce source maps if the data option is used and options.sourceMap is not a string.
154
156
// In case it is a string, options.sourceMap should be a path where the source map is written.
155
157
// But since we're using the data option, the source map will not actually be written, but
156
158
// all paths in sourceMap.sources will be relative to that path.
157
159
// Pretty complicated... :(
158
- options . sourceMap = path . join ( process . cwd ( ) , '/sass.css.map' ) ;
159
- options . sourceMapRoot = process . cwd ( ) ;
160
+ options . sourceMap = true ;
161
+ options . outFile = path . join ( loaderContext . rootContext , 'style.css.map' ) ;
162
+ // options.sourceMapRoot = process.cwd();
160
163
options . sourceMapContents = true ;
161
164
options . omitSourceMapUrl = true ;
162
- options . sourceMapEmbed = false ;
165
+ // options.sourceMapEmbed = false;
163
166
}
164
167
165
168
const { resourcePath } = loaderContext ;
@@ -483,10 +486,36 @@ function getRenderFunctionFromSassImplementation(implementation) {
483
486
return nodeSassJobQueue . push . bind ( nodeSassJobQueue ) ;
484
487
}
485
488
489
+ const ABSOLUTE_SCHEME = / ^ [ A - Z a - z 0 - 9 + \- . ] + : / ;
490
+
491
+ function getURLType ( source ) {
492
+ if ( source [ 0 ] === '/' ) {
493
+ if ( source [ 1 ] === '/' ) {
494
+ return 'scheme-relative' ;
495
+ }
496
+
497
+ return 'path-absolute' ;
498
+ }
499
+
500
+ return ABSOLUTE_SCHEME . test ( source ) ? 'absolute' : 'path-relative' ;
501
+ }
502
+
503
+ function absolutifySourceMapSource ( sourceRoot , source ) {
504
+ const sourceType = getURLType ( source ) ;
505
+
506
+ // Do no touch `scheme-relative`, `path-absolute` and `absolute` types
507
+ if ( sourceType === 'path-relative' ) {
508
+ return path . resolve ( sourceRoot , path . normalize ( source ) ) ;
509
+ }
510
+
511
+ return source ;
512
+ }
513
+
486
514
export {
487
515
getSassImplementation ,
488
516
getSassOptions ,
489
517
getWebpackResolver ,
490
518
getWebpackImporter ,
491
519
getRenderFunctionFromSassImplementation ,
520
+ absolutifySourceMapSource ,
492
521
} ;
0 commit comments