1 | const chalk = require('chalk')
|
2 | const gulp = require('gulp')
|
3 | const rename = require('gulp-rename')
|
4 | const uglify = require('gulp-uglify')
|
5 | const header = require('gulp-header')
|
6 | const del = require('del')
|
7 | const pkg = require('./package.json')
|
8 |
|
9 | const tpl = '/*!\n* theroomjs v<%= version %>\n* A vanilla javascript plugin that allows you to outline dom elements like web inspectors.\n* Works with Chrome, Firefox, Safari, Internet Explorer and Edge\n*\n* Author: <%= author %>\n*/\n'
|
10 |
|
11 |
|
12 | const paths = {
|
13 | srcFile: './src/*.js',
|
14 | dist: './dist/'
|
15 | }
|
16 |
|
17 |
|
18 | gulp.task('clean', function () {
|
19 | return del(paths.dist)
|
20 | })
|
21 |
|
22 |
|
23 | gulp.task('watch', function () {
|
24 | return gulp.watch([paths.srcFile], gulp.series('build'))
|
25 | })
|
26 |
|
27 |
|
28 | gulp.task('build', gulp.series('clean', function () {
|
29 | const sourcemaps = require('gulp-sourcemaps')
|
30 |
|
31 | return gulp.src(paths.srcFile)
|
32 | .pipe(sourcemaps.init())
|
33 | .pipe(
|
34 | header(
|
35 | tpl,
|
36 | {
|
37 | version: pkg.version,
|
38 | author: pkg.author
|
39 | }
|
40 | )
|
41 | )
|
42 | .pipe(gulp.dest(paths.dist))
|
43 | .pipe(uglify())
|
44 | .pipe(
|
45 | header(
|
46 | tpl,
|
47 | {
|
48 | version: pkg.version,
|
49 | author: pkg.author
|
50 | }
|
51 | )
|
52 | )
|
53 | .pipe(rename({ suffix: '.min' }))
|
54 | .pipe(sourcemaps.write('.'))
|
55 | .pipe(gulp.dest(paths.dist))
|
56 | .on('end', function () {
|
57 | console.log(chalk.green('Build process has been completed successfully.'))
|
58 | })
|
59 | }))
|
60 |
|
61 |
|
62 | gulp.task(
|
63 | 'default',
|
64 | gulp.series(
|
65 | 'clean',
|
66 | 'build',
|
67 | 'watch'
|
68 | )
|
69 | )
|