-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
73 lines (62 loc) · 1.84 KB
/
gulpfile.babel.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
const gulp = require('gulp');
const babel = require('gulp-babel');
const sass = require('gulp-sass');
const browserSync = require('browser-sync');
const autoprefixer = require('gulp-autoprefixer');
const uglify = require('gulp-uglify');
const jshint = require('gulp-jshint');
const header = require('gulp-header');
const rename = require('gulp-rename');
const cssnano = require('gulp-cssnano');
const sourcemaps = require('gulp-sourcemaps');
const postcss = require('gulp-postcss');
const assets = require('postcss-assets');
const fs = require('fs');
const path = require('path');
const md5 = require('md5-file');
const eslint = require('gulp-eslint');
function assetsCachebuster(filePath, urlPathname) {
return fs.statSync(filePath).mtime.getTime().toString(16);
}
gulp.task('css', () => {
return gulp.src('src/scss/style.scss')
.pipe(sass().on('error', sass.logError))
.pipe(postcss([assets({
basePath: 'dist/',
loadPaths: ['img'],
baseUrl: '../',
cachebuster: assetsCachebuster,
})]))
.pipe(autoprefixer('last 4 version'))
.pipe(gulp.dest('dist/css'))
.pipe(cssnano())
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist/css'))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('js', () => {
return gulp.src('src/js/**/*.js')
.pipe(eslint())
.pipe(eslint.format())
.pipe(babel())
.pipe(gulp.dest('dist/js'));
});
gulp.task('html', () => {
gulp.src('src/*.html')
.pipe(gulp.dest('dist'))
});
gulp.task('browser-sync', () => {
browserSync.init(null, {
server: {
baseDir: './dist',
},
open: true,
notify: false
});
});
gulp.task('default', gulp.parallel('css', 'js', 'html', 'browser-sync'), () => {
gulp.watch('src/scss/*.scss', ['css']);
gulp.watch('src/js/*.js', ['js']);
gulp.watch('src/*.html', ['html']);
});