Files
OfficialSite/build/watch.js

83 lines
1.7 KiB
JavaScript
Raw Normal View History

import loconfig from '../loconfig.json';
2021-09-21 16:01:47 -04:00
import concatFiles from './tasks/concats.js';
import compileScripts from './tasks/scripts.js';
import compileStyles from './tasks/styles.js' ;
import compileSVGs from './tasks/svgs.js';
import template from './utils/template.js';
import server from 'browser-sync';
import { join } from 'node:path';
const { paths, tasks } = loconfig;
const serverConfig = {
open: false,
notify: false
2021-06-28 21:33:10 -04:00
};
if (typeof paths.url === 'string' && paths.url.length > 0) {
2021-06-28 21:33:10 -04:00
// Use proxy
serverConfig.proxy = paths.url;
2021-06-28 21:33:10 -04:00
} else {
// Use base directory
serverConfig.server = {
baseDir: paths.dest
};
2021-06-28 21:33:10 -04:00
}
// Start the Browsersync server
server.init(serverConfig);
// Build scripts, compile styles, concat files,
// and generate spritesheets on first hit
concatFiles();
compileScripts();
2020-11-27 16:15:36 -05:00
compileStyles();
compileSVGs();
2020-11-27 16:15:36 -05:00
// and call any methods on it.
server.watch(
[
paths.views.src,
join(paths.scripts.dest, '*.js'),
join(paths.styles.dest, '*.css'),
join(paths.svgs.dest, '*.svg'),
]
).on('change', server.reload);
2021-06-28 21:33:10 -04:00
// Watch scripts
server.watch(
[
join(paths.scripts.src, '**/*.js'),
]
).on('change', () => {
compileScripts();
});
// Watch concats
server.watch(
tasks.concats.reduce(
(patterns, { includes }) => patterns.concat(includes),
[]
).map((path) => template(path))
).on('change', () => {
concatFiles();
});
// Watch styles
server.watch(
[
join(paths.styles.src, '**/*.scss'),
]
).on('change', () => {
compileStyles();
});
// Watch svgs
server.watch(
[
join(paths.svgs.src, '*.svg'),
]
).on('change', () => {
compileSVGs();
});