-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.mjs
58 lines (50 loc) · 1.92 KB
/
gulpfile.mjs
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
import gulp from 'gulp';
import gulpSass from 'gulp-sass';
import cleanCSS from 'gulp-clean-css';
import autoprefixer from 'gulp-autoprefixer';
import * as dartSass from 'sass';
import uglify from 'gulp-uglify';
import rename from 'gulp-rename';
import merge from 'merge-stream';
import sourcemaps from 'gulp-sourcemaps';
import gulpIf from 'gulp-if';
const sass = gulpSass(dartSass);
const config = {
sourceMaps: process.env.NODE_ENV === 'development'
}
// Task to compile Sass and minify CSS
gulp.task('build-css', function() {
return gulp.src('dev/scss/**/*.scss')
.pipe(gulpIf(config.sourceMaps, sourcemaps.init()))
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
overrideBrowserslist: ["last 2 versions"],
cascade: false,
}))
.pipe(cleanCSS())
.pipe(rename({ suffix: '.min' }))
.pipe(gulpIf(config.sourceMaps, sourcemaps.write()))
.pipe(gulp.dest('assets/css'));
});
// Task to compile and minify JavaScript
gulp.task('build-js', function() {
// Process main.js in this file you can import others files js
const mainJsStream = gulp.src('dev/js/main.js')
.pipe(uglify())
.pipe(rename({ suffix: '.min' })) // Rename file to main.min.js
.pipe(gulp.dest('assets/js'));
// Libraries: Process spectrum.js
const spectrumJsStream = gulp.src('dev/js/lib/spectrum.js')
.pipe(uglify())
.pipe(rename({ suffix: '.min' })) // Rename file to spectrum.min.js
.pipe(gulp.dest('assets/js'));
// Return a merged stream to signal completion
return merge(mainJsStream, spectrumJsStream);
});
// Task to watch for changes in Sass files
gulp.task('watch', function() {
gulp.watch('dev/scss/**/*.scss', gulp.series('build-css'));
gulp.watch('dev/js/**/*.js', gulp.series('build-js'));
});
// Default task
gulp.task('default', gulp.series('build-css', 'build-js', 'watch'));