-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
158 lines (145 loc) · 3.92 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
const gulp = require( 'gulp' );
const fs = require( 'fs' );
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 browserSync = require( 'browser-sync' ).create();
// Sassのタスク
gulp.task( 'sass', function() {
return gulp.src( [
'./src/scss/**/*.scss',
] )
.pipe( $.plumber( {
errorHandler: $.notify.onError( '<%= error.message %>' )
} ) )
.pipe( $.sourcemaps.init( { loadMaps: true } ) )
.pipe( $.sassGlob() )
.pipe( $.sass( {
errLogToConsole: true,
outputStyle: 'compressed',
includePaths: [
'./src/scss',
'./node_modules/bootstrap/scss',
],
} ) )
.pipe( $.autoprefixer() )
.pipe( $.sourcemaps.write( './map' ) )
.pipe( gulp.dest( './assets/css' ) );
} );
// Lint SCSS
gulp.task( 'stylelint', () => gulp.src( [ './src/scss/**/*.scss' ] )
.pipe( $.stylelint( {
failAfterError: false,
reporters: [
{
formatter: 'string',
console: true,
},
],
} ) )
);
// Bundle Javascript
gulp.task( 'js', () => {
return gulp.src( [ './src/js/**/*.js' ] )
.pipe( $.plumber( {
errorHandler: $.notify.onError( 'JS ERROR: <%= error.message %>' )
} ) )
.pipe( named( function( file ) {
return file.relative.replace( /\.[^.]+$/, '' );
} ) )
.pipe( webpack( require( './webpack.config' ), webpackBundle ) )
.pipe( gulp.dest( './assets/js/' ) );
} );
// JS Hint
gulp.task( 'eslint', function() {
return gulp.src( [
'./src/js/**/*.js',
] )
.pipe( $.eslint( { useEslintrc: true } ) )
.pipe( $.eslint.format() );
} );
// Build modernizr
gulp.task( 'copylib', function() {
return mergeStream(
// copy js
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/vue/dist/vue.min.js',
'./node_modules/moment/min/moment-with-locales.min.js',
'./node_modules/chart.js/dist/Chart.min.js',
'./node_modules/vue-chartjs/dist/vue-chartjs.min.js',
'./node_modules/vue-chartjs/dist/vue-chartjs.js.map',
] )
.pipe( gulp.dest( './assets/js' ) )
);
} );
// Image min
gulp.task( 'imagemin', function() {
return gulp.src( './src/img/**/*' )
.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' ) );
} );
// Pug task
gulp.task( 'pug', function() {
return gulp.src( [ 'src/pug/**/*', '!src/pug/**/_*' ] )
.pipe( $.plumber( {
errorHandler: $.notify.onError( 'HTML ERROR: <%= error.message %>' ),
} ) )
.pipe( $.pug( {
pretty: true,
} ) )
.pipe( gulp.dest( 'assets' ) )
} );
// watch browser sync
gulp.task( 'server', function() {
return browserSync.init( {
files: [ 'assets/**/*' ],
server: {
baseDir: './assets',
index: 'index.html',
},
reloadDelay: 2000,
} );
} );
gulp.task( 'reload', function() {
gulp.watch( 'assets/**/*', function() {
return browserSync.reload();
} );
} );
// watch
gulp.task( 'watch', function() {
// Make SASS
gulp.watch( 'src/scss/**/*.scss', gulp.parallel( 'sass', 'stylelint' ) );
// JS
gulp.watch( [ 'src/js/**/*.js' ], gulp.parallel( 'js', 'eslint' ) );
// Minify Image
gulp.watch( 'src/img/**/*', gulp.parallel( 'imagemin' ) );
// Compile HTML
gulp.watch( 'src/pug/**/*', gulp.parallel( 'pug' ) );
} );
// Build
gulp.task( 'build', gulp.parallel( 'copylib', 'eslint', 'js', 'sass', 'imagemin' ) );
// HTML task
gulp.task( 'html', gulp.series( 'build', 'watch', 'server', 'reload' ) );
// Default Tasks
gulp.task( 'default', gulp.parallel( 'watch' ) );