-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
117 lines (106 loc) · 3.25 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const gulp = require('gulp');
const $ = require('gulp-load-plugins')();
const mozjpeg = require('imagemin-mozjpeg');
const pngquant = require('imagemin-pngquant');
const webpack = require('webpack-stream');
const webpackBundle = require('webpack');
const named = require('vinyl-named');
const {dumpSetting} = require('@kunoichi/grab-deps');
const sass = require('gulp-sass')(require('sass'));
// Sass
gulp.task('scss', function () {
return gulp.src('./src/scss/**/*.scss')
.pipe($.plumber({
errorHandler: $.notify.onError('<%= error.message %>')
}))
// .pipe( $.sassGlob() )
.pipe($.sourcemaps.init())
.pipe(sass({
errLogToConsole: true,
outputStyle: 'compressed',
sourceComments: false,
sourcemap: true,
includePaths: ['./src/scss']
}))
// .pipe( $.autoprefixer() )
.pipe($.sourcemaps.write('./map'))
.pipe(gulp.dest('assets/css'));
});
// Stylelint
gulp.task('stylelint', function (done) {
return gulp.src('./src/scss/**/*.scss')
.pipe($.stylelint({
failAfterError: false,
reporters: [
{
formatter: 'string',
console: true,
},
],
}));
});
// eslint
gulp.task('eslint', function () {
return gulp.src([
'./src/js/**/*.js',
'./src/js/**/*.jsx'
])
.pipe($.eslint({useEslintrc: true}))
.pipe($.eslint.format());
});
// Bundle JavaScripts.
gulp.task('js:bundle', function () {
const tmp = {};
return gulp.src(['./src/js/**/*.jsx', './src/js/**/*.js'])
.pipe($.plumber({
errorHandler: $.notify.onError('<%= error.message %>')
}))
.pipe(named((file) => file.relative.replace(/\.[^\.]+$/, '')))
.pipe(webpack(require('./webpack.config'), webpackBundle))
.pipe(gulp.dest('./assets/js'));
});
// Image min
async function images_to_dist() {
const imagemin = await import('gulp-imagemin');
const imagePlugins = [
pngquant({
quality: [.65, .80],
speed: 1,
floyd: 0
}),
mozjpeg({
quality: 85,
progressive: true
}),
imagemin.svgo(),
imagemin.optipng(),
imagemin.gifsicle(),
];
return gulp.src('./src/img/**/*')
.pipe(imagemin.default(imagePlugins))
.pipe(gulp.dest('./assets/img'));
}
gulp.task('imagemin', function (done) {
return images_to_dist().then(() => done());
});
gulp.task('dump', function (done) {
dumpSetting('assets');
done();
});
// watch
gulp.task('watch', function () {
// Make SASS
gulp.watch('src/scss/**/*.scss', gulp.parallel('scss', 'stylelint'));
// JS bundle
gulp.watch(['src/js/**/*.jsx', 'src/js/**/*.js'], gulp.parallel('js:bundle', 'eslint'));
// Minify Image
gulp.watch('src/img/**/*', gulp.task('imagemin'));
// Dump setting.
gulp.watch(['assets/css/**/*.css', 'assets/js/**/*.js'], gulp.task('dump'));
});
// Default Tasks
gulp.task('default', gulp.task('watch'));
// Build
gulp.task('build', gulp.series(gulp.parallel('js:bundle', 'scss', 'imagemin'), 'dump'));
// Lint tasks.
gulp.task('lint', gulp.parallel('stylelint', 'eslint'));