-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
185 lines (160 loc) · 4.03 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
const gulp = require("gulp"),
path = require('path'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
cssmin = require('gulp-cssmin'),
rename = require('gulp-rename'),
watch = require('gulp-watch'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
plumber = require('gulp-plumber'),
del = require('del'),
runSequence = require('run-sequence'),
browserSync = require("browser-sync"),
exec = require('child_process').execSync;
/**
* File Path
*/
const ROOT = __dirname;
const SRC_PATH = path.join(ROOT, './src');
const PUBLIC_PATH = path.join(ROOT, './public');
const DIST_PATH = path.join(ROOT, './dist');
const DOCS_PATH = path.join(ROOT, './docs');
// HTML
const HTML_SRC_PATH = path.join(SRC_PATH, 'html');
const HTML_FILES = path.join(HTML_SRC_PATH, './**/*.html');
// SASS
const SASS_SRC_PATH = path.join(SRC_PATH, 'scss');
const SASS_FILES = path.join(SASS_SRC_PATH, './**/*.scss');
const CSS_FILES = path.join(PUBLIC_PATH, './**/*.css');
// Fonts
const fontFiles = [ SRC_PATH + '/fonts/**/**' ];
// Image
const IMG_SRC_PATH = path.join(SRC_PATH, 'image');
const IMG_FILES = path.join(IMG_SRC_PATH, './**/*.{jpg,gif,png,ico}');
// Clean Task
gulp.task('clean.release', function() {
return del([CSS_FILES], {force: true});
});
// HTML
gulp.task('html', function() {
return gulp.src([HTML_FILES]).pipe(gulp.dest(PUBLIC_PATH));
});
// Sass, CSS
gulp.task('sass', function() {
return gulp.src([SASS_FILES])
.pipe(sass({
outputStyle: 'expanded'
}).on('error', sass.logError))
.pipe(gulp.dest(PUBLIC_PATH));
});
gulp.task('sass.copy.dist', function() {
return gulp.src([SASS_FILES])
.pipe(gulp.dest(DIST_PATH));
});
gulp.task('css.prefixer', function() {
return gulp.src([CSS_FILES])
.pipe(autoprefixer({
browsers: ['last 2 versions', 'ie 8', 'ios 6', 'android 2.3'],
cascade: false
}))
.pipe(gulp.dest(PUBLIC_PATH));
});
gulp.task('css.min', function() {
return gulp.src([
CSS_FILES,
'!' + PUBLIC_PATH + '/**/*min.css'
])
.pipe(cssmin())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(PUBLIC_PATH));
});
gulp.task('css.copy.docs', function() {
return gulp.src([
PUBLIC_PATH + '/**/*.css'
])
.pipe(gulp.dest(DOCS_PATH));
});
gulp.task('css.copy.dist', function() {
return gulp.src([
PUBLIC_PATH + '/**/*.css'
])
.pipe(gulp.dest(DIST_PATH));
});
// Fonts
gulp.task('font.copy', function() {
return gulp.src(fontFiles)
.pipe(gulp.dest( PUBLIC_PATH + '/font/' ));
});
gulp.task('font.copy.dist', function() {
return gulp.src(fontFiles)
.pipe(gulp.dest( DIST_PATH + '/font/' ));
});
// Image
gulp.task('image', function() {
return gulp.src([IMG_FILES]).pipe(gulp.dest(PUBLIC_PATH + '/image'));
});
// ファイル更新監視
gulp.task('watch', function() {
// HTML
gulp.watch([HTML_FILES], ['html']);
// SCSS
gulp.watch([SASS_FILES], ['build.css']);
});
gulp.task('browser-sync', function() {
browserSync({
server: "./public",
files: ["./public/**"],
port: 8080
});
browserSync.reload();
});
/**
* Build Task
**/
gulp.task('build.ui', function(callback) {
return runSequence(
['html', 'build.css', 'image', 'build.font'],
callback
);
});
gulp.task('build.css', function(callback) {
return runSequence(
'sass',
'css.prefixer',
'css.min',
callback
);
});
gulp.task('build.font', function(callback) {
return runSequence(
'font.copy',
callback
);
});
/**
* Dist Task
**/
gulp.task('dist', function(callback) {
return runSequence(
'build.ui',
'css.copy.dist',
'css.copy.docs',
'sass.copy.dist',
'font.copy.dist',
callback
);
});
/**
* default Task
**/
gulp.task('default', function(callback) {
runSequence(
'build.ui',
'watch',
// 'browser-sync',
callback
);
});