This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
87 lines (75 loc) · 1.96 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
import gulp from 'gulp';
import del from 'del';
import webpackStream from 'webpack-stream';
import webpackConfig from './webpack.config.js';
import webpack from 'webpack';
import sass from 'gulp-sass';
import pug from 'gulp-pug';
import imagemin from 'gulp-imagemin';
import _browserSync from 'browser-sync';
const browserSync = _browserSync.create();
const paths = {
scripts: {
src: 'src/assets/js/**/*.js',
dest: 'dist/assets/js/'
},
styles: {
src: 'src/assets/scss/**/*.scss',
dest: 'dist/assets/css/'
},
htmls: {
src: ['src/**/*.pug', '!src/**/_*.pug'],
watch: ['src/**/*.pug', 'src/**/_*.pug'],
dest: 'dist/'
},
images: {
src: 'src/assets/images/**/*',
dest: 'dist/assets/images/'
}
};
//clean up
export const clean = () => del([ 'dist' ]);
//JS
export function scripts () {
return webpackStream( webpackConfig, webpack)
.pipe(gulp.dest(paths.scripts.dest));
}
//CSS
export function styles() {
return gulp.src(paths.styles.src)
.pipe(sass({
outputStyle: 'nested'
}).on('error', sass.logError))
.pipe(gulp.dest(paths.styles.dest));
}
//Pug(HTML)
export function htmls () {
return gulp.src(paths.htmls.src)
.pipe(pug())
.pipe(gulp.dest(paths.htmls.dest));
}
//画像
export function images() {
return gulp.src(paths.images.src)
.pipe(imagemin({
verbose: true
}))
.pipe(gulp.dest(paths.images.dest))
}
//Watch
export function watch() {
browserSync.init({
server: {
baseDir: 'dist/'
}
});
gulp.watch(paths.scripts.src, scripts);
gulp.watch(paths.styles.src, styles);
gulp.watch(paths.htmls.watch, htmls);
gulp.watch(paths.images.src, images);
gulp.watch([paths.htmls.dest, paths.scripts.dest, paths.styles.dest, paths.images.dest]).on('change', browserSync.reload);
}
const build = gulp.series(clean, gulp.parallel(htmls, images, scripts, styles));
const _default = gulp.series(build, watch);
gulp.task('build', build);
export default _default