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