Skip to content

Instantly share code, notes, and snippets.

@GottZ
Created July 5, 2019 19:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save GottZ/4b1b94dec410aae37c688d2529a80e9a to your computer and use it in GitHub Desktop.
Save GottZ/4b1b94dec410aae37c688d2529a80e9a to your computer and use it in GitHub Desktop.
const sass = require('node-sass');
// related: https://github.com/UnwrittenFun/svelte-vscode/issues/1
module.exports = {
preprocess: {
style: async ({ content, attributes }) => {
if (!['text/sass', 'text/scss'].some(attributes.type) && !['sass', 'scss'].some(attributes.lang)) return;
return new Promise((resolve, reject) => {
sass.render(
{
data: content,
sourceMap: true,
outFile: 'x', // this is necessary, but is ignored
},
(err, result) => {
if (err) return reject(err);
resolve({
code: result.css.toString(),
map: result.map.toString(),
});
},
);
});
},
},
};
@joakim
Copy link

joakim commented Oct 6, 2019

Thanks!

@ShadowfeindX
Copy link

Array.protoype.some takes a callback, not a variable. Maybe replace with Array.prototype.includes.

@joakim
Copy link

joakim commented Oct 7, 2019

I actually rewrote that part to a simple string comparison, didn't see the need for fuzzy checking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment