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

fix(sass sourcemaps): output valid source maps, that chrome can parse #306

Merged
merged 8 commits into from
Jan 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions src/sass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,9 @@ function getComponentDirectories(moduleDirectories: string[], sassConfig: SassCo
function render(context: BuildContext, sassConfig: SassConfig): Promise<string> {
return new Promise((resolve, reject) => {

sassConfig.omitSourceMapUrl = true;
sassConfig.omitSourceMapUrl = false;

if (sassConfig.sourceMap) {
sassConfig.sourceMap = basename(sassConfig.outFile);
sassConfig.sourceMapContents = true;
}

Expand Down Expand Up @@ -263,7 +262,8 @@ function renderSassSuccess(context: BuildContext, sassResult: Result, sassConfig
let autoPrefixerMapOptions: any = false;
if (sassConfig.sourceMap) {
autoPrefixerMapOptions = {
inline: false
inline: false,
prev: generateSourceMaps(sassResult, sassConfig)
};
}

Expand All @@ -280,10 +280,10 @@ function renderSassSuccess(context: BuildContext, sassResult: Result, sassConfig
Logger.warn(warn.toString());
});

let apMapResult: string = null;
let apMapResult: SassMap = null;
if (sassConfig.sourceMap && postCssResult.map) {
Logger.debug(`sass, parse postCssResult.map`);
apMapResult = JSON.parse(postCssResult.map.toString()).mappings;
apMapResult = generateSourceMaps(postCssResult, sassConfig);
}

Logger.debug(`sass: postcss/autoprefixer completed`);
Expand All @@ -292,18 +292,13 @@ function renderSassSuccess(context: BuildContext, sassResult: Result, sassConfig
}

// without autoprefixer
generateSourceMaps(sassResult, sassConfig);

let sassMapResult: string = null;
if (sassResult.map) {
sassMapResult = JSON.parse(sassResult.map.toString()).mappings;
}
let sassMapResult: SassMap = generateSourceMaps(sassResult, sassConfig);

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


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

// build Source Maps!
Expand Down Expand Up @@ -335,16 +330,13 @@ function generateSourceMaps(sassResult: Result, sassConfig: SassConfig) {
return src;
}
});

// Replace the map file with the original file name (but new extension)
// sassMap.file = gutil.replaceExtension(sassFileSrc, '.css');
// Apply the map
// applySourceMap(file, sassMap);
return sassMap;
}
}


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

Logger.debug(`sass start write output: ${sassConfig.outFile}`);
Expand Down Expand Up @@ -458,6 +450,9 @@ export interface SassConfig {


export interface SassMap {
version: number;
file: string;
sources: any[];
sources: string[];
mappings: string;
names: any[];
}