-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
61 lines (55 loc) · 1.58 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
const gulp = require('gulp');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');
const cleanCSS = require('gulp-clean-css');
const autoprefixer = require('gulp-autoprefixer');
const plumber = require('gulp-plumber');
const sass = require('gulp-sass');
const babel = require('gulp-babel');
const DIST_PATH = './dist';
const CSS_PATH = './src/css/**/*.css';
const SCSS_PATH = './src/scss/**/*.scss';
const SCRIPTS_PATH = './src/js/**/*.js';
gulp.task('styles', () => {
console.log('Running styles task');
return gulp
.src(['./src/css/reset.css', CSS_PATH, SCSS_PATH])
.pipe(plumber(err => handleError(err, 'styles')))
.pipe(
sass({
outputStyle: 'compressed'
})
)
.pipe(autoprefixer())
.pipe(concat('styles.css'))
.pipe(cleanCSS({ compatability: 'ie8' }))
.pipe(gulp.dest(DIST_PATH));
});
gulp.task('scripts', () => {
console.log('Running scripts task');
return gulp
.src(SCRIPTS_PATH)
.pipe(plumber(err => handleError(err, 'scripts')))
.pipe(
babel({
presets: ['@babel/preset-env']
})
)
.pipe(concat('bundle.js'))
.pipe(uglify())
.pipe(gulp.dest(DIST_PATH));
});
gulp.task('default', ['styles', 'scripts'], () => {
console.log('Running default task');
});
gulp.task('watch', ['default'], () => {
console.log('Running watch task');
gulp.watch(CSS_PATH, ['styles']);
gulp.watch(SCSS_PATH, ['styles']);
gulp.watch(SCRIPTS_PATH, ['scripts']);
});
function handleError(err, taskNameStr) {
console.log(`${taskNameStr} task error`);
console.log(err);
gulp.emit('end');
}