-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
executable file
·81 lines (69 loc) · 1.93 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
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var replace = require('gulp-replace');
var uglifycss = require('gulp-uglifycss');
var fs = require('fs');
var runSequence = require('run-sequence');
var del = require('del');
const babel = require('gulp-babel');
// var pump = require('pump');
// gulp.task('uglify-error-debugging', function (cb) {
// pump([
// gulp.src('./dist/*.js'),
// uglify(),
// gulp.dest('./dist/')
// ], cb);
// });
// gulp.task('transcompile', function() {
// return gulp.src('./dist/bundle.js')
// .pipe(babel({
// presets: ['env']
// }))
// .pipe(gulp.dest('./dist/'));
// });
gulp.task('cleanBuild', function () {
return del(['dist/**/*']);
});
gulp.task('minifyCss', function(callback) {
return gulp.src('./src/*.css')
.pipe(concat('bundle.min.css'))
.pipe(uglifycss())
.pipe(gulp.dest('./dist/'))
});
gulp.task('concatJs', function() {
return gulp.src([
'./src/*.js',
])
.pipe(concat('bundle.js'))
.pipe(babel({
presets: ['env']
}))
.pipe(gulp.dest('./dist/'))
});
gulp.task('injectCss', function() {
return gulp.src('./dist/bundle.js')
.pipe(replace(/@import "main.css"/, function(s) {
var style = fs.readFileSync('./dist/bundle.min.css', 'utf8');
return style;
}))
.pipe(gulp.dest('./dist/'));
});
gulp.task('uglifyJs', function() {
return gulp.src('./dist/*.js')
.pipe(concat('bundle.min.js'))
.pipe(uglify())
.pipe(gulp.dest('./dist/'));
});
gulp.task('moveHtmlFile', function() {
return gulp.src('./src/*.html')
.pipe(replace(/index.js/, 'bundle.min.js'))
.pipe(gulp.dest('./dist/'));
});
gulp.task('moveAssets', function() {
return gulp.src('./src/assets/*')
.pipe(gulp.dest('./dist/assets/'));
});
gulp.task('bundle', function() {
runSequence('cleanBuild', 'minifyCss', 'concatJs', 'injectCss', 'uglifyJs', 'moveHtmlFile', 'moveAssets');
});