This repository has been archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
88 lines (80 loc) · 2.41 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
const gulp = require('gulp');
const runSequence = require('run-sequence');
const gulpIf = require('gulp-if');
const rename = require('gulp-rename');
const babel = require('gulp-babel');
const plumber = require('gulp-plumber');
const uglify = require('gulp-uglify');
const bs = require('browser-sync').create();
const stylus = require('gulp-stylus');
const sourcemaps = require('gulp-sourcemaps');
const autoprefixer = require('gulp-autoprefixer');
const postcss = require('gulp-postcss');
const flexfixes = require('postcss-flexbugs-fixes');
const nano = require('gulp-cssnano');
const isDebug = process.env.NODE_ENV !== 'production';
const { PORT, OPEN, TUNNEL } = process.env;
const browsers = require('./package.json')['browsers'];
gulp.task('default', () => runSequence('copy', 'styles', 'scripts', 'server', 'watch'));
gulp.task('styles', () =>
gulp
.src('src/*.styl')
.pipe(plumber())
.pipe(gulpIf(isDebug, sourcemaps.init()))
.pipe(stylus())
.pipe(
autoprefixer(
'Android >= ' + browsers.android,
'Chrome >= ' + browsers.chrome,
'Firefox >= ' + browsers.firefox,
'Explorer >= ' + browsers.ie,
'iOS >= ' + browsers.ios,
'Opera >= ' + browsers.opera,
'Safari >= ' + browsers.safari
)
)
.pipe(postcss([flexfixes()]))
.pipe(nano({ zindex: false, autoprefixer: false }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulpIf(isDebug, sourcemaps.write()))
.pipe(gulp.dest('dist'))
);
gulp.task('scripts', () => {
gulp
.src('src/*.js')
.pipe(plumber())
.pipe(babel({ presets: ['env'] }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulpIf(!isDebug, uglify()))
.pipe(gulp.dest('dist'));
});
gulp.task('server', () =>
bs.init({
watchOptions: {
ignored: 'src/**/*'
},
files: ['dist/**/*'],
open: !!OPEN,
reloadOnRestart: true,
port: PORT || 3000,
snippetOptions: {
rule: {
match: /<\/body>/i
}
},
server: {
baseDir: ['src', 'dist'],
directory: false
},
tunnel: !!TUNNEL
})
);
gulp.task('copy', () => {
gulp.src(['src/**/*.*', '!app/*.js', '!app/*.styl']).pipe(gulp.dest('dist'));
});
gulp.task('watch', () => {
gulp.watch('src/*.html', () => runSequence('copy'));
gulp.watch('src/*.styl', () => runSequence('styles'));
gulp.watch('src/*.js', () => runSequence('scripts'));
});
gulp.task('build', () => runSequence('styles', 'scripts'));