Init
This commit is contained in:
126
Prefab.Web/wwwroot/template/sources/gulpfile.js
Normal file
126
Prefab.Web/wwwroot/template/sources/gulpfile.js
Normal file
@@ -0,0 +1,126 @@
|
||||
const gulp = require('gulp');
|
||||
const del = require('del');
|
||||
const yargs = require('yargs');
|
||||
const browserSync = require('browser-sync').create();
|
||||
const gulpTasks = require('./gulp/tasks');
|
||||
|
||||
|
||||
const PRODUCTION = yargs.argv.production;
|
||||
|
||||
|
||||
/**
|
||||
* Runs a local http server and watch for files changes
|
||||
*/
|
||||
function serve() {
|
||||
browserSync.init({
|
||||
port: 3001,
|
||||
server: {
|
||||
baseDir: './dist'
|
||||
}
|
||||
});
|
||||
|
||||
gulp.watch(['src/twig/**/*', 'src/data/**/*'], {ignoreInitial: false}, twig).on('change', browserSync.reload);
|
||||
gulp.watch(['src/scss/**/*'], {ignoreInitial: false}, scss);
|
||||
gulp.watch(['src/vendor/**/*'], {ignoreInitial: true}, vendor).on('change', browserSync.reload);
|
||||
gulp.watch(['src/images/**/*'], {ignoreInitial: false}, images).on('change', browserSync.reload);
|
||||
gulp.watch(['src/svg/**/*.svg'], {ignoreInitial: false}, svg).on('change', browserSync.reload);
|
||||
gulp.watch(['src/js/**/*'], {ignoreInitial: false}, js).on('change', browserSync.reload);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes dist directory
|
||||
*/
|
||||
function clean() {
|
||||
return del(['dist']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compiles twig files to html
|
||||
*/
|
||||
function twig() {
|
||||
return gulpTasks.twig().pipe(gulp.dest('dist'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compiles scss files to css
|
||||
*/
|
||||
function scss() {
|
||||
return gulpTasks.scss({production: PRODUCTION}).pipe(gulp.dest('dist')).pipe(browserSync.stream());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copies vendor directory to dist directory
|
||||
*/
|
||||
function vendor() {
|
||||
return gulpTasks.vendor().pipe(gulp.dest('dist'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copies images to dist directory
|
||||
*/
|
||||
function images() {
|
||||
return gulpTasks.images().pipe(gulp.dest('dist'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compiles svg sprite
|
||||
*/
|
||||
function svg() {
|
||||
return gulpTasks.svg().pipe(gulp.dest('dist'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compiles js
|
||||
*/
|
||||
function js() {
|
||||
return gulpTasks.js().pipe(gulp.dest('dist'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Watch task
|
||||
*/
|
||||
function watch () {
|
||||
gulp.watch(['src/twig/**/*', 'src/data/**/*'], {ignoreInitial: false}, twig);
|
||||
gulp.watch(['src/scss/**/*'], {ignoreInitial: false}, scss);
|
||||
gulp.watch(['src/vendor/**/*'], {ignoreInitial: false}, vendor);
|
||||
gulp.watch(['src/images/**/*'], {ignoreInitial: false}, images);
|
||||
gulp.watch(['src/svg/**/*.svg'], {ignoreInitial: false}, svg);
|
||||
gulp.watch(['src/js/**/*'], {ignoreInitial: false}, js);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build task
|
||||
*/
|
||||
function build(cb) {
|
||||
gulp.series(clean, gulp.parallel(twig, scss, vendor, images, svg, js))(cb);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Default task
|
||||
*/
|
||||
gulp.task('default', function(cb) {
|
||||
build(cb);
|
||||
});
|
||||
|
||||
|
||||
exports.serve = gulp.series(vendor, serve);
|
||||
exports.clean = clean;
|
||||
exports.twig = twig;
|
||||
exports.scss = scss;
|
||||
exports.vendor = vendor;
|
||||
exports.images = images;
|
||||
exports.svg = svg;
|
||||
exports.js = js;
|
||||
|
||||
exports.watch = gulp.series(clean, watch);
|
||||
exports.build = build;
|
||||
Reference in New Issue
Block a user