-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
78 lines (71 loc) · 2.4 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// initialize modules
// Importing specific gulp API functions lets us write them below as series() instead of gulp.series()
const { src, dest, watch, series, parallel } = require('gulp');
// Importing all the Gulp-related packages we want to use
const sourcemaps = require('gulp-sourcemaps');
const sass = require('gulp-sass')(require('sass'));
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const replace = require('gulp-replace');
const imagemin = require("gulp-imagemin");
const cache = require("gulp-cache");
// file path variables
const allCompiledJsFilename = '_9550808079.js';
const files = {
scssPath: 'assets/app/scss/**/*.scss',
jsPath: 'assets/app/js/**/*.js',
distPath: 'dist',
imagePath: 'assets/app/images/**/*.+(png|jpg|gif|svg|jpeg)',
}
// Task to minify images
function imagesTask() {
return src(files.imagePath)
.pipe(cache(imagemin()))
.pipe(dest('dist/images'));
}
function scssTask(){
return src(files.scssPath)
.pipe(sourcemaps.init()) // initialize sourcemaps first
.pipe(sass()) // compile SCSS to CSS
.pipe(postcss([ autoprefixer(), cssnano ])) // PostCSS plugins
.pipe(sourcemaps.write('.')) // write sourcemaps file in current directory
.pipe(dest(files.distPath)
); // put final CSS in dist folder
}
// JS task: concatenates and uglifies JS files to script.js
function jsTask(){
return src([
files.jsPath
//,'!' + 'includes/js/jquery.min.js', // to exclude any specific files
])
.pipe(concat(allCompiledJsFilename))
.pipe(uglify())
.pipe(dest(files.distPath)
);
}
// cache busting task
function cacheBustTask(){
const cbString = new Date().getTime().toString().trim();
return src(['.env.example', '.env'])
.pipe(replace( /JAVASCRIPT_VERSION_CONTROL=\d+/g, 'JAVASCRIPT_VERSION_CONTROL=' + cbString))
.pipe(dest('.'));
}
// Watch task
function watchTask(){
watch([files.scssPath, files.jsPath],
{interval: 1000, usePolling: true}, //Makes docker work
series(
parallel(scssTask, jsTask, imagesTask),
cacheBustTask
)
);
}
// Default task
exports.default = series(
parallel(scssTask, jsTask, imagesTask),
cacheBustTask,
watchTask
);