-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathgulpfile.babel.js
114 lines (94 loc) · 2.5 KB
/
gulpfile.babel.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
import gulp from 'gulp';
import browserify from 'browserify';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import babelify from 'babelify';
import uglify from 'gulp-uglify';
import rimraf from 'rimraf';
import sourcemaps from 'gulp-sourcemaps';
import cleancss from 'gulp-clean-css';
import imagemin from 'gulp-imagemin';
import pngquant from 'imagemin-pngquant';
import runSequence from 'run-sequence';
import ghPages from 'gulp-gh-pages';
import concatCss from 'gulp-concat-css';
const paths = {
bundle: 'app.js',
entry: 'src/js/Index.js',
srcCss: 'src/styles/*.css',
srcImg: 'src/images/**',
srcLint: ['src/**/*.js', 'test/**/*.js'],
distCss: 'dist/css',
distJs: 'dist/js',
distImg: 'dist/img'
};
gulp.task('clean', cb => {
rimraf('dist', cb);
});
gulp.task('browserify', () => {
browserify(paths.entry, {debug: false})
.transform(babelify)
.bundle()
.pipe(source(paths.bundle))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest(paths.distJs));
});
gulp.task('browserify_debug', () => {
browserify(paths.entry, {debug: true})
.transform(babelify)
.bundle()
.pipe(source(paths.bundle))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.distJs));
});
gulp.task('styles', () => {
gulp.src(paths.srcCss)
.pipe(concatCss("main.css"))
.pipe(cleancss({advanced: false}))
.pipe(gulp.dest(paths.distCss))
});
gulp.task('images', () => {
gulp.src(paths.srcImg)
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest(paths.distImg));
});
gulp.task('watchTask', () => {
gulp.watch(paths.srcCss, ['styles']);
});
gulp.task('build', cb => {
process.env.NODE_ENV = 'production';
runSequence('clean', ['browserify', 'styles', 'images', 'copyAssets'], cb);
});
gulp.task('source', cb=> {
process.env.NODE_ENV = 'debug';
runSequence('clean', ['browserify_debug', 'styles', 'images', 'copyAssets'], cb);
});
gulp.task('copyAssets', ()=> {
gulp.src([
'assets/js/*'
]).pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest('dist/js'));
gulp.src([
'assets/css/*'
]).pipe(cleancss({advanced: false}))
.pipe(gulp.dest('dist/css'));
gulp.src([
'favicon.ico'
]).pipe(gulp.dest('dist'));
gulp.src([
'src/index.html'
]).pipe(gulp.dest('dist'));
});
gulp.task('deploy', () => {
gulp.src('dist/**/**')
.pipe(ghPages());
});