-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
84 lines (74 loc) · 1.9 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
79
80
81
82
83
84
const autoprefixer = require('gulp-autoprefixer');
const browserSync = require('browser-sync');
const cssnano = require('gulp-cssnano');
const eslint = require('gulp-eslint');
const gulp = require('gulp');
const prettyError = require('gulp-prettyerror');
const rename = require('gulp-rename');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const terser = require('gulp-terser');
const babel = require('gulp-babel');
// Create basic Gulp tasks
gulp.task('sass', function() {
return gulp
.src('./sass/style.scss', { sourcemaps: true })
.pipe(sourcemaps.init())
.pipe(prettyError())
.pipe(sass())
.pipe(
autoprefixer({
browsers: ['last 2 versions']
})
)
.pipe(gulp.dest('./'))
.pipe(cssnano())
.pipe(rename('style.min.css'))
.pipe(sourcemaps.write('../maps'))
.pipe(gulp.dest('./build/css'));
});
gulp.task('lint', function() {
return gulp
.src(['./js/*.js'])
.pipe(prettyError())
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task(
'scripts',
gulp.series('lint', function compileScripts() {
return gulp
.src('./js/*.js')
.pipe(
babel({
presets: ['env']
})
)
.pipe(terser())
.pipe(
rename({
extname: '.min.js'
})
)
.pipe(gulp.dest('./build/js'));
})
);
// Set-up BrowserSync and watch
gulp.task('browser-sync', function() {
const files = [
'./build/css/*.css',
'./build/js/*.js',
'./*.php',
'./**/*.php'
];
browserSync.init(files, {
proxy: 'localhost[:port-here]/[your-dir-name-here]'
});
gulp.watch(files).on('change', browserSync.reload);
});
gulp.task('watch', function() {
gulp.watch('js/*.js', gulp.series('scripts'));
gulp.watch('sass/*.scss', gulp.series('sass'));
});
gulp.task('default', gulp.parallel('browser-sync', 'watch'));