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

Commit

Permalink
fix(sass): output valid source maps, that chrome can parse (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
flobacher authored and danbucholtz committed Jan 28, 2017
1 parent 13e930a commit 6589550
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions src/sass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,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 @@ -266,7 +265,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 @@ -283,10 +283,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 @@ -295,18 +295,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 @@ -338,16 +333,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 @@ -461,6 +453,9 @@ export interface SassConfig {


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

0 comments on commit 6589550

Please sign in to comment.