-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
117 lines (104 loc) · 2.65 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
var gulp = require('gulp');
var plumber = require('gulp-plumber');
var runSequence = require('run-sequence');
var autoprefixer = require('gulp-autoprefixer');
/* Server
****************************** */
var browser = require('browser-sync');
gulp.task('server', function() {
browser({
server: {
baseDir: './app/public/'
}
});
});
/* Clean
****************************** */
var del = require('del');
gulp.task('clean', function() {
del(['./app/public/']);
});
/* Sass
****************************** */
var sass = require('gulp-sass');
gulp.task('sass', function() {
gulp.src(['./app/source/scss/**/*.scss', '!./app/source/scss/**/_*.scss'])
.pipe(plumber())
.pipe(sass())
.pipe(sass({outputStyle: 'expanded'}))
.pipe(autoprefixer({
browsers: ['last 2 versions', 'ie >= 9', 'Android >= 4', 'ios_saf >= 8', 'safari >= 8'],
cascade: false
}))
.pipe(gulp.dest('./app/public/css'))
.pipe(browser.reload({stream:true}))
});
/* Combine MediaQuery
****************************** */
var cmq = require('gulp-combine-media-queries');
gulp.task('cmq', function() {
gulp.src('./app/public/css/*.css')
.pipe(plumber())
.pipe(cmq({
log: true
}))
.pipe(gulp.dest('./app/public/css'));
});
/* Ejs
****************************** */
var ejs = require('gulp-ejs');
gulp.task('ejs', function() {
gulp.src(['./app/source/ejs/**/*.ejs','!./app/source/ejs/**/_*.ejs'])
.pipe(plumber())
.pipe(ejs())
.pipe(gulp.dest('./app/public'))
.pipe(browser.reload({stream:true}))
});
// 複製タスクに関わるパス
var copyPaths = [
{
from: './app/source/images/**/*',
to: './app/public/images'
}, {
from: './app/source/fonts/**/*',
to: './app/public/fonts'
}, {
from: './app/source/js/**/*',
to: './app/public/js'
}, {
from: './app/source/plugins/**/*',
to: './app/public/plugins'
}
];
/* Copy
****************************** */
gulp.task('copy', function() {
Object.keys(copyPaths).forEach(function (key) {
gulp.src(copyPaths[key].from).pipe(gulp.dest(copyPaths[key].to));
});
});
/* Watch
****************************** */
var watch = require('gulp-watch');
gulp.task('watch', function() {
watch(['./app/source/scss/**/*.scss'], function(event){
gulp.start('sass');
});
watch(['./app/source/ejs/**/*.ejs'], function(event){
gulp.start('ejs');
});
// 複製タスクはループを回す
for(var i=0; i<copyPaths.length; i++){
watch(copyPaths[i].from, function(event){
gulp.start('copy');
});
}
});
gulp.task('build', ['clean'], function (callback) {
return runSequence(['ejs', 'sass', 'copy'], callback);
});
/* Default
****************************** */
gulp.task('default', function() {
return runSequence(['server'],['watch']);
});