This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
127 lines (108 loc) · 3.42 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
// 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 imageOptim = require('gulp-imageoptim');
var reload = browserSync.reload;
// Include paths file.
var paths = require('./paths');
// stylus - Compiles stylus file.
gulp.task('stylus', function() {
var stylus_options = {
use : [
rupture()
]
}
return gulp.src(paths.stylusMain)
.pipe(stylus(stylus_options))
.pipe(gulp.dest(paths.cssFolder));
});
// postcss - Run postcss processors.
gulp.task('postcss', function() {
var processors = [
rucksack,
lost,
autoprefixer ({
browsers:['last 2 version']
})
];
return gulp.src(paths.cssMain)
.pipe(postcss(processors))
.pipe(gulp.dest(paths.cssFolder))
});
// mincss - Minify app.css file.
gulp.task ('mincss', function() {
return gulp.src(paths.cssMain)
.pipe(cssmin())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(paths.cssFolder));
});
// Styles:watch Task - Reloads html files
gulp.task('styles:watch', function(){
return gulp.src(paths.stylusFiles)
.pipe(reload({ stream:true }));
});
// styles - Run styles tasks.
gulp.task('styles', gulp.series('stylus', 'postcss', 'mincss', 'styles:watch'));
// concatjs - Concatenates *.js files.
gulp.task ('concatjs', function() {
return gulp.src([paths.jsVendor, paths.jsModules])
.pipe(babel()) // En teoría tu lo tenías antes del concat
.pipe(concat('main.js'))
.pipe(gulp.dest(paths.jsFolder));
});
// uglify - Compress *.js files.
gulp.task('uglify', function() {
return gulp.src(paths.jsMain)
.pipe(uglify())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(paths.jsFolder));
});
// Scripts:watch Task - Reloads html files
gulp.task('scripts:watch', function(){
return gulp.src(paths.jsMain)
.pipe(reload({ stream:true }));
});
// scripts - Run scripts tasks.
gulp.task('scripts', gulp.series('concatjs', 'uglify', 'scripts:watch'));
// images - Optimize images.
gulp.task('imageOptim', function() {
return gulp.src(paths.imgFiles)
.pipe(imageOptim.optimize())
.pipe(gulp.dest(paths.imgFolder));
});
// Images - Run images tasks.
gulp.task('images', gulp.series('imageOptim'));
// server task - Run server
gulp.task('server', function() {
browserSync.init({
server: paths.siteDir,
port: 3000,
browser: "google chrome"
});
gulp.watch(paths.htmlFiles).on('change', reload); // Watch html
gulp.watch(paths.stylusFiles, gulp.series('styles')); // Watch styles
gulp.watch(paths.jsModules, gulp.series('scripts')); // Watch scripts
gulp.watch(paths.jsVendor, gulp.series('scripts')); // Watch scripts
});
// build - Builds assets
gulp.task('build', gulp.series('styles', 'scripts'));
// Develop Task
gulp.task('develop', gulp.series('build', 'server'));
// Default Task
gulp.task('default', gulp.series('develop'));