diff --git a/lib/tasks/build-sass.js b/lib/tasks/build-sass.js index 2f257913..b3a8b6a8 100644 --- a/lib/tasks/build-sass.js +++ b/lib/tasks/build-sass.js @@ -16,8 +16,8 @@ module.exports = function buildSass(config) { const cwd = config.cwd || process.cwd(); const src = config.sass ? Promise.resolve(config.sass) : files.getMainSassPath(cwd); - return src.then(code => { - if (code) { + return src.then(sassFile => { + if (sassFile) { const destFolder = config.buildFolder || files.getBuildFolderPath(cwd); const dest = config.buildCss || 'main.css'; @@ -40,32 +40,34 @@ module.exports = function buildSass(config) { grid: true }; - return readFile(code, 'utf-8') - .then(sassFile => { + let sassConfig; + + if (!config.sassPrefix) { + sassConfig = { file: sassFile }; + } else { + sassConfig = readFile(sassFile, 'utf-8').then(code => { // Sass prefixing is used in our origami component specification sass tests - if (config.sassPrefix) { - sassFile = config.sassPrefix + sassFile; - } + return { data: config.sassPrefix + code }; + }); + } + return Promise.resolve(sassConfig) + .then(sassConfig => { const includePaths = (config.sassIncludePaths || []).concat('bower_components').map(p => path.join(cwd, p)); // Ensure that the specified current working directory is included as the first path for node-sass to look into includePaths.unshift(cwd); - const sassConfig = { - data: sassFile, - includePaths, - outputStyle: 'nested', - - // This is an experimental LibSass feature. Use with caution. - // https://github.com/sass/node-sass#functions--v300---experimental - // We use this to silence the sass console output when running `obt test`. - // We also use this to hide warnings when building sass without the verbose flag. - functions: config.sassFunctions ? config.sassFunctions : {}, - }; + sassConfig.includePaths = includePaths; + sassConfig.outputStyle = 'nested'; + // This is an experimental LibSass feature. Use with caution. + // https://github.com/sass/node-sass#functions--v300---experimental + // We use this to silence the sass console output when running `obt test`. + // We also use this to hide warnings when building sass without the verbose flag. + sassConfig.functions = config.sassFunctions ? config.sassFunctions : {}; if (useSourceMaps) { - sassConfig.sourceMap = code; + sassConfig.sourceMap = sassFile; sassConfig.outFile = dest; // Embeds the source map as a data URI @@ -99,7 +101,7 @@ module.exports = function buildSass(config) { .then(({ css }) => { if (useSourceMaps) { return postcss(postCssTransforms).process(css, { - from: code, + from: sassFile, to: dest, map: { inline: true diff --git a/test/integration/build/build.test.js b/test/integration/build/build.test.js index b31d0a91..380c7dd2 100644 --- a/test/integration/build/build.test.js +++ b/test/integration/build/build.test.js @@ -525,7 +525,7 @@ describe('obt build', function () { .test__visual { -ms-grid-row: 1; grid-row: 1; } -/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0ZGluIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNDO0VBQ0MsZ0JBQWU7RUFDZixrQkFBYTtFQUFiLGNBQWE7RUFDYiwwQkFBOEI7RUFBOUIsK0JBQThCO0VBQzlCLG1CQUF1QjtFQUF2Qix3QkFBdUIsRUFLdkI7RUFKQTtJQUNDLHNCQUFxQjtJQUNyQixhQUFZLEVBQ1o7O0FBRUY7RUFDQyx3QkFBdUI7RUFBdkIsbUJBQXVCO0VBQXZCLHdCQUF1QjtFQUN2QixnQkFBVztFQUFYLFlBQVc7RUFDWCwrQkFBc0I7RUFBdEIsdUJBQXNCO0VBQ3RCLDJCQUFrQjtFQUFsQiw0QkFBa0I7RUFBbEIsMkJBQWtCO0VBQWxCLG1CQUFrQixFQUNsQjs7QUFDRDtFQUNDLGdCQUFXO0VBQVgsWUFBVyxFQUNYIiwiZmlsZSI6Im1haW4uY3NzIn0= */`); +/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm1haW4uc2NzcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQztFQUNDLGdCQUFlO0VBQ2Ysa0JBQWE7RUFBYixjQUFhO0VBQ2IsMEJBQThCO0VBQTlCLCtCQUE4QjtFQUM5QixtQkFBdUI7RUFBdkIsd0JBQXVCLEVBS3ZCO0VBSkE7SUFDQyxzQkFBcUI7SUFDckIsYUFBWSxFQUNaOztBQUVGO0VBQ0Msd0JBQXVCO0VBQXZCLG1CQUF1QjtFQUF2Qix3QkFBdUI7RUFDdkIsZ0JBQVc7RUFBWCxZQUFXO0VBQ1gsK0JBQXNCO0VBQXRCLHVCQUFzQjtFQUN0QiwyQkFBa0I7RUFBbEIsNEJBQWtCO0VBQWxCLDJCQUFrQjtFQUFsQixtQkFBa0IsRUFDbEI7O0FBQ0Q7RUFDQyxnQkFBVztFQUFYLFlBQVcsRUFDWCIsImZpbGUiOiJtYWluLmNzcyJ9 */`); }); }); });