UNPKG

2.64 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 = `
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* MIT License
16* by <%= author %>
17*/
18`.trimStart()
19
20const paths = {
21 srcJavascript: './src/*.js',
22 srcCss: './src/*.css',
23 dist: './dist/'
24}
25
26// clean dist folder
27gulp.task('clean', function () {
28 return del(paths.dist)
29})
30
31// watch for changes of source file to build distributable file (only for stage environment)
32gulp.task('watch', function () {
33 return gulp.watch(
34 [paths.srcJavascript, paths.srcCss],
35 gulp.series('build')
36 )
37})
38
39// build javascript file
40gulp.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// build css file
62gulp.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// 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)