Use sassc instead of node-sass

node-sass is a compiled ELF module, which is problematic for
distributions that want to rebuild everything from source. The sassc CLI
program is packaged everywhere, and both use the same libsass library.

So drop node-sass and sass-loader, and replace it with a simple loader
wrapper around sassc.

This also saves 122 npm packages (16 MB in node_modules/).

Closes #382
This commit is contained in:
Martin Pitt 2020-10-17 11:33:52 +02:00 committed by Martin Pitt
parent ea1377da1c
commit 233b5cfe04
4 changed files with 34 additions and 20 deletions

25
src/lib/sassc-loader.js Normal file
View file

@ -0,0 +1,25 @@
const fs = require('fs');
const path = require('path');
const childProcess = require('child_process');
/* source is not used. This must be the first loader in the chain, using this.resource, so that sassc can include the scss file's directory in the include path */
module.exports = function() {
this.cacheable();
const workdir = fs.mkdtempSync("sassc-loader.");
const out = path.join(workdir, "output.css");
childProcess.execFileSync(
'sassc',
['--load-path=node_modules', '--style=compressed', '--sourcemap', this.resource, out],
{ stdio: ['pipe', 'stdio', 'stdio'] });
const css = fs.readFileSync(out, 'utf8');
const cssmap = fs.readFileSync(out + ".map", 'utf8');
fs.unlinkSync(out);
fs.unlinkSync(out + ".map");
fs.rmdirSync(workdir);
this.callback(null, css, cssmap);
};