-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
137 lines (119 loc) · 3.32 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
// Dependencies
var gulp = require('gulp');
var stylus = require('gulp-stylus');
var postcss = require('gulp-postcss');
var cssmin = require('gulp-cssmin');
var imagemin = require('gulp-imagemin');
var rename = require('gulp-rename');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var babel = require('gulp-babel');
var rupture = require('rupture');
var lost = require('lost');
var rucksack = require('rucksack-css');
var autoprefixer = require('autoprefixer');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
// Paths
var paths = {
html: './**/*.html',
img: './img/',
css: './css/',
js: './js/',
images: './img/**/*.{JPG,jpg,png,gif}',
styles: './css/stylus/styles.styl',
stylus: './css/stylus/**/*.styl',
scripts: [
'./js/vendor/*.js',
'./js/modules/*.js'
]
};
// server task - Run server
gulp.task('server', function() {
browserSync.init({
server: {
baseDir: "./"
},
port: 3000,
notify: false,
browser: "google chrome"
});
gulp.watch(paths.html).on('change', reload);
gulp.watch(paths.stylus, gulp.series('styles'));
gulp.watch(paths.scripts, gulp.series('scripts'));
});
// Stylus Task - Compiles stylus file
gulp.task('stylus', function() {
var stylus_options = {
use : [
rupture()
]
}
return gulp.src(paths.styles)
.pipe(stylus(stylus_options))
.pipe(gulp.dest(paths.css));
});
// Postcss Task - Run postcss processors
gulp.task('postcss', function() {
var processors = [
rucksack,
lost,
autoprefixer ({
browsers:['last 2 version']
})
];
return gulp.src(paths.css + 'styles.css')
.pipe(postcss(processors))
.pipe(gulp.dest(paths.css))
});
// Mincss - Minify style.css file
gulp.task ('mincss', function() {
return gulp.src(paths.css + 'styles.css')
.pipe(cssmin())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(paths.css));
});
// Concatjs Task - Concatenates *.js files
gulp.task ('concatjs', function() {
return gulp.src(paths.scripts)
.pipe(babel())
.pipe(concat('main.js'))
.pipe(gulp.dest(paths.js));
});
// Uglify Task - Compress *.js files
gulp.task('uglify', function() {
return gulp.src(paths.js + 'main.js')
.pipe(uglify())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(paths.js));
});
// Styles:watch Task - Reloads html files
gulp.task('styles:watch', function(){
return gulp.src(paths.styles)
.pipe(reload({ stream:true }));
});
// Scripts:watch Task - Reloads html files
gulp.task('scripts:watch', function(){
return gulp.src(paths.scripts)
.pipe(reload({ stream:true }));
});
// Optimize images
gulp.task('images', function() {
return gulp.src(paths.images)
.pipe(imagemin())
.pipe(gulp.dest(paths.img));
});
// Styles Task
gulp.task('styles', gulp.series('stylus', 'postcss', 'mincss', 'styles:watch'));
// Scripts Task
gulp.task('scripts', gulp.series('concatjs', 'uglify', 'scripts:watch'));
// Build Task
gulp.task('build', gulp.parallel('styles', 'scripts'));
// Develop Task
gulp.task('develop', gulp.series('build', 'server'));
// Production Task
gulp.task('production', gulp.series('build', 'images', 'server'));