expressCart/gulpfile.js

102 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-02-01 10:51:37 +10:00
const { src, dest, series, watch } = require('gulp');
2018-01-07 04:55:48 +10:00
const gulp = require('gulp');
2020-02-01 10:51:37 +10:00
const nodemon = require('gulp-nodemon');
2019-12-26 20:32:28 +10:00
const less = require('gulp-less');
2020-02-01 10:51:37 +10:00
const colors = require('colors');
2018-01-07 04:55:48 +10:00
const cleanCSS = require('gulp-clean-css');
const minify = require('gulp-minify');
const rename = require('gulp-rename');
2020-02-01 10:51:37 +10:00
const nodemonOptions = {
script: 'app.js',
ext: 'js json',
env: { NODE_ENV: 'development' },
verbose: false,
ignore: [],
watch: ['lib/*', 'config/*', 'routes/*', 'app.js']
};
2019-12-26 20:32:28 +10:00
function lessCss(){
return gulp.src('public/stylesheets/less/**/*.less')
2019-12-26 20:32:28 +10:00
.pipe(less({
paths: [
'public/stylesheets/less'
]
}))
.pipe(rename({
dirname: 'public/stylesheets',
extname: '.css'
}))
.pipe(gulp.dest('./'));
};
2019-10-26 11:05:04 +10:00
function compressJS(){
return src([
'public/javascripts/*.js',
'!public/javascripts/*.min.js'
])
.pipe(minify({
ext: {
src: '.js',
min: '.min.js'
}
}))
.pipe(dest('public/javascripts'));
2019-10-26 11:05:04 +10:00
};
2018-01-07 04:55:48 +10:00
2019-10-26 11:05:04 +10:00
function compressCss(){
return src([
'public/stylesheets/*.css',
'!public/stylesheets/*.min.css'
])
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(rename({
dirname: 'public/stylesheets',
extname: '.min.css'
}))
.pipe(dest('./'));
2019-10-26 11:05:04 +10:00
};
2018-01-07 04:55:48 +10:00
2019-10-26 11:05:04 +10:00
function compressThemeCss(){
return src([
'views/themes/**/*.css',
'!views/themes/**/*.min.css'
])
.pipe(cleanCSS({ compatibility: 'ie8' }))
.pipe(rename({
extname: '.min.css'
}))
.pipe(dest('views/themes/'));
};
function compressThemeJS(){
return src([
'views/themes/**/*.js',
'!views/themes/**/*.min.js'
])
.pipe(minify({
ext: {
src: '.js',
min: '.min.js'
}
}))
.pipe(dest('views/themes/'));
2019-10-26 11:05:04 +10:00
};
2018-02-14 07:15:14 +10:00
2018-01-07 04:55:48 +10:00
// run the tasks
2019-12-26 20:32:28 +10:00
gulp.task('default', series(lessCss, compressJS, compressCss, compressThemeCss, compressThemeJS));
2020-02-01 10:51:37 +10:00
gulp.task('watch', (done) => {
// Watch LESS files and generate CSS
watch(['public/stylesheets/less/**/*.less'], async () => {
lessCss();
console.log(colors.blue('CSS generation complete'));
});
// run, watch and restart app
nodemon(nodemonOptions)
.once('quit', () => {
done();
});
});