質問編集履歴
1
package.jsonとgulpfine.jsの追記です。
test
CHANGED
File without changes
|
test
CHANGED
@@ -7,3 +7,453 @@
|
|
7
7
|
以下、gulp watch した際のコンソール画面。
|
8
8
|
|
9
9
|
![イメージ説明](188df99acbf96ab38cd7874426c8efa5.png)
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
少し長くなりますが、package.jsonとgulpfine.jsの追記です。
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
```package.json
|
18
|
+
|
19
|
+
{
|
20
|
+
|
21
|
+
"name": "gulp",
|
22
|
+
|
23
|
+
"version": "1.0.0",
|
24
|
+
|
25
|
+
"description": "",
|
26
|
+
|
27
|
+
"main": "index.js",
|
28
|
+
|
29
|
+
"scripts": {
|
30
|
+
|
31
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
32
|
+
|
33
|
+
},
|
34
|
+
|
35
|
+
"author": "",
|
36
|
+
|
37
|
+
"license": "ISC",
|
38
|
+
|
39
|
+
"devDependencies": {
|
40
|
+
|
41
|
+
"browser-sync": "^2.18.8",
|
42
|
+
|
43
|
+
"gulp": "^4.0.0",
|
44
|
+
|
45
|
+
"gulp-changed": "^3.2.0",
|
46
|
+
|
47
|
+
"gulp-plumber": "^1.1.0",
|
48
|
+
|
49
|
+
"gulp-sass": "^4.0.1"
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
```gulpfile.js
|
60
|
+
|
61
|
+
var gulp = require('gulp'),
|
62
|
+
|
63
|
+
autoprefixer = require('gulp-autoprefixer'),
|
64
|
+
|
65
|
+
browserSync = require('browser-sync'),
|
66
|
+
|
67
|
+
cssimport = require('postcss-import'),
|
68
|
+
|
69
|
+
cssmin = require('gulp-cssmin'),
|
70
|
+
|
71
|
+
cssv = require('gulp-csslint'),
|
72
|
+
|
73
|
+
cssvariables = require('postcss-css-variables'),
|
74
|
+
|
75
|
+
colorfunction = require('postcss-color-function'),
|
76
|
+
|
77
|
+
coffee = require('gulp-coffee'),
|
78
|
+
|
79
|
+
concat = require('gulp-concat'),
|
80
|
+
|
81
|
+
htmlv = require('gulp-htmlhint'),
|
82
|
+
|
83
|
+
imagemin = require('gulp-imagemin'),
|
84
|
+
|
85
|
+
mqpacker = require('css-mqpacker'),
|
86
|
+
|
87
|
+
nested = require('postcss-nested'),
|
88
|
+
|
89
|
+
notify = require('gulp-notify'),
|
90
|
+
|
91
|
+
plumber = require('gulp-plumber'),
|
92
|
+
|
93
|
+
postcss = require('gulp-postcss'),
|
94
|
+
|
95
|
+
pump = require('pump'),
|
96
|
+
|
97
|
+
rename = require('gulp-rename'),
|
98
|
+
|
99
|
+
simplevars = require('postcss-simple-vars'),
|
100
|
+
|
101
|
+
slim = require('gulp-slim'),
|
102
|
+
|
103
|
+
ssi = require('browsersync-ssi'),
|
104
|
+
|
105
|
+
tinyping = require('gulp-tinypng-compress'),
|
106
|
+
|
107
|
+
uglify = require('gulp-uglify');
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
// default
|
112
|
+
|
113
|
+
gulp.task('default', ['watch', 'browser-sync']);
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
// concat
|
118
|
+
|
119
|
+
gulp.task('css.concat', () => {
|
120
|
+
|
121
|
+
var plugins = [
|
122
|
+
|
123
|
+
colorfunction,
|
124
|
+
|
125
|
+
cssimport,
|
126
|
+
|
127
|
+
cssvariables,
|
128
|
+
|
129
|
+
mqpacker,
|
130
|
+
|
131
|
+
nested,
|
132
|
+
|
133
|
+
simplevars
|
134
|
+
|
135
|
+
];
|
136
|
+
|
137
|
+
gulp.src('docs/tmp/css/*.css')
|
138
|
+
|
139
|
+
.pipe(plumber({
|
140
|
+
|
141
|
+
errorHandler: notify.onError('Error: <%= error.message %>')
|
142
|
+
|
143
|
+
}))
|
144
|
+
|
145
|
+
.pipe(postcss(plugins))
|
146
|
+
|
147
|
+
.pipe(autoprefixer({
|
148
|
+
|
149
|
+
browsers: ['last 2 version'],
|
150
|
+
|
151
|
+
grid: true
|
152
|
+
|
153
|
+
}))
|
154
|
+
|
155
|
+
.pipe(concat('s.css'))
|
156
|
+
|
157
|
+
.pipe(gulp.dest('docs/tmp/concat'))
|
158
|
+
|
159
|
+
});
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
// cssmin
|
164
|
+
|
165
|
+
gulp.task('cssmin', ['css.concat'], () => {
|
166
|
+
|
167
|
+
gulp.src('docs/tmp/concat/s.css')
|
168
|
+
|
169
|
+
.pipe(plumber({
|
170
|
+
|
171
|
+
errorHandler: notify.onError('Error: <%= error.message %>')
|
172
|
+
|
173
|
+
}))
|
174
|
+
|
175
|
+
.pipe(cssmin())
|
176
|
+
|
177
|
+
.pipe(rename({suffix: '.min'}))
|
178
|
+
|
179
|
+
.pipe(gulp.dest('htdocs/css'))
|
180
|
+
|
181
|
+
.pipe(browserSync.stream())
|
182
|
+
|
183
|
+
});
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
// css
|
188
|
+
|
189
|
+
gulp.task('css', ['css.concat', 'cssmin']);
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
// coffee
|
194
|
+
|
195
|
+
gulp.task('coffee', () => {
|
196
|
+
|
197
|
+
gulp.src('docs/tmp/js/*.coffee')
|
198
|
+
|
199
|
+
.pipe(plumber({
|
200
|
+
|
201
|
+
errorHandler: notify.onError('Error: <%= error.message %>')
|
202
|
+
|
203
|
+
}))
|
204
|
+
|
205
|
+
.pipe(coffee({bare: true}))
|
206
|
+
|
207
|
+
.pipe(gulp.dest('htdocs/js'))
|
208
|
+
|
209
|
+
.pipe(browserSync.stream())
|
210
|
+
|
211
|
+
});
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
// uglify
|
216
|
+
|
217
|
+
gulp.task('jsmin', (cb) => {
|
218
|
+
|
219
|
+
pump(
|
220
|
+
|
221
|
+
[
|
222
|
+
|
223
|
+
gulp.src('htdocs/js/*js'),
|
224
|
+
|
225
|
+
uglify(),
|
226
|
+
|
227
|
+
rename({suffix: '.min'}),
|
228
|
+
|
229
|
+
gulp.dest('htdocs/js/min')
|
230
|
+
|
231
|
+
],
|
232
|
+
|
233
|
+
cb
|
234
|
+
|
235
|
+
);
|
236
|
+
|
237
|
+
});
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
// slim
|
242
|
+
|
243
|
+
gulp.task('slim', () => {
|
244
|
+
|
245
|
+
gulp.src('docs/tmp/slim/*.slim')
|
246
|
+
|
247
|
+
.pipe(plumber({
|
248
|
+
|
249
|
+
errorHandler: notify.onError('Error: <%= error.message %>')
|
250
|
+
|
251
|
+
}))
|
252
|
+
|
253
|
+
.pipe(slim({
|
254
|
+
|
255
|
+
require: 'slim/include',
|
256
|
+
|
257
|
+
pretty: true,
|
258
|
+
|
259
|
+
options: 'include_dirs=["docs/tmp/slim/inc"]'
|
260
|
+
|
261
|
+
}))
|
262
|
+
|
263
|
+
.pipe(gulp.dest('htdocs'))
|
264
|
+
|
265
|
+
.pipe(browserSync.stream())
|
266
|
+
|
267
|
+
});
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
// watch
|
272
|
+
|
273
|
+
gulp.task('watch', () => {
|
274
|
+
|
275
|
+
gulp.watch(['docs/tmp/css/*.css'], ['css']);
|
276
|
+
|
277
|
+
gulp.watch(['docs/tmp/js/*.coffee'], ['coffee']);
|
278
|
+
|
279
|
+
gulp.watch(['docs/tmp/slim/**/*.slim'], ['slim']);
|
280
|
+
|
281
|
+
});
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
// browser-sync
|
286
|
+
|
287
|
+
gulp.task('browser-sync', () => {
|
288
|
+
|
289
|
+
browserSync({
|
290
|
+
|
291
|
+
server: {
|
292
|
+
|
293
|
+
baseDir: 'htdocs',
|
294
|
+
|
295
|
+
middleware:[
|
296
|
+
|
297
|
+
ssi({
|
298
|
+
|
299
|
+
ext: '.html',
|
300
|
+
|
301
|
+
baseDir: 'htdocs'
|
302
|
+
|
303
|
+
})
|
304
|
+
|
305
|
+
]
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
});
|
310
|
+
|
311
|
+
});
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
// tinypng
|
316
|
+
|
317
|
+
gulp.task('tinypng', () => {
|
318
|
+
|
319
|
+
gulp.src('docs/tmp/img/src/**/*.{png,jpg}')
|
320
|
+
|
321
|
+
.pipe(tinyping({
|
322
|
+
|
323
|
+
key: '__API_Key__'
|
324
|
+
|
325
|
+
summarize: true
|
326
|
+
|
327
|
+
}))
|
328
|
+
|
329
|
+
.pipe(gulp.dest('docs/tmp/img/dist'))
|
330
|
+
|
331
|
+
});
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
// imagemin
|
336
|
+
|
337
|
+
gulp.task('imagemin', () => {
|
338
|
+
|
339
|
+
gulp.src('docs/tmp/img/src/**/*.{png,jpg,gif,svg}')
|
340
|
+
|
341
|
+
.pipe(imagemin([
|
342
|
+
|
343
|
+
imagemin.gifsicle({interlaced: true}),
|
344
|
+
|
345
|
+
imagemin.jpegtran({progressive: true}),
|
346
|
+
|
347
|
+
imagemin.optipng({optimizationLevel: 4}),
|
348
|
+
|
349
|
+
imagemin.svgo({
|
350
|
+
|
351
|
+
plugins: [
|
352
|
+
|
353
|
+
{removeViewBox: false}
|
354
|
+
|
355
|
+
]
|
356
|
+
|
357
|
+
})
|
358
|
+
|
359
|
+
]))
|
360
|
+
|
361
|
+
.pipe(gulp.dest('docs/tmp/img/dist'))
|
362
|
+
|
363
|
+
});
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
// htmlhint
|
368
|
+
|
369
|
+
gulp.task('htmlv', () => {
|
370
|
+
|
371
|
+
gulp.src('htdocs/*.html')
|
372
|
+
|
373
|
+
.pipe(htmlv())
|
374
|
+
|
375
|
+
.pipe(htmlv.reporter())
|
376
|
+
|
377
|
+
});
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
// csslint
|
382
|
+
|
383
|
+
gulp.task('cssv', () => {
|
384
|
+
|
385
|
+
gulp.src('htdocs/css/s.min.css')
|
386
|
+
|
387
|
+
.pipe(cssv({
|
388
|
+
|
389
|
+
'adjoining-classes': false,
|
390
|
+
|
391
|
+
'box-model': false,
|
392
|
+
|
393
|
+
'box-sizing': false,
|
394
|
+
|
395
|
+
'bulletproof-font-face': false,
|
396
|
+
|
397
|
+
'compatible-vendor-prefixes': false,
|
398
|
+
|
399
|
+
'empty-rules': true,
|
400
|
+
|
401
|
+
'display-property-grouping': true,
|
402
|
+
|
403
|
+
'duplicate-background-images': false,
|
404
|
+
|
405
|
+
'duplicate-properties': true,
|
406
|
+
|
407
|
+
'fallback-colors': false,
|
408
|
+
|
409
|
+
'floats': false,
|
410
|
+
|
411
|
+
'font-faces': false,
|
412
|
+
|
413
|
+
'font-sizes': false,
|
414
|
+
|
415
|
+
'gradients': false,
|
416
|
+
|
417
|
+
'ids': false,
|
418
|
+
|
419
|
+
'import': false,
|
420
|
+
|
421
|
+
'important': false,
|
422
|
+
|
423
|
+
'known-properties': true,
|
424
|
+
|
425
|
+
'order-alphabetical': false,
|
426
|
+
|
427
|
+
'outline-none': true,
|
428
|
+
|
429
|
+
'overqualified-elements': false,
|
430
|
+
|
431
|
+
'qualified-headings': false,
|
432
|
+
|
433
|
+
'regex-selectors': false,
|
434
|
+
|
435
|
+
'shorthand': false,
|
436
|
+
|
437
|
+
'star-property-hack': false,
|
438
|
+
|
439
|
+
'text-indent': false,
|
440
|
+
|
441
|
+
'underscore-property-hack': false,
|
442
|
+
|
443
|
+
'unique-headings': false,
|
444
|
+
|
445
|
+
'universal-selector': false,
|
446
|
+
|
447
|
+
'unqualified-attributes': false,
|
448
|
+
|
449
|
+
'vendor-prefix': false,
|
450
|
+
|
451
|
+
'zero-units': true
|
452
|
+
|
453
|
+
}))
|
454
|
+
|
455
|
+
.pipe(cssv.formatter('compact'))
|
456
|
+
|
457
|
+
});
|
458
|
+
|
459
|
+
```
|