UNPKG

2.91 kBJavaScriptView Raw
1const chalk = require('chalk')
2const gulp = require('gulp')
3const rename = require('gulp-rename')
4const uglify = require('gulp-uglify')
5const header = require('gulp-header')
6const del = require('del')
7const sourcemaps = require('gulp-sourcemaps')
8const pkg = require('./package.json')
9
10const 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// src and dist paths
13const paths = {
14 srcJavascript: './src/*.js',
15 srcCss: './src/*.css',
16 dist: './dist/'
17}
18
19// clean dist folder
20gulp.task('clean', function () {
21 return del(paths.dist)
22})
23
24// watch for changes of source file to build distributable file (only for stage environment)
25gulp.task('watch', function () {
26 return gulp.watch(
27 [paths.srcJavascript, paths.srcCss],
28 gulp.series('build')
29 )
30})
31
32// build javascript file
33gulp.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// build css file
55gulp.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 /* format: 'keep-breaks', */
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// generate/build production files in dist folder
100gulp.task('build', gulp.series('script', 'style'))
101
102// gulp default task
103gulp.task(
104 'default',
105 gulp.series(
106 'clean',
107 'build',
108 'watch'
109 )
110)