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