-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
122 lines (107 loc) · 2.69 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
const gulp = require( 'gulp' );
const fs = require( 'fs' );
const $ = require( 'gulp-load-plugins' )();
const webpack = require( 'webpack-stream' );
const webpackBundle = require( 'webpack' );
const named = require( 'vinyl-named' );
const mergeStream = require( 'merge-stream' );
const { dumpSetting } = require('@kunoichi/grab-deps');
let plumber = true;
// Sass
gulp.task( 'sass', function () {
return gulp.src( [ './assets/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: [
'./assets/scss',
]
} ) )
.pipe( $.autoprefixer() )
.pipe( $.sourcemaps.write( './map' ) )
.pipe( gulp.dest( './dist/css' ) );
} );
// Style lint.
gulp.task( 'stylelint', function () {
let task = gulp.src( [ './assets/scss/**/*.scss' ] );
if ( plumber ) {
task = task.pipe( $.plumber() );
}
return task.pipe( $.stylelint( {
reporters: [
{
formatter: 'string',
console: true,
},
],
} ) );
} );
// Package jsx.
gulp.task( 'jsx', function () {
return gulp.src( [
'./assets/js/**/*.js',
] )
.pipe( $.plumber( {
errorHandler: $.notify.onError( '<%= error.message %>' )
} ) )
.pipe( named( (file) => {
return file.relative.replace(/\.[^\.]+$/, '');
} ) )
.pipe( webpack( require( './webpack.config.js' ), webpackBundle ) )
.pipe( gulp.dest( './dist/js' ) );
} );
// ESLint
gulp.task( 'eslint', function () {
let task = gulp.src( [
'./assets/js/**/*.js',
] );
if ( plumber ) {
task = task.pipe( $.plumber() );
}
return task.pipe( $.eslint( { useEslintrc: true } ) )
.pipe( $.eslint.format() );
} );
// Copy bundles.
gulp.task( 'copy', ( done ) => {
done();
// return mergeStream(
// gulp.src( [] )
// .pipe( gulp.dest( 'dist/vendor' ) )
// );
} );
// Dump dependencies.
gulp.task( 'dump', ( done ) => {
dumpSetting( 'dist' );
done();
} );
// watch
gulp.task( 'watch', ( done ) => {
// Make SASS
gulp.watch( 'assets/scss/**/*.scss', gulp.parallel( 'sass', 'stylelint' ) );
// Bundle JS
gulp.watch( [ 'assets/js/**/*.{js,jsx}' ], gulp.parallel( 'jsx', 'eslint' ) );
// Dump setting.
gulp.watch( [
'dist/js/**/*.js',
'dist/css/**/*.css',
], gulp.task( 'dump' ) );
done();
} );
// Toggle plumber.
gulp.task( 'noplumber', ( done ) => {
plumber = false;
done();
} );
// Build
gulp.task( 'build', gulp.series( gulp.parallel( 'jsx', 'sass', 'copy' ), 'dump' ) );
// Default Tasks
gulp.task( 'default', gulp.series( 'watch' ) );
// Lint
gulp.task( 'lint', gulp.series( 'noplumber', gulp.parallel( 'stylelint', 'eslint' ) ) );