Add autoprefixer and postcss

Added:
- autoprefixer v10.3.4
- postcss v8.3.6

Changed:
- Node Sass options to pass source map to PostCSS.
This commit is contained in:
Chauncey McAskill
2021-09-14 19:21:24 -04:00
parent e9e0e5784e
commit b24014d8b1
9 changed files with 327 additions and 41 deletions

View File

@@ -1,5 +1,7 @@
import autoprefixer from 'autoprefixer';
import fs from 'fs';
import sass from 'node-sass';
import postcss from 'postcss';
import paths from '../mconfig.json';
import message from './utils/message.js';
import notification from './notification.js';
@@ -20,9 +22,11 @@ export function compileStyles() {
sass.render({
file: infile,
omitSourceMapUrl: true,
outFile: outfile,
outputStyle: 'compressed',
sourceMap: true
sourceMap: true,
sourceMapContents: true
}, (err, result) => {
if (err) {
message(`Error compiling ${name}.scss`, 'error');
@@ -35,19 +39,62 @@ export function compileStyles() {
return;
}
fs.writeFile(outfile, result.css, (err) => {
fs.access(outfile, (err) => {
if (err) {
message(`Error compiling ${name}.scss`, 'error');
message(err.formatted);
message(err);
notification({
title: `${name}.scss compilation failed 🚨`,
message: `Could not save stylesheet to ${name}.css`
message: err
});
return;
}
message(`${name}.css compiled`, 'success', timeLabel);
postcss([ autoprefixer ]).process(result.css, {
from: outfile,
to: outfile,
map: {
annotation: false,
inline: false,
sourcesContent: true
}
}).then((result) => {
result.warnings().forEach((warn) => {
message(`Error prefixing ${name}.css`, 'error');
message(warn.toString());
});
fs.writeFile(outfile, result.css, (err) => {
if (err) {
message(`Error compiling ${name}.scss`, 'error');
message(err);
notification({
title: `${name}.scss compilation failed 🚨`,
message: `Could not save stylesheet to ${name}.css`
});
return;
}
message(`${name}.css compiled`, 'success', timeLabel);
});
if (result.map) {
fs.writeFile(outfile + '.map', result.map.toString(), (err) => {
if (err) {
message(`Error compiling ${name}.scss`, 'error');
message(err);
notification({
title: `${name}.scss compilation failed 🚨`,
message: `Could not save sourcemap to ${name}.css.map`
});
return;
}
});
}
});
});
});
});