質問編集履歴
2
jsファイル 追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -47,3 +47,547 @@
|
|
47
47
|
#やってみたこと2
|
48
48
|
|
49
49
|
gulpと実行し、そのままの状態で、sassファイルに修正を加えるとcssファイルの更新日が変わることが確認できました。これは正しい手順でしょうか???
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
■gulpfile.js
|
54
|
+
|
55
|
+
```js
|
56
|
+
|
57
|
+
var gulp = require('gulp');
|
58
|
+
|
59
|
+
var $ = require('gulp-load-plugins')();
|
60
|
+
|
61
|
+
var browserify = require('browserify');
|
62
|
+
|
63
|
+
var babelify = require('babelify');
|
64
|
+
|
65
|
+
var watchify = require('watchify');
|
66
|
+
|
67
|
+
var source = require('vinyl-source-stream');
|
68
|
+
|
69
|
+
var runSequence = require('run-sequence');
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
var ga2 = {
|
74
|
+
|
75
|
+
src: './',
|
76
|
+
|
77
|
+
pub: '../public/',
|
78
|
+
|
79
|
+
assets: '../public/assets/',
|
80
|
+
|
81
|
+
js: {
|
82
|
+
|
83
|
+
src: './js/',
|
84
|
+
|
85
|
+
pub: '../public/assets/js/'
|
86
|
+
|
87
|
+
},
|
88
|
+
|
89
|
+
css: {
|
90
|
+
|
91
|
+
src: './css/',
|
92
|
+
|
93
|
+
pub: '../public/assets/css/'
|
94
|
+
|
95
|
+
},
|
96
|
+
|
97
|
+
img: {
|
98
|
+
|
99
|
+
src: './img/',
|
100
|
+
|
101
|
+
pub: '../public/assets/img/'
|
102
|
+
|
103
|
+
},
|
104
|
+
|
105
|
+
html: {
|
106
|
+
|
107
|
+
src: './html/',
|
108
|
+
|
109
|
+
pub: '../public/'
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
};
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
// scripts
|
118
|
+
|
119
|
+
gulp.task('watchify:ga2', function(){
|
120
|
+
|
121
|
+
return compileJs({
|
122
|
+
|
123
|
+
file: 'main.js',
|
124
|
+
|
125
|
+
src: ga2.js.src,
|
126
|
+
|
127
|
+
dest: ga2.js.pub
|
128
|
+
|
129
|
+
});
|
130
|
+
|
131
|
+
});
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
gulp.task('watchify:gaModules', function(){
|
136
|
+
|
137
|
+
return compileJs({
|
138
|
+
|
139
|
+
file: 'ga-modules.js',
|
140
|
+
|
141
|
+
src: ga2.js.src,
|
142
|
+
|
143
|
+
dest: ga2.js.pub
|
144
|
+
|
145
|
+
});
|
146
|
+
|
147
|
+
});
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
gulp.task('watchify:gaWidgets', function(){
|
152
|
+
|
153
|
+
return compileJs({
|
154
|
+
|
155
|
+
file: 'ga-widgets.js',
|
156
|
+
|
157
|
+
src: ga2.js.src,
|
158
|
+
|
159
|
+
dest: ga2.js.pub
|
160
|
+
|
161
|
+
});
|
162
|
+
|
163
|
+
});
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
gulp.task('watchify:gaWidgetsDev', function(){
|
168
|
+
|
169
|
+
return compileJs({
|
170
|
+
|
171
|
+
file: 'ga-widgets-dev.js',
|
172
|
+
|
173
|
+
src: ga2.js.src,
|
174
|
+
|
175
|
+
dest: ga2.js.pub
|
176
|
+
|
177
|
+
});
|
178
|
+
|
179
|
+
});
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
function compileJs(opt){
|
184
|
+
|
185
|
+
var bundler = watchify(browserify({
|
186
|
+
|
187
|
+
entries: [opt.src + opt.file],
|
188
|
+
|
189
|
+
transform: ['babelify', 'coffeeify', 'browserify-shim'],
|
190
|
+
|
191
|
+
cache: {},
|
192
|
+
|
193
|
+
packageCache: {}
|
194
|
+
|
195
|
+
}));
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
function bundle(){
|
200
|
+
|
201
|
+
return bundler
|
202
|
+
|
203
|
+
.bundle()
|
204
|
+
|
205
|
+
.on('error', handleErrors)
|
206
|
+
|
207
|
+
.pipe(source(opt.file))
|
208
|
+
|
209
|
+
.pipe($.duration('compiled ' + opt.file))
|
210
|
+
|
211
|
+
.pipe(gulp.dest(opt.dest))
|
212
|
+
|
213
|
+
.pipe($.connect.reload());
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
bundler.on('update', bundle);
|
220
|
+
|
221
|
+
return bundle();
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
gulp.task('watchify', ['watchify:ga2', 'watchify:gaModules', 'watchify:gaWidgets', 'watchify:gaWidgetsDev']);
|
228
|
+
|
229
|
+
gulp.task('scripts:modules', function(){
|
230
|
+
|
231
|
+
return gulp.src(ga2.js.src + 'page-modules/*.js')
|
232
|
+
|
233
|
+
.pipe(gulp.dest(ga2.js.pub + 'modules/'))
|
234
|
+
|
235
|
+
.pipe($.connect.reload());
|
236
|
+
|
237
|
+
});
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
// styles
|
242
|
+
|
243
|
+
gulp.task('styles:ga2', function(){
|
244
|
+
|
245
|
+
return gulp.src(ga2.css.src + '**/*.{sass,scss}')
|
246
|
+
|
247
|
+
.pipe($.sass({
|
248
|
+
|
249
|
+
outputStyle: 'compact'
|
250
|
+
|
251
|
+
})
|
252
|
+
|
253
|
+
.on('error', handleErrors))
|
254
|
+
|
255
|
+
.pipe($.autoprefixer({
|
256
|
+
|
257
|
+
browsers: ['last 2 versions', 'iOS >= 7', 'Android >= 4', 'Explorer >= 9'],
|
258
|
+
|
259
|
+
cascade: false
|
260
|
+
|
261
|
+
}))
|
262
|
+
|
263
|
+
.pipe(gulp.dest(ga2.css.pub))
|
264
|
+
|
265
|
+
.pipe($.connect.reload());
|
266
|
+
|
267
|
+
});
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
// html
|
272
|
+
|
273
|
+
var configJson = require(ga2.html.src + 'config.json');
|
274
|
+
|
275
|
+
var jadePages = ga2.html.src + 'pages/**/*.jade';
|
276
|
+
|
277
|
+
var jadeTemplates = ga2.html.src + 'layouts/**/*.jade';
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
gulp.task('jade:page', function(){
|
282
|
+
|
283
|
+
return gulp.src(jadePages)
|
284
|
+
|
285
|
+
.pipe($.changed(ga2.html.pub, {
|
286
|
+
|
287
|
+
extension: '.html'
|
288
|
+
|
289
|
+
}))
|
290
|
+
|
291
|
+
.pipe($.plumber({
|
292
|
+
|
293
|
+
errorHandler: handleErrors
|
294
|
+
|
295
|
+
}))
|
296
|
+
|
297
|
+
.pipe($.jade({
|
298
|
+
|
299
|
+
pretty: true,
|
300
|
+
|
301
|
+
basedir: ga2.html.src,
|
302
|
+
|
303
|
+
data: configJson
|
304
|
+
|
305
|
+
}))
|
306
|
+
|
307
|
+
.pipe(gulp.dest(ga2.html.pub));
|
308
|
+
|
309
|
+
});
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
gulp.task('jade:templates', function(){
|
314
|
+
|
315
|
+
return gulp.src(jadePages)
|
316
|
+
|
317
|
+
.pipe($.plumber({
|
318
|
+
|
319
|
+
errorHandler: handleErrors
|
320
|
+
|
321
|
+
}))
|
322
|
+
|
323
|
+
.pipe($.jade({
|
324
|
+
|
325
|
+
pretty: true,
|
326
|
+
|
327
|
+
basedir: ga2.html.src,
|
328
|
+
|
329
|
+
data: configJson
|
330
|
+
|
331
|
+
}))
|
332
|
+
|
333
|
+
.pipe(gulp.dest(ga2.html.pub));
|
334
|
+
|
335
|
+
});
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
gulp.task('html', ['jade:page']);
|
340
|
+
|
341
|
+
gulp.task('html:templates', ['jade:templates']);
|
342
|
+
|
343
|
+
gulp.task('html:json', function(){
|
344
|
+
|
345
|
+
return gulp.src(ga2.html.pub + '_api/*.html')
|
346
|
+
|
347
|
+
.pipe($.htmlToJson())
|
348
|
+
|
349
|
+
.pipe(gulp.dest(ga2.html.pub + '_api/'));
|
350
|
+
|
351
|
+
});
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
var jsonFiles = [
|
356
|
+
|
357
|
+
'head-notifier',
|
358
|
+
|
359
|
+
'ranking-mo',
|
360
|
+
|
361
|
+
'ga-comment_01',
|
362
|
+
|
363
|
+
'ga-comment_02',
|
364
|
+
|
365
|
+
'ga-comment-post_01',
|
366
|
+
|
367
|
+
'ga-comment-post_02',
|
368
|
+
|
369
|
+
'pm-lk_comment-01',
|
370
|
+
|
371
|
+
'pm-lk_comment-02',
|
372
|
+
|
373
|
+
'pm-tw-list'
|
374
|
+
|
375
|
+
];
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
gulp.task('json:merge', function(){
|
380
|
+
|
381
|
+
var filename, i, len, results;
|
382
|
+
|
383
|
+
results = [];
|
384
|
+
|
385
|
+
for(i = 0, len = jsonFiles.length; i < len; i++){
|
386
|
+
|
387
|
+
filename = jsonFiles[i];
|
388
|
+
|
389
|
+
results.push(gulp.src(ga2.html.pub + '_api/' + filename + '*.json')
|
390
|
+
|
391
|
+
.pipe($.extend(filename + '.json'))
|
392
|
+
|
393
|
+
.pipe(gulp.dest(ga2.html.pub + '_api/')));
|
394
|
+
|
395
|
+
}
|
396
|
+
|
397
|
+
return results;
|
398
|
+
|
399
|
+
});
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
gulp.task('json:api', function(){
|
404
|
+
|
405
|
+
return runSequence('html:json', 'json:merge');
|
406
|
+
|
407
|
+
});
|
408
|
+
|
409
|
+
gulp.task('html', function(){
|
410
|
+
|
411
|
+
return runSequence('jade:page', 'json:api');
|
412
|
+
|
413
|
+
});
|
414
|
+
|
415
|
+
gulp.task('html:templates', function(){
|
416
|
+
|
417
|
+
return runSequence('jade:templates', 'json:api');
|
418
|
+
|
419
|
+
});
|
420
|
+
|
421
|
+
|
422
|
+
|
423
|
+
// image
|
424
|
+
|
425
|
+
gulp.task('image:svg', function(){
|
426
|
+
|
427
|
+
return gulp.src(ga2.img.pub + '**/*.svg')
|
428
|
+
|
429
|
+
.pipe($.svgmin())
|
430
|
+
|
431
|
+
.pipe(gulp.dest(ga2.img.pub));
|
432
|
+
|
433
|
+
});
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
// minify
|
438
|
+
|
439
|
+
gulp.task('minify:scripts', function(){
|
440
|
+
|
441
|
+
return gulp.src(ga2.assets + '**/*.js')
|
442
|
+
|
443
|
+
.pipe($.uglify({
|
444
|
+
|
445
|
+
preserveComments: 'some'
|
446
|
+
|
447
|
+
}))
|
448
|
+
|
449
|
+
.pipe(gulp.dest(ga2.assets));
|
450
|
+
|
451
|
+
});
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
gulp.task('minify:styles', function(){
|
456
|
+
|
457
|
+
return gulp.src(ga2.assets + '**/*.css')
|
458
|
+
|
459
|
+
.pipe($.cleanCss())
|
460
|
+
|
461
|
+
.pipe(gulp.dest(ga2.assets));
|
462
|
+
|
463
|
+
});
|
464
|
+
|
465
|
+
gulp.task('minify', ['minify:scripts', 'minify:styles']);
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
// build
|
470
|
+
|
471
|
+
gulp.task('browserify:ga2', function(){
|
472
|
+
|
473
|
+
browserify({
|
474
|
+
|
475
|
+
entries: ['./js/main.js'],
|
476
|
+
|
477
|
+
transform: ['babelify', 'coffeeify', 'browserify-shim'],
|
478
|
+
|
479
|
+
cache: {},
|
480
|
+
|
481
|
+
packageCache: {}
|
482
|
+
|
483
|
+
})
|
484
|
+
|
485
|
+
.bundle()
|
486
|
+
|
487
|
+
.pipe(source('./js/main.js'))
|
488
|
+
|
489
|
+
.pipe(gulp.dest('../public/assets/'));
|
490
|
+
|
491
|
+
});
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
gulp.task('browserify:modules', function(){
|
496
|
+
|
497
|
+
browserify({
|
498
|
+
|
499
|
+
entries: ['./js/ga-modules.js'],
|
500
|
+
|
501
|
+
transform: ['babelify', 'coffeeify', 'browserify-shim'],
|
502
|
+
|
503
|
+
cache: {},
|
504
|
+
|
505
|
+
packageCache: {}
|
506
|
+
|
507
|
+
})
|
508
|
+
|
509
|
+
.bundle()
|
510
|
+
|
511
|
+
.pipe(source('./js/ga-modules.js'))
|
512
|
+
|
513
|
+
.pipe(gulp.dest('../public/assets/'));
|
514
|
+
|
515
|
+
});
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
gulp.task('build:js', ['browserify:ga2', 'browserify:modules', 'scripts:modules']);
|
520
|
+
|
521
|
+
gulp.task('build:sass', ['styles:ga2']);
|
522
|
+
|
523
|
+
gulp.task('build', ['build:sass', 'build:js']);
|
524
|
+
|
525
|
+
|
526
|
+
|
527
|
+
// web server
|
528
|
+
|
529
|
+
gulp.task('server', function(){
|
530
|
+
|
531
|
+
$.connect.server({
|
532
|
+
|
533
|
+
root: ga2.pub,
|
534
|
+
|
535
|
+
port: 8000,
|
536
|
+
|
537
|
+
livereload: true
|
538
|
+
|
539
|
+
});
|
540
|
+
|
541
|
+
});
|
542
|
+
|
543
|
+
|
544
|
+
|
545
|
+
// watch
|
546
|
+
|
547
|
+
gulp.task('watch', function(){
|
548
|
+
|
549
|
+
gulp.watch(ga2.js.src + 'page-modules/*.js', { interval: 750 }, ['scripts:modules']);
|
550
|
+
|
551
|
+
gulp.watch(ga2.css.src + '**/*.{sass,scss}', { interval: 750 }, ['styles:ga2']);
|
552
|
+
|
553
|
+
gulp.watch(jadePages, { interval: 750 }, ['html']);
|
554
|
+
|
555
|
+
gulp.watch(jadeTemplates, { interval: 750 }, ['html:templates']);
|
556
|
+
|
557
|
+
gulp.watch(ga2.html.pub + '_api/*.html', { interval: 750 }, ['json:api']);
|
558
|
+
|
559
|
+
gulp.watch(ga2.pub + '**/*.html', { interval: 750 }, function(e){
|
560
|
+
|
561
|
+
return gulp.src(e.path)
|
562
|
+
|
563
|
+
.pipe($.connect.reload());
|
564
|
+
|
565
|
+
});
|
566
|
+
|
567
|
+
});
|
568
|
+
|
569
|
+
gulp.task('default', ['server', 'watch', 'watchify']);
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
// utils
|
574
|
+
|
575
|
+
var handleErrors = function(){
|
576
|
+
|
577
|
+
var args = Array.prototype.slice.call(arguments);
|
578
|
+
|
579
|
+
$.notify.onError({
|
580
|
+
|
581
|
+
title: 'Task Error',
|
582
|
+
|
583
|
+
message: '<%= error %>'
|
584
|
+
|
585
|
+
}).apply(this, args);
|
586
|
+
|
587
|
+
return this.emit('end');
|
588
|
+
|
589
|
+
};
|
590
|
+
|
591
|
+
|
592
|
+
|
593
|
+
```
|
1
試してみたことを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,10 +34,16 @@
|
|
34
34
|
|
35
35
|
|
36
36
|
|
37
|
-
#やってみたこと
|
37
|
+
#やってみたこと1
|
38
38
|
|
39
39
|
npm uninstall gulp-sass
|
40
40
|
|
41
41
|
npm install gulp-sass --save-dev
|
42
42
|
|
43
43
|
その後も、cssファイルは更新されない
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
#やってみたこと2
|
48
|
+
|
49
|
+
gulpと実行し、そのままの状態で、sassファイルに修正を加えるとcssファイルの更新日が変わることが確認できました。これは正しい手順でしょうか???
|