-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
56 lines (50 loc) · 1.38 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
const gulp = require('gulp');
const dartSass = require('sass');
const sass = require('gulp-sass')(dartSass);
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const terser = require('gulp-terser');
const tsify = require('tsify');
const sourcemaps = require('gulp-sourcemaps');
const buffer = require('vinyl-buffer');
// build scss
const buildScss = () => {
return gulp
.src('src/scss/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('dist/css'));
};
// build typescript
const buildTs = () => {
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(terser())
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest('dist/js'));
};
// task to build scss
gulp.task('build-scss', buildScss);
// task to build typescript
gulp.task('build-ts', buildTs);
// defult task
gulp.task('default', gulp.parallel(buildScss, buildTs));
// watch for change
gulp.task('watch', () => {
gulp.watch(['src'], gulp.parallel(buildScss, buildTs));
});