-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
97 lines (87 loc) · 2.87 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
const { series, parallel, src, dest, watch } = require('gulp'),
sass = require('gulp-sass')(require('sass')),
concat = require('gulp-concat'),
merge2 = require('merge2'),
sourcemaps = require('gulp-sourcemaps'),
autoprefixer = require('gulp-autoprefixer'),
cleanDest = require('gulp-clean-dest'),
eslint = require('gulp-eslint'),
babel = require('gulp-babel'),
uglify = require('gulp-uglify'),
svgmin = require('gulp-svgmin'),
through2 = require('through2'),
log = require('fancy-log'),
minimist = require('minimist')(process.argv.slice(2))
const config = {
project: 'app',
srcPath: 'src/',
publicPath: 'static/',
forProduction: minimist.prod,
}
let location = {
compiled: {
css: config.publicPath + 'css/',
js: config.publicPath + 'js',
},
sources: {
jsVendors: ['node_modules/gsap/dist/gsap.js', 'node_modules/gsap/dist/ScrollTrigger.js', config.srcPath + 'js/vendor/*.js'],
jsApp: config.srcPath + 'js/*.js',
css: [config.srcPath + 'sass/app.s*ss'],
frameworks: ['node_modules/bootstrap/scss'],
},
}
const handleError = (err) => {
log.error('\n\n' + ' | Error: ' + err.messageOriginal + ' /// line: ' + err.line + '/' + err.column + '\n' + ' | In file: ' + err.file + '\n')
this.emit('end')
}
const css = () => {
return src(location.sources.css)
.pipe(config.forProduction ? through2.obj() : sourcemaps.init())
.pipe(config.forProduction ? sass({ includePaths: location.sources.frameworks, outputStyle: 'compressed' }).on('error', handleError) : sass({ includePaths: location.sources.frameworks }).on('error', handleError))
.pipe(autoprefixer())
.pipe(concat(config.project + '.css'))
.pipe(cleanDest(location.compiled.css))
.pipe(config.forProduction ? through2.obj() : sourcemaps.write('maps'))
.pipe(dest(location.compiled.css))
}
const js = () => {
return merge2(
src(location.sources.jsVendors, { allowEmpty: true }),
src(location.sources.jsApp)
.pipe(eslint())
.pipe(eslint.format())
.pipe(
babel({
presets: [['@babel/preset-env']],
})
)
)
.pipe(concat(config.project + '.js'))
.pipe(config.forProduction ? uglify() : through2.obj())
.pipe(cleanDest(location.compiled.js))
.pipe(dest(location.compiled.js))
}
const svg = () => {
return src(config.srcPath + 'svg/**/*.svg')
.pipe(cleanDest(config.publicPath + 'svg'))
.pipe(
svgmin({
plugins: [
{
removeViewBox: false,
convertStyleToAttrs: false,
cleanupIDs: false,
},
],
})
)
.pipe(dest(config.publicPath + 'svg'))
}
const w = () => {
watch(config.srcPath + 'sass/**/*.s*ss', css)
watch(config.srcPath + 'js/**/*.js', js)
watch(config.srcPath + 'svg/**/*.svg', svg)
}
exports.default = parallel(css, js, svg)
exports.watch = series(parallel(css, js, svg), w)
exports.svgmin = svg