-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
99 lines (89 loc) · 2.5 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
const gulp = require("gulp");
const browserify = require("browserify");
const source = require('vinyl-source-stream');
const watchify = require("watchify");
const tsify = require("tsify");
const gutil = require("gulp-util");
const sourcemaps = require('gulp-sourcemaps');
const buffer = require('vinyl-buffer');
const stylus = require('gulp-stylus');
const minify = require('gulp-minify');
const imagemin = require('gulp-imagemin');
const csso = require('gulp-csso');
/*
** Typescript Part
*/
var watchedBrowserify = watchify(browserify({
basedir: '.',
debug: true,
entries: ['src/ts/main.ts'],
cache: {},
packageCache: {}
}).plugin(tsify));
function bundle() {
return watchedBrowserify
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest("dist/js"));
}
gulp.task('default', ['js'], function () {
return browserify({
basedir: '.',
debug: true,
entries: ['src/ts/main.ts'],
cache: {},
packageCache: {}
})
.plugin(tsify)
.transform('babelify', {
presets: ['es2015'],
extensions: ['.ts']
})
.bundle()
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('dist/js'));
});
// Task build js
gulp.task("js", bundle);
watchedBrowserify.on("update", bundle);
watchedBrowserify.on("log", gutil.log);
/*
** Style Part
*/
gulp.task('css', function () {
return gulp.src( './src/stylus/style.styl' )
.pipe(stylus())
.pipe(gulp.dest( './dist/css' ));
});
gulp.task('minify', ['css'] , function () {
return gulp.src( './dist/css/style.css' )
.pipe(csso())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('./dist/css'));
});
gulp.task('imagemini', () =>
gulp.src( './src/images/**/*' )
.pipe(imagemin([
imagemin.gifsicle({interlaced: true}),
imagemin.jpegtran({progressive: true}),
imagemin.optipng({optimizationLevel: 5}),
imagemin.svgo({
plugins: [
{removeViewBox: true},
{cleanupIDs: false}
]
})
]))
.pipe(gulp.dest( './dist/images/' ))
);
// Task build css/img
gulp.task('build', ['css', 'imagemini'] );
// Si watch => Task build
gulp.task('watch', function () {
gulp.watch( './src/stylus/**/*.styl', ['build']);
});