-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
103 lines (95 loc) · 2.67 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
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
const gulp = require("gulp");
const pug = require("gulp-pug");
const sass = require("gulp-sass");
const plumber = require("gulp-plumber");
const notify = require("gulp-notify");
const sourcemaps = require("gulp-sourcemaps");
const postcss = require("gulp-postcss");
const autoprefixer = require("autoprefixer");
const imagemin = require("gulp-imagemin");
const changed = require("gulp-changed");
const pngquant = require("imagemin-pngquant");
const mozjpeg = require("imagemin-mozjpeg");
const browserSync = require("browser-sync").create();
//htmlのコピー
gulp.task("html", () => {
return gulp
.src("./src/**/*.html")
.pipe(gulp.dest("./dist"));
});
//Pugのコンパイル
gulp.task("pug", () => {
return gulp
.src(["./src/**/*.pug", "!./src/**/_*.pug"])
.pipe(plumber({ errorHandler: notify.onError("Error: <%= error.message %>") }))
.pipe(pug({
pretty: true
}))
.pipe(gulp.dest("./dist"));
});
//Sassのコンパイル
gulp.task("sass", () => {
return gulp
.src("./src/assets/scss/**/*.scss")
.pipe(plumber({ errorHandler: notify.onError("Error: <%= error.message %>") }))
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: "expanded"
}))
.pipe(postcss([autoprefixer({
cascade: false
}
)]))
.pipe(sourcemaps.write())
.pipe(gulp.dest("./dist/assets/css"));
});
//jsのコピー
gulp.task("js", () => {
return gulp
.src("./src/**/*.js")
.pipe(gulp.dest("./dist"));
});
//画像圧縮
gulp.task("imagemin", () => {
return gulp
.src("./src/assets/img/**/*.{png,jpg,jpeg,gif,svg}")
.pipe(changed("./dist/assets/img"))
.pipe(
imagemin([
pngquant({
quality: [.7, .85]
}),
mozjpeg({
quality: 85
}),
imagemin.svgo(),
imagemin.gifsicle()
])
)
.pipe(gulp.dest("./dist/assets/img"));
});
//サーバーの立ち上げ
gulp.task("serve", () => {
browserSync.init({
server: {
baseDir: "./dist"
}
});
});
//ファイルの監視
gulp.task("watch", () => {
const reload = (done) => {
browserSync.reload()
done()
};
gulp.watch("./src/**/*.html", gulp.task("html"));
gulp.watch("./src/**/*.pug", gulp.task("pug"));
gulp.watch("./src/assets/**/*.scss", gulp.task("sass"));
gulp.watch("./src/**/*.js", gulp.task("js"));
gulp.watch("./src/assets/img/**/*.{png,jpg,jpeg,gif,svg}", gulp.task("imagemin"));
gulp.watch("./dist/**/*", reload);
});
//デフォルトのタスク作成
gulp.task("default",
gulp.series("html", "pug", "sass", "js", "imagemin", gulp.parallel("serve", "watch"))
);