forked from timseverien/taggd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
74 lines (63 loc) · 1.81 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
/* eslint arrow-body-style: 0 */
const browserify = require('browserify');
const babelify = require('babelify');
const buffer = require('vinyl-buffer');
const del = require('del');
const source = require('vinyl-source-stream');
const gulp = require('gulp');
const $ = require('gulp-load-plugins')({
rename: {
'gulp-uglify': 'minifyJs',
'gulp-cssnano': 'minifyCss',
},
});
const DIR_BUILD = 'dist';
const DIR_SOURCE = 'src';
const OPTIONS_BABEL = {
presets: ['es2015', 'es2017'],
plugins: ['transform-runtime'],
};
const OPTIONS_BROWSERIFY = {
standalone: 'Taggd',
};
const paths = {
scripts: {
src: `${DIR_SOURCE}/scripts/**/*.js`,
entry: `${DIR_SOURCE}/scripts/umd.js`,
dest: DIR_BUILD,
},
styles: {
src: `${DIR_SOURCE}/styles/**/*.css`,
dest: DIR_BUILD,
},
};
gulp.task('clean', () => {
return del(DIR_BUILD);
});
gulp.task('build:scripts', () => {
return browserify(OPTIONS_BROWSERIFY)
.transform(babelify, OPTIONS_BABEL)
.require(paths.scripts.entry, { entry: true })
.bundle()
.pipe(source('taggd.js'))
.pipe(buffer())
.pipe(gulp.dest(paths.scripts.dest))
.pipe($.sourcemaps.init({ loadMaps: true }))
.pipe($.minifyJs())
.pipe($.rename('taggd.min.js'))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest(paths.scripts.dest));
});
gulp.task('build:styles', () => {
return gulp.src(paths.styles.src)
.pipe($.sourcemaps.init())
.pipe($.minifyCss())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest(paths.styles.dest));
});
gulp.task('build', gulp.series('clean', gulp.parallel('build:scripts', 'build:styles')));
gulp.task('default', gulp.series('build'));
gulp.task('watch', gulp.series('build', () => {
gulp.watch(paths.scripts.src, gulp.series('build:scripts'));
gulp.watch(paths.styles.src, gulp.series('build:styles'));
}));