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

View file

@ -3,6 +3,10 @@ sudo: false
language: node_js
node_js:
- "lts/*"
addons:
apt:
packages:
- sassc
script:
- make
- make po/starter-kit.pot

View file

@ -36,10 +36,8 @@
"htmlparser": "^1.7.7",
"jed": "^1.1.1",
"mini-css-extract-plugin": "^0.11.0",
"node-sass": "^4.14.1",
"po2json": "^1.0.0-alpha",
"qunit": "^2.9.3",
"sass-loader": "^10.0.2",
"sizzle": "^2.3.3",
"stdio": "^2.1.0",
"string-replace-loader": "^2.3.0",

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);
};

View file

@ -118,6 +118,9 @@ module.exports = {
resolve: {
modules: [ nodedir ],
},
resolveLoader: {
modules: [ nodedir, path.resolve(__dirname, 'src/lib') ],
},
watchOptions: {
ignored: /node_modules/,
},
@ -165,15 +168,7 @@ module.exports = {
]
},
},
{
loader: 'sass-loader',
options: {
sassOptions: {
outputStyle: 'compressed',
},
sourceMap: true,
},
},
'sassc-loader',
]
},
{
@ -188,15 +183,7 @@ module.exports = {
url: false
}
},
{
loader: 'sass-loader',
options: {
sassOptions: {
outputStyle: 'compressed',
},
sourceMap: true,
},
},
'sassc-loader',
]
},
]