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.
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
import paths from '../mconfig.json';
|
|
import notification from './notification.js';
|
|
import message from './utils/message.js';
|
|
import esbuild from 'esbuild';
|
|
|
|
/**
|
|
* Bundles and minifies main JavaScript files.
|
|
*/
|
|
export function compileScripts() {
|
|
[
|
|
'app.js',
|
|
].forEach((filename) => {
|
|
const includes = [ paths.scripts.src + filename ];
|
|
const outfile = paths.scripts.dest + filename;
|
|
|
|
const timeLabel = `${filename} compiled in`;
|
|
console.time(timeLabel);
|
|
|
|
esbuild.build({
|
|
entryPoints: includes,
|
|
bundle: true,
|
|
minify: true,
|
|
sourcemap: true,
|
|
color: true,
|
|
logLevel: 'error',
|
|
target: [
|
|
'es2015',
|
|
],
|
|
outfile
|
|
}).catch((err) => {
|
|
// errors managments (already done in esbuild)
|
|
notification({
|
|
title: `${filename} compilation failed 🚨`,
|
|
message: `${err.errors[0].text} in ${err.errors[0].location.file} line ${err.errors[0].location.line}`
|
|
});
|
|
}).then(() => {
|
|
message(`${filename} compiled`, 'success', timeLabel);
|
|
});
|
|
});
|
|
}
|