From 233b5cfe04142fb33d0f0c54b05206a85108ba7c Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Sat, 17 Oct 2020 11:33:52 +0200 Subject: [PATCH] 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 --- .travis.yml | 4 ++++ package.json | 2 -- src/lib/sassc-loader.js | 25 +++++++++++++++++++++++++ webpack.config.js | 23 +++++------------------ 4 files changed, 34 insertions(+), 20 deletions(-) create mode 100644 src/lib/sassc-loader.js diff --git a/.travis.yml b/.travis.yml index ef8d75c..bee776c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,10 @@ sudo: false language: node_js node_js: - "lts/*" +addons: + apt: + packages: + - sassc script: - make - make po/starter-kit.pot diff --git a/package.json b/package.json index e6fafc9..b197446 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/lib/sassc-loader.js b/src/lib/sassc-loader.js new file mode 100644 index 0000000..19ff806 --- /dev/null +++ b/src/lib/sassc-loader.js @@ -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); +}; diff --git a/webpack.config.js b/webpack.config.js index a0d9904..386ea37 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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', ] }, ]