Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 6589550

Browse files
flobacherdanbucholtz
authored andcommitted
fix(sass): output valid source maps, that chrome can parse (#306)
1 parent 13e930a commit 6589550

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

src/sass.ts

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,9 @@ function getComponentDirectories(moduleDirectories: string[], sassConfig: SassCo
230230
function render(context: BuildContext, sassConfig: SassConfig): Promise<string> {
231231
return new Promise((resolve, reject) => {
232232

233-
sassConfig.omitSourceMapUrl = true;
233+
sassConfig.omitSourceMapUrl = false;
234234

235235
if (sassConfig.sourceMap) {
236-
sassConfig.sourceMap = basename(sassConfig.outFile);
237236
sassConfig.sourceMapContents = true;
238237
}
239238

@@ -266,7 +265,8 @@ function renderSassSuccess(context: BuildContext, sassResult: Result, sassConfig
266265
let autoPrefixerMapOptions: any = false;
267266
if (sassConfig.sourceMap) {
268267
autoPrefixerMapOptions = {
269-
inline: false
268+
inline: false,
269+
prev: generateSourceMaps(sassResult, sassConfig)
270270
};
271271
}
272272

@@ -283,10 +283,10 @@ function renderSassSuccess(context: BuildContext, sassResult: Result, sassConfig
283283
Logger.warn(warn.toString());
284284
});
285285

286-
let apMapResult: string = null;
286+
let apMapResult: SassMap = null;
287287
if (sassConfig.sourceMap && postCssResult.map) {
288288
Logger.debug(`sass, parse postCssResult.map`);
289-
apMapResult = JSON.parse(postCssResult.map.toString()).mappings;
289+
apMapResult = generateSourceMaps(postCssResult, sassConfig);
290290
}
291291

292292
Logger.debug(`sass: postcss/autoprefixer completed`);
@@ -295,18 +295,13 @@ function renderSassSuccess(context: BuildContext, sassResult: Result, sassConfig
295295
}
296296

297297
// without autoprefixer
298-
generateSourceMaps(sassResult, sassConfig);
299-
300-
let sassMapResult: string = null;
301-
if (sassResult.map) {
302-
sassMapResult = JSON.parse(sassResult.map.toString()).mappings;
303-
}
298+
let sassMapResult: SassMap = generateSourceMaps(sassResult, sassConfig);
304299

305300
return writeOutput(context, sassConfig, sassResult.css.toString(), sassMapResult);
306301
}
307302

308303

309-
function generateSourceMaps(sassResult: Result, sassConfig: SassConfig) {
304+
function generateSourceMaps(sassResult: Result, sassConfig: SassConfig): SassMap {
310305
// this can be async and nothing needs to wait on it
311306

312307
// build Source Maps!
@@ -338,16 +333,13 @@ function generateSourceMaps(sassResult: Result, sassConfig: SassConfig) {
338333
return src;
339334
}
340335
});
341-
342-
// Replace the map file with the original file name (but new extension)
343-
// sassMap.file = gutil.replaceExtension(sassFileSrc, '.css');
344-
// Apply the map
345-
// applySourceMap(file, sassMap);
336+
return sassMap;
346337
}
347338
}
348339

349340

350-
function writeOutput(context: BuildContext, sassConfig: SassConfig, cssOutput: string, mappingsOutput: string): Promise<string> {
341+
function writeOutput(context: BuildContext, sassConfig: SassConfig, cssOutput: string, sourceMap: SassMap): Promise<string> {
342+
let mappingsOutput: string = JSON.stringify(sourceMap);
351343
return new Promise((resolve, reject) => {
352344

353345
Logger.debug(`sass start write output: ${sassConfig.outFile}`);
@@ -461,6 +453,9 @@ export interface SassConfig {
461453

462454

463455
export interface SassMap {
456+
version: number;
464457
file: string;
465-
sources: any[];
458+
sources: string[];
459+
mappings: string;
460+
names: any[];
466461
}

0 commit comments

Comments
 (0)