-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
98 lines (88 loc) · 2.8 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
'use strict';
const gulp = require('gulp'),
del = require('del'),
sourcemaps = require('gulp-sourcemaps'),
concat = require('gulp-concat'),
sassLint = require('gulp-sass-lint'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
cssnano = require('gulp-cssnano'),
eslint = require('gulp-eslint'),
babel = require('gulp-babel'),
uglify = require('gulp-uglify'),
browserSync = require('browser-sync').create(),
gulpif = require('gulp-if'),
gulpSequence = require('gulp-sequence'),
rename = require('gulp-rename');
const arg = (argList => {
let arg = {},
a, opt, thisOpt, curOpt;
for (a = 0; a < argList.length; a++) {
thisOpt = argList[a].trim();
opt = thisOpt.replace(/^\-+/, '');
if (opt === thisOpt) {
if (curOpt) arg[curOpt] = opt;
curOpt = null;
} else {
curOpt = opt;
arg[curOpt] = true;
}
}
return arg;
})(process.argv);
gulp.task('clean', () => {
del.sync(['dist/**/*']);
});
gulp.task('copy', () => {
return gulp.src('src/languages/*.klc', { base: 'src/languages/' })
.pipe(gulp.dest('dist/languages'));
});
gulp.task('copy-demo', () => {
return gulp.src('src/demo/*.html', { base: 'src/demo/' })
.pipe(rename('index.html'))
.pipe(gulp.dest('dist/'));
});
gulp.task('build-css', () => {
return gulp.src('src/scss/**/*.scss')
.pipe(gulpif(arg.sourcemap, sourcemaps.init()))
.pipe(sassLint())
.pipe(concat('styles.scss'))
.pipe(sassLint.format())
.pipe(sass())
.pipe(autoprefixer('last 20 versions'))
.pipe(cssnano())
.pipe(gulpif(arg.sourcemap, sourcemaps.write()))
.pipe(gulp.dest('dist/'))
.pipe(browserSync.stream({ match: '**/*.css' }));
});
gulp.task('build-js', () => {
return gulp.src('src/js/**/*.js')
.pipe(gulpif(arg.sourcemap, sourcemaps.init()))
.pipe(concat('main.js'))
.pipe(eslint({ fix: true }))
.pipe(eslint.format())
.pipe(babel({
presets: [
'@babel/env'
]
}))
.pipe(uglify())
.pipe(gulpif(arg.sourcemap, sourcemaps.write()))
.pipe(gulp.dest('dist/'));
});
gulp.task('serve', () => {
browserSync.init({
server: {
baseDir: './dist/',
index: 'index.html'
},
reloadDelay: 50,
reloadDebounce: 250
});
gulp.watch('src/scss/**/*.scss', ['build-css']);
gulp.watch('src/js/**/*.js', ['build-js']).on('change', (e) => {
browserSync.reload();
});
});
gulp.task('develop', gulpSequence('clean', ['copy', 'copy-demo', 'build-css', 'build-js', 'serve']));
gulp.task('build', gulpSequence('clean', ['copy', 'build-css', 'build-js']));