This repository has been archived by the owner on Nov 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
324 lines (255 loc) · 7.4 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
// plugin
var gulp = require('gulp')
// server + live-reload
connect = require('gulp-connect'),
livereload = require('gulp-livereload'),
// html template
extender = require('gulp-html-extend')
// image minify
imagemin = require('gulp-imagemin'),
// task run sequancial
runSequence = require('run-sequence'),
// clean before running
clean = require('del'),
// styling
sass = require('gulp-sass'),
// for cross browsing
autoprefixer = require('gulp-autoprefixer'),
// source tracking
sourcemaps = require('gulp-sourcemaps'),
// comment remove
removeHtmlComment = require('gulp-remove-html-comments'),
// get node_modules to build
npmDist = require('gulp-npm-dist'),
// change path name
rename = require('gulp-rename'),
// gulp-gh-pages
publish = require('gulp-gh-pages'),
// image inliner(for slow network)
base64 = require('gulp-base64'),
imagemin = require('gulp-imagemin')
;
// 환경설정
var path = {
source : {
root : 'source',
style : 'source/style',
js : 'source/js',
template : 'source',
image : 'source/image',
conf : 'source/conf',
html : 'source/html'
},
deploy : 'deploy'
};
// 도움말
gulp.task('help',function () {
var comment = `
eosys.io 사이트를 static하게 만들어냅니다.
# 환경설정
> npm install gulp -g
전역으로 gulp 설치가 완료되고 나면 사전 정의된 각종 플러그인을 설치합니다.
> npm install --save
설치가 마무리되면 아래처럼 명령어를 실행합니다.
명령어는 두가지 입니다.
# 실행
로컬에서 실행해볼떄
> gulp local
배포용
> gulp deploy
자세한 사항은 readme를 참조하세요.
`;
console.log(comment);
});
// --------------------------------------------------------------------------------
// task running 설정
// --------------------------------------------------------------------------------
// 로컬 서버 설정 :: host 설정 해주지 않으면 외부에서 보이질 않는구나.
gulp.task('connect', function() {
connect.server({
root: path.deploy,
port : 7080,
livereload: true,
directory:true,
host:'0.0.0.0'
});
});
// 파일 변경 감지 :: local
gulp.task('watch', function(callback) {
livereload.listen();
gulp.watch(path.source.js+'/*.js',['copy:js'],callback);
gulp.watch(path.source.style+'/*.{scss,sass,css}',['convert:sass:sourcemap'],callback);
// 탬플릿은 세밀하게 지정해줘야 될지도...
gulp.watch([
path.source.template+'/**/*.html',
path.source.html+'/**/*.html',
], ['html'],callback);
// 이미지 수정처리
gulp.watch(path.source.root+'/**/*.{png,jpg,gif}', ['copy:image'],callback);
});
// 빌드 전 청소
gulp.task('clean',function () {
return clean(path.deploy);
});
// scss 변환 :: local
gulp.task('convert:sass:sourcemap', function () {
return gulp.src(path.source.style + '/**/style.scss')
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'expanded'
}))
.on('error', function (err) {
console.log(err.toString());
this.emit('end');
})
.pipe(autoprefixer({
browsers: ['last 2 versions', 'ie 11'],
expand: true,
flatten: true
}))
.pipe(base64({
maxImageSize: 120*1024 // bytes,
}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(path.deploy + '/css'))
.pipe(livereload());
});
// scss 변환 :: deploy, sass > hack
gulp.task('convert:sass', function () {
return gulp.src(path.source.style + '/**/style.scss')
.pipe(sass({
outputStyle: 'compressed'
}))
.pipe(autoprefixer({
browsers: ['last 2 versions', 'ie 10', 'ie 11'],
expand: true,
flatten: false
}))
.pipe(base64({
maxImageSize: 120*1024 // bytes,
}))
.pipe(gulp.dest(path.deploy + '/css'))
.pipe(livereload());
});
// js 파일 :: local, 복사
gulp.task('copy:js',function () {
return gulp.src(path.source.js + '/*.js')
.pipe(gulp.dest(path.deploy + '/js'))
.pipe(livereload());
});
// jquery include
npmDistExcludeJS = [
'*.map',
'src/**/*',
'examples/**/*',
'example/**/*',
'demo/**/*',
'spec/**/*',
'docs/**/*',
'tests/**/*',
'test/**/*',
'Gruntfile.js',
'gulpfile.js',
'package.json',
'package-lock.json',
'bower.json',
'composer.json',
'yarn.lock',
'webpack.config.js',
'README',
'LICENSE',
'CHANGELOG',
'*.yml',
'*.md',
'*.coffee',
'*.ts',
'*.scss',
'*.less',
'core.js',
'slim',
'assets',
// '*.css',
'*.gif',
'component.json',
'slick.jquery.json',
'*.rb',
'*.markdown',
'*.html',
'MakeFile',
'*.eot',
'*.ttf',
'*.woff',
'*.svg',
'*.png',
'slick',
'fonts'
];
gulp.task('copy:node_modules',function () {
return gulp.src(
npmDist({
copyUnminified : false,
slimexcludes : npmDistExcludeJS // only import jquery
}),
{base : './node_modules'}
)
.pipe(rename(function(path) {
path.dirname = '';
}))
.pipe(gulp.dest(path.deploy + '/js'))
.pipe(livereload());
});
// js 파일 :: deploy, concat > copy
gulp.task('copy:js:concat:minify',function () {
return;
});
// conference file copy :: local, deploy 공통
gulp.task('copy:conf',function () {
return gulp.src(path.source.conf + '/*')
.pipe(gulp.dest(path.deploy))
.pipe(livereload());
});
// image :: local, copy
gulp.task('copy:image', function () {
return gulp.src(path.source.image + '/*.{jpg,png,gif,svg}')
.pipe(gulp.dest(path.deploy + '/image'))
.pipe(livereload());
});
gulp.task('imagemin',function () {
return gulp.src(path.source.image + '/*.{jpg,png,gif,svg}')
.pipe(imagemin({
interlaced: true,
progressive: true,
optimizationLevel: 5,
verbose:true
}))
.pipe(gulp.dest(path.source.image));
});
// html 처리
gulp.task('html',function () {
return gulp.src(path.source.html + '/*.html')
.pipe(extender({
annotations: false,
verbose: false
})) // default options
.pipe(removeHtmlComment())
.pipe(gulp.dest(path.deploy))
.pipe(livereload());
});
// 배포
gulp.task('release', function () {
return gulp.src(path.deploy + '/**/*')
.pipe(publish({
force : true,
message : 'Polaris.io :: 깃허브 페이지에 반영됨. Published to Github pages'
}))
});
// --------------------------------------------------------------------------------
// pipe running
// --------------------------------------------------------------------------------
gulp.task('default', ['help']);
gulp.task('local', function () {
runSequence('clean','copy:image','convert:sass:sourcemap','copy:conf','html',['copy:js','copy:node_modules'],['connect','watch']);
});
gulp.task('deploy',function () {
runSequence('clean','copy:image','convert:sass','copy:conf','html',['copy:js','copy:node_modules'],'release');
});