-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
109 lines (96 loc) · 2.52 KB
/
Copy pathgulpfile.js
File metadata and controls
109 lines (96 loc) · 2.52 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const autoprefixer = require('autoprefixer')
const babel = require('gulp-babel')
const bsCreate = require('browser-sync').create
const cssnano = require('cssnano')
const del = require('del')
const gulp = require('gulp')
const gulpIgnore = require('gulp-ignore')
const postcss = require('gulp-postcss')
const postcssImport = require('postcss-import')
const postcssCustomProperties = require('postcss-custom-properties')
const size = require('gulp-size')
const sourcemaps = require('gulp-sourcemaps')
const uglify = require('gulp-uglify')
const browserSync = bsCreate()
const dirs = {
src: 'src',
dest: 'dist'
}
const htmlPaths = {
srcFiles: `${dirs.src}`,
destDir: `${dirs.dest}`,
exclude: `partials/**`
}
const cssPaths = {
srcFiles: `${dirs.src}/styles`,
destDir: `${dirs.dest}/styles`,
exclude: `partials/**`
}
const jsPaths = {
srcFiles: `${dirs.src}/scripts`,
destDir: `${dirs.dest}/scripts`,
exclude: `includes/**`
}
gulp.task('html', () => {
return gulp.src(`${htmlPaths.srcFiles}/**/*.html`)
.pipe(gulpIgnore.exclude(htmlPaths.exclude))
.pipe(size({title: 'Write HTML:', showFiles: true}))
.pipe(gulp.dest(htmlPaths.destDir))
})
gulp.task('css', () => {
return gulp.src(`${cssPaths.srcFiles}/**/*.css`)
.pipe(sourcemaps.init())
.pipe(postcss([
postcssImport(),
postcssCustomProperties(),
autoprefixer(),
cssnano()
]))
.pipe(gulpIgnore.exclude(cssPaths.exclude))
.pipe(size({title: 'Write CSS:', showFiles: true}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(cssPaths.destDir))
})
gulp.task('js', () => {
return gulp.src(`${jsPaths.srcFiles}/**/*.js`)
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['latest']
}))
.pipe(uglify())
.pipe(gulpIgnore.exclude(jsPaths.exclude))
.pipe(size({title: 'Write JS:', showFiles: true}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(jsPaths.destDir))
})
gulp.task('browsersync', () => {
browserSync.init({
server: {
baseDir: './dist'
}
})
})
gulp.task('watch', () => {
gulp.watch(`${htmlPaths.srcFiles}/**/*.html`, ['html', browserSync.reload])
gulp.watch(`${cssPaths.srcFiles}/**/*.css`, ['css', browserSync.reload])
gulp.watch(`${jsPaths.srcFiles}/**/*.js`, ['js', browserSync.reload])
})
gulp.task('clean', () => {
return del(dirs.dest)
})
gulp.task('build', ['clean'], () => {
gulp.start([
'html',
'css',
'js'
])
})
gulp.task('default', ['clean'], () => {
gulp.start([
'html',
'css',
'js',
'browsersync',
'watch'
])
})