2021-09-12 17:35:08 +02:00
|
|
|
const sass = require('sass');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
|
|
|
// The SASS doc claims that renderSync is twice as fast as render, so if speed
|
|
|
|
// turns out to be an issue we could use that instead. The advantage of async is
|
|
|
|
// that we can run complation of each file in parallel (and running other async
|
|
|
|
// gulp tasks in parallel too).
|
|
|
|
|
|
|
|
// sasss.render is old school async, so convert it to a promise here.
|
|
|
|
async function sassRender(options) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
sass.render(options, ((error, result) => {
|
|
|
|
if (error) {
|
|
|
|
reject(error);
|
|
|
|
} else {
|
|
|
|
resolve(result);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-10-03 17:00:49 +02:00
|
|
|
// module.exports = async function compileSass(inputPaths, outputPath) {
|
|
|
|
// const promises = [];
|
|
|
|
// for (const inputPath of inputPaths) {
|
|
|
|
// console.info(`Compiling ${inputPath}...`);
|
|
|
|
|
|
|
|
// promises.push(sassRender({
|
|
|
|
// file: inputPath,
|
|
|
|
// sourceMap: true,
|
|
|
|
// outFile: outputPath,
|
|
|
|
// }));
|
|
|
|
// }
|
|
|
|
|
|
|
|
// const results = await Promise.all(promises);
|
|
|
|
|
|
|
|
// const cssString = results.map(r => r.css.toString()).join('\n');
|
|
|
|
// const mapString = results.map(r => r.map.toString()).join('\n');
|
2021-09-12 17:35:08 +02:00
|
|
|
|
2021-10-03 17:00:49 +02:00
|
|
|
// await Promise.all([
|
|
|
|
// fs.writeFile(outputPath, cssString, 'utf8'),
|
|
|
|
// fs.writeFile(`${outputPath}.map`, mapString, 'utf8'),
|
|
|
|
// ]);
|
|
|
|
|
|
|
|
// console.info(`Generated ${outputPath}`);
|
|
|
|
// };
|
|
|
|
|
|
|
|
module.exports = async function compileSass(inputPath, outputPath) {
|
|
|
|
const result = await sassRender({
|
|
|
|
file: inputPath,
|
|
|
|
sourceMap: true,
|
|
|
|
outFile: outputPath,
|
|
|
|
outputStyle: 'compressed',
|
|
|
|
indentType: 'tab',
|
|
|
|
});
|
2021-09-12 17:35:08 +02:00
|
|
|
|
2021-10-03 17:00:49 +02:00
|
|
|
const cssString = result.css.toString();
|
|
|
|
const mapString = result.map.toString();
|
2021-09-12 17:35:08 +02:00
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
fs.writeFile(outputPath, cssString, 'utf8'),
|
|
|
|
fs.writeFile(`${outputPath}.map`, mapString, 'utf8'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
console.info(`Generated ${outputPath}`);
|
|
|
|
};
|