@swift-ws/gulp-kit
Version:
A starter kit for automating frontend development using Gulp.js.
40 lines (33 loc) • 1.29 kB
JavaScript
import {gulp, webpack, vinylNamed} from '../plugins.js';
import path from "path";
import {Readable} from 'stream';
export const compileScripts = async () => {
const {config} = await import('../config.js');
const {webpackConfig} = await import('../webpack.config.js');
const files = gulp.src(config.task.script.src);
const promises = [];
files.on('data', file => {
promises.push(new Promise((resolve, reject) => {
const tempStream = new Readable({ objectMode: true });
tempStream.push(file);
tempStream.push(null);
tempStream
.pipe(vinylNamed())
.pipe(webpack(webpackConfig))
.pipe(gulp.dest(path.dirname(file.path).replace(path.resolve(config.task.script.dirSrc), path.resolve(config.task.script.dirDest))))
.on('end', resolve)
.on('error', reject);
}));
});
return new Promise((resolve, reject) => {
files.on('end', () => {
Promise.all(promises)
.then(() => resolve())
.catch(reject);
});
});
};
export const watchScripts = async () => {
const {config} = await import('../config.js');
gulp.watch(config.task.script.watch, compileScripts);
};