-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
64 lines (58 loc) · 1.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
const gulp = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const browserify = require('browserify');
const babel = require('babelify');
const less = require('gulp-less');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
const sourceFile = 'index';
const bundleName = 'widget';
const paths = {
scripts: {
src: `./widget/src/scripts/${sourceFile}.js`,
bundle: './widget/bundle',
watch: './widget/src/**/*.js',
},
styles: {
src: `./widget/src/styles/${sourceFile}.less`,
bundle: './widget/bundle',
watch: './widget/src/**/*.less',
},
};
// eslint-disable-next-line
gulp.task('build:scripts', () => {
return browserify(paths.scripts.src, { debug: true })
.transform(babel, { presets: ['env'] })
.bundle()
.on('error', function errorHandler(err) {
// eslint-disable-next-line
console.error(err);
this.emit('end');
})
.pipe(source(`${bundleName}.js`))
.pipe(buffer())
.pipe(uglify().on('error',console.log))
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(paths.scripts.bundle));
});
// eslint-disable-next-line
gulp.task('build:styles', () => {
return gulp.src(paths.styles.src)
.pipe(sourcemaps.init())
.pipe(less())
.pipe(rename({ basename: bundleName }))
.pipe(sourcemaps.write())
.pipe(gulp.dest(paths.styles.bundle));
});
gulp.task('watch:scripts', () => {
gulp.watch(paths.scripts.watch, ['build:scripts']);
});
gulp.task('watch:styles', () => {
gulp.watch(paths.scripts.watch, ['build:styles']);
});
gulp.task('build', ['build:scripts', 'build:styles']);
gulp.task('watch', ['watch:scripts', 'watch:styles']);
gulp.task('default', ['build']);