-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
100 lines (100 loc) · 3.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
'use strict';
//global variable
var sources = require('./package.json'),
gulp = require('gulp'),
browserSync = require('browser-sync').create(),
header = require('gulp-header'),
sourcemaps = require('gulp-sourcemaps'),
banner = [
'/**',
' * <%= sources.name %> - <%= sources.description %>',
' * @author <%= sources.author.name %>',
' * @version v<%= sources.version %>',
' * @link <%= sources.author.homepage %>',
' * @license <%= sources.license %>',
' */',
''
].join('\n');
var browser_support = [
'last 2 versions',
'> 5%',
'Firefox ESR',
"ie >= 10",
"ie_mob >= 10",
"ff >= 30",
"chrome >= 34",
"safari >= 7",
"opera >= 23",
"ios >= 7",
"android >= 4.4",
"bb >= 10"
],
date = new Date().toISOString().slice(0,10);
//css-task variable
var sass = require('gulp-sass'),
cssnano = require('gulp-cssnano'),
autoprefixer = require('gulp-autoprefixer'),
//js-task variable
concat = require('gulp-concat'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
//image-task variable
//staging & delivery variable
copy = require('gulp-copy'),
zip = require('gulp-zip');
// css task
gulp.task('sass', function() {
return gulp.src("./src/sass/**/*.sass")
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'compressed', errLogToConsole: true}).on('error', sass.logError))
.pipe(concat(sources.name + '.min.css'))
.pipe(cssnano({autoprefixer: {browsers: browser_support, add: true} }))
.pipe(sourcemaps.write('../maps'))
.pipe(header(banner, {sources : sources}))
.pipe(gulp.dest("./src/css/"))
.pipe(browserSync.stream())
});
// javascript task
gulp.task('javascript', function() {
return gulp.src('./src/js/**/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'))
.pipe(sourcemaps.init())
.pipe(concat(sources.name + '.min.js'))
.pipe(uglify())
.pipe(sourcemaps.write('../maps'))
.pipe(header(banner, {sources : sources}))
.pipe(gulp.dest('./src/app/'))
.pipe(browserSync.stream())
});
// html task
gulp.task('html', function() {
return gulp.src('./src/*.html')
.pipe(gulp.dest('./src'))
.pipe(browserSync.stream())
});
// static server & task watch
gulp.task('default', function() {
browserSync.init({
server: "./src"
});
gulp.watch('src/sass/**/*.sass', function (event) {
console.log(event);
gulp.start('sass');
});
gulp.watch('src/js/**/*.js', function (event) {
console.log(event);
gulp.start('javascript');
});
gulp.watch('src/**/*.html', function (event) {
console.log(event);
gulp.start('html').on('change', browserSync.reload);
});
});
// delivery & compress ( integrated with web & apps )
gulp.task('dist', function(){
return gulp.src('./src/**/*')
.pipe(zip( 'prod_'+ sources.name + '_' + date +'.zip'))
.pipe(gulp.dest('./dist'))
});