-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
executable file
·143 lines (127 loc) · 2.85 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import gulp from 'gulp';
import imagemin from "gulp-imagemin";
import newer from "gulp-newer";
import less from 'gulp-less';
import babel from 'gulp-babel';
import concat from 'gulp-concat';
import uglify from 'gulp-uglify';
import rename from 'gulp-rename';
import cleanCSS from 'gulp-clean-css';
import htmlmin from 'gulp-htmlmin';
import del from 'del';
import browserSync from 'browser-sync';
const server = browserSync.create();
const paths = {
images: {
src: 'src/img/**/*',
dest: 'dist/img/'
},
styles: {
src: 'src/styles/**/*.less',
dest: 'dist/styles/'
},
scripts: {
src: 'src/scripts/**/*.js',
dest: 'dist/scripts/'
},
pages: {
src: 'src/**/*.html',
dest: 'dist/'
}
};
/*
* For small tasks you can export arrow functions
*/
export const clean = () => del(['dist']);
/*
* You can also declare named functions and export them as tasks
*/
export function images() {
return gulp
.src(paths.images.src)
.pipe(newer(paths.images.src))
.pipe(
imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}]
})
)
.pipe(gulp.dest(paths.images.dest))
}
export function styles() {
return gulp
.src(paths.styles.src)
.pipe(less())
.pipe(cleanCSS())
// pass in options to the stream
.pipe(rename({
basename: 'main',
suffix: '.min'
}))
.pipe(gulp.dest(paths.styles.dest))
.pipe(browserSync.stream());
}
export function scripts() {
return gulp
.src(paths.scripts.src, {
sourcemaps: true
})
.pipe(babel())
.pipe(uglify())
.pipe(concat('main.min.js'))
.pipe(gulp.dest(paths.scripts.dest));
}
export function htmls() {
return gulp
.src(paths.pages.src)
.pipe(htmlmin({
collapseWhitespace: true
}))
.pipe(gulp.dest(paths.pages.dest))
}
/*
* Set up reload
*/
export function reload(done) {
server.reload();
done();
};
/*
* Set up serve to init the page
*/
export function serve(done) {
server.init({
server: {
baseDir: './dist'
},
port: 3000
});
done();
};
/*
* You could even use `export as` to rename exported tasks
*/
function watchFiles() {
gulp.watch(paths.images.src, gulp.series(images, reload));
gulp.watch(paths.scripts.src, gulp.series(scripts, reload));
gulp.watch(paths.styles.src, gulp.series(styles, reload));
gulp.watch(paths.pages.src, gulp.series(htmls, reload));
}
export {
watchFiles as watch
};
/*
* You can still use `gulp.task` create the build task that can be called alone
* for example to set task names that would otherwise be invalid
*/
const build = gulp.series(clean, gulp.parallel(images, styles, scripts, htmls));
gulp.task('build', build);
/*
*
* Here we set up the default process to fire up the server and watch
*/
const dev = gulp.series(clean, build, serve, watchFiles)
/*
* Export a default task
*/
export default dev;