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 sourcemaps = require('gulp-sourcemaps')
|
8 | const pkg = require('./package.json')
|
9 |
|
10 | const tpl = `
|
11 | /*!
|
12 | * <%= name %> v<%= version %>
|
13 | * A light-weight multi-level jQuery side menu plugin.
|
14 | * It's fully customizable and is compatible with modern browsers such as Google Chrome, Mozilla Firefox, Safari, Edge and Internet Explorer
|
15 | * <%= license %> License
|
16 | * by <%= author %>
|
17 | */
|
18 | `.trimStart()
|
19 |
|
20 | const paths = {
|
21 | srcJavascript: './src/*.js',
|
22 | srcCss: './src/*.css',
|
23 | dist: './dist/'
|
24 | }
|
25 |
|
26 |
|
27 | gulp.task('clean', function () {
|
28 | return del(paths.dist)
|
29 | })
|
30 |
|
31 |
|
32 | gulp.task('watch', function () {
|
33 | return gulp.watch(
|
34 | [paths.srcJavascript, paths.srcCss],
|
35 | gulp.series('build')
|
36 | )
|
37 | })
|
38 |
|
39 |
|
40 | gulp.task('script', function () {
|
41 | return gulp.src(paths.srcJavascript)
|
42 | .pipe(sourcemaps.init())
|
43 | .pipe(
|
44 | header(tpl, pkg)
|
45 | )
|
46 | .pipe(gulp.dest(paths.dist))
|
47 | .pipe(uglify())
|
48 | .pipe(
|
49 | header(tpl, pkg)
|
50 | )
|
51 | .pipe(rename({ suffix: '.min' }))
|
52 | .pipe(sourcemaps.write('.'))
|
53 | .pipe(gulp.dest(paths.dist))
|
54 | .on('end', function () {
|
55 | console.log(
|
56 | chalk.green('Script file building process has been completed successfully.')
|
57 | )
|
58 | })
|
59 | })
|
60 |
|
61 |
|
62 | gulp.task('style', function () {
|
63 | return gulp.src(paths.srcCss)
|
64 | .pipe(sourcemaps.init())
|
65 | .pipe(
|
66 | header(tpl, pkg)
|
67 | )
|
68 | .pipe(
|
69 | require('gulp-postcss')([
|
70 | require('postcss-discard-comments'),
|
71 | require('autoprefixer')(),
|
72 | require('postcss-sorting')({
|
73 | order: [
|
74 | 'custom-properties',
|
75 | 'dollar-variables',
|
76 | 'declarations',
|
77 | 'at-rules',
|
78 | 'rules'
|
79 | ],
|
80 | 'properties-order': 'alphabetical',
|
81 | 'unspecified-properties-position': 'bottom'
|
82 | })
|
83 | ])
|
84 | )
|
85 | .pipe(gulp.dest(paths.dist))
|
86 | .pipe(
|
87 | require('gulp-clean-css')()
|
88 | )
|
89 | .pipe(rename({ suffix: '.min' }))
|
90 | .pipe(sourcemaps.write('.'))
|
91 | .pipe(gulp.dest(paths.dist))
|
92 | .on('end', function () {
|
93 | console.log(
|
94 | chalk.green('Style file building process has been completed successfully.')
|
95 | )
|
96 | })
|
97 | })
|
98 |
|
99 |
|
100 | gulp.task('build', gulp.series('script', 'style'))
|
101 |
|
102 |
|
103 | gulp.task(
|
104 | 'default',
|
105 | gulp.series(
|
106 | 'clean',
|
107 | 'build',
|
108 | 'watch'
|
109 | )
|
110 | )
|