Skip to content

Commit 41d1ee0

Browse files
committed
Use a custom importer to modify _normalize.scss instead of sed.
1 parent 99de004 commit 41d1ee0

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

votrfront/buildstatic.sh

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,6 @@ if [ "$1" == "build" ] || [ "$1" == "" ]; then
1818

1919
yarn --cwd=.. install
2020

21-
bs=../node_modules/bootstrap-sass/assets
22-
23-
sed -i "
24-
# Don't use pointer cursor on buttons.
25-
# http://lists.w3.org/Archives/Public/public-css-testsuite/2010Jul/0024.html
26-
s@cursor: pointer; // 3@@
27-
# Don't inherit color and font on inputs and selects.
28-
s@color: inherit; // 1@@
29-
s@font: inherit; // 2@@
30-
" $bs/stylesheets/bootstrap/_normalize.scss
31-
3221
rm -f static/votr.min.js.*.map
3322
yarn webpack --mode=production --progress --display=minimal
3423

webpack.config.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
1+
const fs = require('fs');
12
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
23

4+
const bootstrapPath = __dirname + '/node_modules/bootstrap-sass/assets/stylesheets';
5+
6+
// A custom node-sass importer that removes some unwanted rules from _normalize.scss.
7+
function importerWhichRewritesBootstrapNormalizeScss(url, prev, done) {
8+
if (url != 'bootstrap/normalize') {
9+
done(null);
10+
return;
11+
}
12+
13+
fs.readFile(bootstrapPath + '/bootstrap/_normalize.scss', 'utf8', (err, data) => {
14+
if (err) return done(err);
15+
16+
function remove(what) {
17+
if (!data.includes(what)) throw Error(`"${what}" not found`);
18+
data = data.replace(what, '');
19+
}
20+
21+
// Don't use pointer cursor on buttons.
22+
// http://lists.w3.org/Archives/Public/public-css-testsuite/2010Jul/0024.html
23+
remove('cursor: pointer; // 3');
24+
25+
// Don't inherit color and font on inputs and selects.
26+
remove('color: inherit; // 1');
27+
remove('font: inherit; // 2');
28+
29+
done({ contents: data });
30+
});
31+
}
32+
333
const outputPath = __dirname + '/votrfront/static';
434

535
module.exports = function (env, args) {
@@ -43,8 +73,9 @@ module.exports = function (env, args) {
4373
{
4474
loader: 'sass-loader',
4575
options: {
46-
includePaths: [__dirname + '/node_modules/bootstrap-sass/assets/stylesheets'],
76+
includePaths: [bootstrapPath],
4777
outputStyle: mode == 'development' ? undefined : 'compressed',
78+
importer: importerWhichRewritesBootstrapNormalizeScss,
4879
},
4980
},
5081
],

0 commit comments

Comments
 (0)