Decouple static "main" keys in mconfig.json and refactor tasks to support many output files. Added: - scripts.js: Array of output files (such as 'app.js') to iterate over to bundle JS files. - styles.js: Array of input files (such as 'main.css' and 'critical.css') to iterate over to compile Sass files. - svgs.js: Array of output files (such as 'sprite.svg') to iterate over to compile SVG spritesheets. Changed: - mconfig.json: Decouple entry points to individual tasks to allow for more flexibility in projects. - concat.js: Refactor function to use promises to build list of JS files to concatenate. - message.js: Replace if statements with switch for improved readability. - message.js: If timerID provided with "waiting" type, log time. - watch.js: Change CSS and JS reload watch paths to include all files. - Sorted imports by path.
55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
import fs from 'fs';
|
|
import sass from 'node-sass';
|
|
import paths from '../mconfig.json';
|
|
import message from './utils/message.js';
|
|
import notification from './notification.js';
|
|
|
|
/**
|
|
* Compiles and minifies main Sass files to CSS.
|
|
*/
|
|
export function compileStyles() {
|
|
[
|
|
'critical',
|
|
'main',
|
|
].forEach((name) => {
|
|
const infile = paths.styles.src + name + '.scss';
|
|
const outfile = paths.styles.dest + name + '.css';
|
|
|
|
const timeLabel = `${name}.css compiled in`;
|
|
console.time(timeLabel);
|
|
|
|
sass.render({
|
|
file: infile,
|
|
outFile: outfile,
|
|
outputStyle: 'compressed',
|
|
sourceMap: true
|
|
}, (err, result) => {
|
|
if (err) {
|
|
message(`Error compiling ${name}.scss`, 'error');
|
|
message(err.formatted);
|
|
|
|
notification({
|
|
title: `${name}.scss compilation failed 🚨`,
|
|
message: err.formatted
|
|
});
|
|
return;
|
|
}
|
|
|
|
fs.writeFile(outfile, result.css, (err) => {
|
|
if (err) {
|
|
message(`Error compiling ${name}.scss`, 'error');
|
|
message(err.formatted);
|
|
|
|
notification({
|
|
title: `${name}.scss compilation failed 🚨`,
|
|
message: `Could not save stylesheet to ${name}.css`
|
|
});
|
|
return;
|
|
}
|
|
|
|
message(`${name}.css compiled`, 'success', timeLabel);
|
|
});
|
|
});
|
|
});
|
|
}
|