Skip to content

Instantly share code, notes, and snippets.

@ear
Created October 10, 2014 15:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ear/aa46c3cc92842035a91c to your computer and use it in GitHub Desktop.
Save ear/aa46c3cc92842035a91c to your computer and use it in GitHub Desktop.
// hotfix sass sourcemaps
var appSassFiles = pickFiles('app', {
srcDir: '/styles',
destDir: '/assets/styles'
});
var bootstrapSassFiles = pickFiles('bower_components/bootstrap-sass-official/assets/stylesheets', {
srcDir: 'bootstrap',
destDir: '/assets/styles/bower_components/bootstrap-sass-official/assets/stylesheets/bootstrap'
});
var fontAwesomeSassFiles = pickFiles('bower_components/fontawesome', {
srcDir: 'scss',
destDir: '/assets/styles/bower_components/fontawesome/scss'
});
var hotfixSassSourceMaps = require('./vendor/hotfix-sass-sourcemaps.js');
module.exports = mergeTrees([ hotfixSassSourceMaps(app.toTree()), faFonts, appSassFiles, bootstrapSassFiles, fontAwesomeSassFiles]);
var Filter = require('broccoli-filter');
/*
* fix sourceMappingURL=…
*/
function SourceMapPathFixerFilter(inputTree) {
if (!(this instanceof SourceMapPathFixerFilter)) {
return new SourceMapPathFixerFilter(inputTree);
}
this.inputTree = inputTree;
}
SourceMapPathFixerFilter.prototype = Object.create(Filter.prototype);
SourceMapPathFixerFilter.prototype.constructor = SourceMapPathFixerFilter;
SourceMapPathFixerFilter.prototype.extensions = ['css'];
SourceMapPathFixerFilter.prototype.targetExtension = 'css';
SourceMapPathFixerFilter.prototype.processString = function (str) {
return str.replace(/\/\*# sourceMappingURL=(.*)\/(.*\.css\.map) \*\//g, '/*# sourceMappingURL=/assets/$2 */');
};
/*
* fix .map source:[…paths…]
*/
function SourceMapSourcesPathFixerFilter(inputTree) {
if (!(this instanceof SourceMapSourcesPathFixerFilter)) {
return new SourceMapSourcesPathFixerFilter(inputTree);
}
this.inputTree = inputTree;
}
SourceMapSourcesPathFixerFilter.prototype = Object.create(Filter.prototype);
SourceMapSourcesPathFixerFilter.prototype.constructor = SourceMapSourcesPathFixerFilter;
SourceMapSourcesPathFixerFilter.prototype.extensions = ['map'];
SourceMapSourcesPathFixerFilter.prototype.targetExtension = 'map';
SourceMapSourcesPathFixerFilter.prototype.processString = function (str) {
var sourceMap = JSON.parse(str);
sourceMap.sources = sourceMap.sources.map(function (source) {
return "/assets/styles/" + source.replace(/^(\.\.\/)+/g, '');
});
return JSON.stringify(sourceMap, null, 2);
}
/*
* combined filter
*/
function HotfixSassSourceMapsFilter (tree) {
return SourceMapSourcesPathFixerFilter(SourceMapPathFixerFilter(tree));
}
module.exports = HotfixSassSourceMapsFilter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment