Files
OfficialSite/build/watch.js
Chauncey McAskill e9e0e5784e Refactor build tasks
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.
2021-09-18 01:16:44 -04:00

77 lines
1.5 KiB
JavaScript

import paths from '../mconfig.json';
import { concatVendors } from './concat.js';
import { compileScripts } from './scripts.js';
import { compileStyles } from './styles.js' ;
import { compileSVGs } from './svgs.js';
import server from 'browser-sync';
const serverConfig = {
open: false,
notify: false
};
if (typeof paths.url === 'string' && paths.url.length > 0) {
// Use proxy
serverConfig.proxy = paths.url;
} else {
// Use base directory
serverConfig.server = {
baseDir: paths.dest
};
}
// Start the Browsersync server
server.init(serverConfig);
// Build scripts, compile styles, concat vendors and generate the svgs sprite on first hit
concatVendors();
compileScripts();
compileStyles();
compileSVGs();
// and call any methods on it.
server.watch(
[
paths.views.src,
paths.scripts.dest + '*.js',
paths.styles.dest + '*.css',
paths.svgs.dest + '*.svg',
]
).on('change', server.reload);
// Watch scripts
server.watch(
[
paths.scripts.src + '**/*.js',
]
).on('change', () => {
compileScripts();
});
// Watch scripts vendors
server.watch(
[
paths.scripts.vendors.src + '*.js',
]
).on('change', () => {
concatVendors();
});
// Watch styles
server.watch(
[
paths.styles.src + '**/*.scss',
]
).on('change', () => {
compileStyles();
});
// Watch svgs
server.watch(
[
paths.svgs.src + '*.svg',
]
).on('change', () => {
compileSVGs();
});