-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
181 lines (163 loc) · 4.17 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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
const gulp = require( 'gulp' );
const $ = require( 'gulp-load-plugins' )();
const mozjpeg = require( 'imagemin-mozjpeg' );
const pngquant = require( 'imagemin-pngquant' );
const mergeStream = require( 'merge-stream' );
const webpack = require( 'webpack-stream' );
const webpackBundle = require( 'webpack' );
const named = require( 'vinyl-named' );
const bulkImport = require( './src/gulp/bulk-importer' );
//
// SCSS tasks
// ================
//
// Lint SCSS
gulp.task( 'scss:lint', function() {
return gulp.src( './src/scss/**/*.scss' )
.pipe( $.stylelint( {
reporters: [
{
formatter: 'string',
console: true,
},
],
} ) );
} );
gulp.task( 'scss:generate', function() {
const includePath = [
'./src/scss',
'./vendor/hametuha/hashboard/src/scss',
'../../lib/hashboard/src/scss',
'../../plugins/makibishi/vendor/hametuha/hashboard/src/scss',
'./node_modules/bootstrap/scss',
'./node_modules/swiper/src',
];
return gulp.src( [
'./src/scss/**/*.scss',
] )
.pipe( $.plumber( {
errorHandler: $.notify.onError( 'SCSS: <%= error.message %>' ),
} ) )
.pipe( $.sourcemaps.init( { loadMaps: true } ) )
.pipe( bulkImport( {
includePaths: includePath,
} ) )
.pipe( $.sass( {
errLogToConsole: true,
outputStyle: 'compressed',
includePaths: includePath,
} ) )
.pipe( $.autoprefixer() )
.pipe( $.sourcemaps.write( './map' ) )
.pipe( gulp.dest( './assets/css' ) );
} );
gulp.task( 'scss', gulp.parallel( 'scss:generate', 'scss:lint' ) );
//
// JS Bundle
// ===============
//
// Minify All
gulp.task( 'js:bundle', function() {
const tmp = {};
return gulp.src( [ './src/js/**/*.js' ] )
.pipe( $.plumber( {
errorHandler: $.notify.onError( '<%= error.message %>' ),
} ) )
.pipe( named() )
.pipe( $.rename( function( path ) {
tmp[ path.basename ] = path.dirname;
} ) )
.pipe( webpack( require( './webpack.config.js' ), webpackBundle ) )
.pipe( $.rename( function( path ) {
if ( tmp[ path.basename ] ) {
path.dirname = tmp[ path.basename ];
} else if ( '.map' === path.extname && tmp[ path.basename.replace( /\.js$/, '' ) ] ) {
path.dirname = tmp[ path.basename.replace( /\.js$/, '' ) ];
}
return path;
} ) )
.pipe( gulp.dest( './assets/js/' ) );
} );
// ESLint
gulp.task( 'js:eslint', function() {
return gulp.src( [ 'src/**/*.js' ] )
.pipe( $.eslint( { useEslintrc: true } ) )
.pipe( $.eslint.format() );
} );
// JS task.
gulp.task( 'js', gulp.parallel( 'js:bundle', 'js:eslint' ) );
//
// Copy Library
// ==============
//
// Just copy.
gulp.task( 'copy', function() {
return mergeStream(
gulp.src( [
'./node_modules/bootstrap/dist/js/bootstrap.min.js',
'./node_modules/bootstrap/dist/js/bootstrap.min.js.map',
'./node_modules/popper.js/dist/umd/popper.min.js',
'./node_modules/popper.js/dist/umd/popper.min.js.map',
'./node_modules/swiper/js/swiper.min.js',
'./node_modules/swiper/js/swiper.min.js.map',
] )
.pipe( gulp.dest( 'assets/js' ) )
);
} );
//
// Image min
// ==============
//
// SVG Minify and copy
gulp.task( 'imagemin:svg', function() {
return gulp.src( './src/img/**/*.svg' )
.pipe( $.svgmin() )
.pipe( gulp.dest( './assets/icon ' ) );
} );
// Image min
gulp.task( 'imagemin:misc', function() {
return gulp.src( [
'./src/img/**/*',
'!./src/img/**/*.svg',
] )
.pipe( $.imagemin( [
pngquant( {
quality: [ .65, .8 ],
speed: 1,
floyd: 0,
} ),
mozjpeg( {
quality: 85,
progressive: true,
} ),
$.imagemin.svgo(),
$.imagemin.optipng(),
$.imagemin.gifsicle(),
] ) )
.pipe( gulp.dest( './assets/img' ) );
} );
// minify all images.
gulp.task( 'imagemin', gulp.parallel( 'imagemin:misc', 'imagemin:svg' ) );
//
// Watch
// =================
//
gulp.task( 'watch', function() {
// Make SASS
gulp.watch( [
'src/scss/**/*.scss',
'../../lib/hashboard/src/scss/**/*.scss',
], gulp.task( 'scss' ) );
// JS
gulp.watch( [ 'src/js/**/*.js' ], gulp.task( 'js' ) );
// Minify Image
gulp.watch( 'src/img/**/*', gulp.task( 'imagemin' ) );
} );
//
// Global commands.
// ================
//
// Build
gulp.task( 'build', gulp.parallel( 'copy', 'js:bundle', 'scss:generate', 'imagemin' ) );
// Default Tasks
gulp.task( 'default', gulp.task( 'watch' ) );