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* zeynepjs v<%= version %>\n* A light-weight multi-level jQuery side menu plugin.\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(rename({ prefix: 'jquery.' }))
|
43 | .pipe(gulp.dest(paths.dist))
|
44 | .pipe(uglify())
|
45 | .pipe(
|
46 | header(
|
47 | tpl,
|
48 | {
|
49 | version: pkg.version,
|
50 | author: pkg.author
|
51 | }
|
52 | )
|
53 | )
|
54 | .pipe(rename({ suffix: '.min' }))
|
55 | .pipe(sourcemaps.write('.'))
|
56 | .pipe(gulp.dest(paths.dist))
|
57 | .on('end', function () {
|
58 | console.log(chalk.green('Build process has been completed successfully.'));
|
59 | });
|
60 | }));
|
61 |
|
62 |
|
63 | gulp.task(
|
64 | 'default',
|
65 | gulp.series(
|
66 | 'clean',
|
67 | 'build',
|
68 | 'watch'
|
69 | )
|
70 | );
|