This repository has been archived by the owner on Oct 31, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
109 lines (94 loc) · 2.39 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
'use strict'
var postcss = require('gulp-postcss')
var gulp = require('gulp')
var sourcemaps = require('gulp-sourcemaps')
var autoprefixer = require('autoprefixer')
var cssnano = require('cssnano')
var sass = require('gulp-sass')
var babel = require('gulp-babel')
var uglify = require('gulp-uglify')
var cleanCSS = require('gulp-clean-css')
var del = require('del')
var zip = require('gulp-zip')
var concat = require('gulp-concat')
sass.compiler = require('node-sass');
var paths = {
styles: {
src: 'src/sass',
dest: 'assets/css'
},
scripts: {
src: 'src/js',
dest: 'assets/js'
}
};
function clean() {
return del([ 'assets' ]);
}
function copyStaticJS() {
return gulp.src(paths.scripts.src + '/libs/**/*')
.pipe(gulp.dest(paths.scripts.dest + '/libs'))
}
function copyStaticCSS() {
return gulp.src(paths.styles.src + '/libs/**/*')
.pipe(gulp.dest(paths.styles.dest))
}
function copyFonts() {
return gulp.src('src/font/**/*')
.pipe(gulp.dest('assets/font'))
}
function copyIMG() {
return gulp.src('src/img/**/*')
.pipe(gulp.dest('assets/img'))
}
function styles() {
var plugins = [
autoprefixer(),
cssnano()
];
return gulp.src(paths.styles.src + '/style.scss')
.pipe(sourcemaps.init())
.pipe(sass.sync().on('error', sass.logError))
.pipe(cleanCSS())
.pipe(postcss(plugins))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.styles.dest))
}
function scripts() {
return gulp.src(paths.scripts.src + '/**/*.js')
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(concat('script.js'))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.scripts.dest))
}
function watchFiles() {
gulp.watch(paths.scripts.src + '/**/*.js', scripts)
gulp.watch(paths.styles.src + '/**/*.scss', style)
}
function zipIt() {
return gulp.src([
'**',
'!node_modules',
'!node_modules/**',
'!src',
'!src/**',
'!dist',
'!dist/**',
'!.git',
'!.gitignore',
'!gulpfile.js',
'!package-lock.json'
])
.pipe(zip('tonic.zip'))
.pipe(gulp.dest('dest'))
}
var copy = gulp.series(copyStaticCSS, copyStaticJS, copyIMG, copyFonts)
var style = gulp.series(styles)
var script = gulp.parallel(scripts)
var defaults = gulp.series(clean, copy, style, script)
var compress = gulp.series(defaults, gulp.parallel(zipIt))
exports.watch = watchFiles
exports.compress = compress
exports.default = defaults