-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
208 lines (182 loc) · 4.8 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
const gulp = require("gulp"),
path = require('path'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
cssmin = require('gulp-cssmin'),
rename = require("gulp-rename"),
browserSync = require("browser-sync"),
watch = require('gulp-watch'),
del = require('del'),
runSequence = require('run-sequence');
/**
* File Path
*/
const ROOT = __dirname;
const SRC_PATH = path.join(ROOT, './data');
const HTML_SRC_PATH = path.join(SRC_PATH, 'html');
const SCSS_SRC_PATH = path.join(SRC_PATH, 'scss');
const JS_SRC_PATH = path.join(SRC_PATH, 'js');
const IMAGE_SRC_PATH = path.join(SRC_PATH, 'img');
const FILE_SRC_PATH = path.join(SRC_PATH, 'file');
const HTML_SRC_FILES = path.join(HTML_SRC_PATH, './**/*.html');
const HTML_SRC_INDEX_FILE = path.join(SRC_PATH, 'index.html');
const SCSS_SRC_FILES = path.join(SCSS_SRC_PATH, './**/*.scss');
const JS_SRC_FILES = path.join(JS_SRC_PATH, './**/*.js');
const IMAGE_SRC_FILES = path.join(IMAGE_SRC_PATH, './**/*.{jpg,png,gif,ico}');
const FILE_SRC_FILES = path.join(FILE_SRC_PATH, './**/*.pdf');
// public files
const PUBLIC_PATH = path.join(ROOT, './public');
const HTML_PUBLIC_PATH = path.join(PUBLIC_PATH, 'html');
const CSS_PUBLIC_PATH = path.join(PUBLIC_PATH, 'css');
const JS_PUBLIC_PATH = path.join(PUBLIC_PATH, 'js');
const IMAGE_PUBLIC_PATH = path.join(PUBLIC_PATH, 'img');
const FILE_PUBLIC_PATH = path.join(PUBLIC_PATH, 'file');
const HTML_PUBLIC_FILES = path.join(HTML_PUBLIC_PATH, './**/*.html');
const HTML_PUBLIC_INDEX_FILE = path.join(PUBLIC_PATH, 'index.html');
const CSS_PUBLIC_FILES = path.join(CSS_PUBLIC_PATH, './**/*.css');
const IMAGE_PUBLIC_FILES = path.join(IMAGE_PUBLIC_PATH, './**/*.{jpg,png,gif,ico}');
/**
* Clean Task
**/
gulp.task('public.clean', function() {
return del([PUBLIC_PATH + '/*'], { force: true });
});
/**
* HTML Task
**/
gulp.task('html.dist', function () {
return gulp.src(HTML_SRC_FILES).pipe(gulp.dest(HTML_PUBLIC_PATH));
});
gulp.task('html.dist.index', function () {
return gulp.src(HTML_SRC_INDEX_FILE).pipe(gulp.dest(PUBLIC_PATH));
});
/**
* SASS, CSS Task
**/
gulp.task('sass', function() {
return gulp.src(SCSS_SRC_FILES)
.pipe(sass({
outputStyle: 'expanded'
}).on('error', sass.logError))
.pipe(gulp.dest(CSS_PUBLIC_PATH));
});
gulp.task('css.prefixer', function() {
return gulp.src(CSS_PUBLIC_FILES)
.pipe(autoprefixer({
browsers: ['last 2 versions', 'ie 8', 'ios 5', 'android 2.3'],
cascade: false
}))
.pipe(gulp.dest(CSS_PUBLIC_PATH));
});
gulp.task('css.min', function () {
return gulp.src([
CSS_PUBLIC_FILES,
'!' + CSS_PUBLIC_PATH + '**/*min.css'
])
.pipe(cssmin())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(CSS_PUBLIC_PATH));
});
/**
* JavaScript Task
**/
gulp.task('js', function() {
return gulp.src(JS_SRC_FILES)
.pipe(gulp.dest(JS_PUBLIC_PATH));
});
/**
* Image Task
**/
gulp.task('img.dist', function () {
return gulp.src(IMAGE_SRC_FILES).pipe(gulp.dest(IMAGE_PUBLIC_PATH));
});
/**
* Pdf etc Task
**/
gulp.task('file.dist', function () {
return gulp.src(FILE_SRC_FILES).pipe(gulp.dest(FILE_PUBLIC_PATH));
});
/**
* watch Task
**/
gulp.task('watch', function() {
// html
gulp.watch([HTML_SRC_FILES, HTML_SRC_INDEX_FILE], ['build.html']);
// CSS,SASS
gulp.watch([SCSS_SRC_FILES], ['build.css']);
// Image
gulp.watch([IMAGE_SRC_FILES], ['build.image']);
});
/**
* Build Task
**/
gulp.task('build.html', function(callback) {
return runSequence(
'html.dist',
'html.dist.index',
callback
);
});
gulp.task('build.css', function(callback) {
return runSequence(
'sass',
'css.prefixer',
'css.min',
callback
);
});
gulp.task('build.js', function(callback) {
return runSequence(
'js',
callback
);
});
gulp.task('build.image', function(callback) {
return runSequence(
'img.dist',
callback
);
});
gulp.task('build.file', function(callback) {
return runSequence(
'file.dist',
callback
);
});
gulp.task('build.all', function(callback) {
return runSequence(
['build.html', 'build.css', 'build.js', 'build.image', 'build.file'],
callback
);
});
/**
* Browser Sync
**/
gulp.task('browser-sync', function() {
browserSync.init({
files: [
HTML_PUBLIC_INDEX_FILE,
HTML_SRC_INDEX_FILE,
CSS_PUBLIC_FILES,
IMAGE_PUBLIC_FILES
],
server: {
baseDir: PUBLIC_PATH
}
});
browserSync.reload();
});
/**
* Default Task
**/
gulp.task('default', function(callback) {
runSequence(
'public.clean',
'build.all',
'watch',
'browser-sync',
callback
);
});