-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.mjs
More file actions
61 lines (55 loc) · 1.5 KB
/
Copy pathgulpfile.mjs
File metadata and controls
61 lines (55 loc) · 1.5 KB
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
import { src, dest, watch, series, parallel } from 'gulp';
import sassCompiler from 'gulp-sass';
import * as sassPkg from 'sass';
import terser from 'gulp-terser';
import rename from 'gulp-rename';
import sourcemaps from 'gulp-sourcemaps';
import autoprefixer from 'gulp-autoprefixer';
const sass = sassCompiler(sassPkg);
const paths = {
css: {
src: 'assets/scss/**/*.scss',
dest: 'assets/dist/css/'
},
js: {
src: ['assets/js/**/*.js'],
dest: 'assets/dist/js/'
},
maps: './' // Save maps alongside the minified files
};
/**
* Compiles SCSS files to CSS.
*
* @returns {Stream} A Gulp stream that completes the SCSS compilation process.
*/
function compileSCSS() {
return src(paths.css.src)
.pipe(sourcemaps.init())
.pipe(sass({ style: 'compressed' }).on('error', sass.logError))
.pipe(autoprefixer())
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write(paths.maps))
.pipe(dest(paths.css.dest));
}
/**
* Compresses JavaScript files.
*
* @returns {Stream} A stream containing the processed JavaScript files.
*/
function compressJS() {
return src(paths.js.src)
.pipe(sourcemaps.init())
.pipe(terser())
.pipe(rename({ suffix: '.min' }))
.pipe(sourcemaps.write(paths.maps))
.pipe(dest(paths.js.dest));
}
/**
* Watches for changes in CSS and JS source files.
*/
function watchFiles() {
watch(paths.css.src, compileSCSS);
watch(paths.js.src, compressJS);
}
export const build = parallel(compileSCSS, compressJS);
export default series(parallel(compileSCSS, compressJS), watchFiles);