-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
94 lines (85 loc) · 2.46 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
let fileswatch = 'html,htm,txt,json,md,woff2' // List of files extensions for watching & hard reload
const { src, dest, parallel, series, watch } = require('gulp')
const browserSync = require('browser-sync').create()
const webpack = require('webpack-stream')
const sass = require('gulp-sass')
const autoprefixer = require('gulp-autoprefixer')
const rename = require('gulp-rename')
const imagemin = require('gulp-imagemin')
const newer = require('gulp-newer')
const rsync = require('gulp-rsync')
const del = require('del')
function browsersync() {
browserSync.init({
server: { baseDir: 'app/' },
notify: false,
online: true
})
}
function scripts() {
return src('app/js/app.js')
.pipe(webpack({
mode: 'production',
module: {
rules: [
{
test: /\.(js)$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
query: {
presets: ['@babel/env']
}
}
]
}
})).on('error', function handleError() {
this.emit('end')
})
.pipe(rename('app.min.js'))
.pipe(dest('app/js'))
.pipe(browserSync.stream())
}
function styles() {
return src('app/sass/main.sass')
.pipe(sass({ outputStyle: 'compressed' }))
.pipe(autoprefixer({ overrideBrowserslist: ['last 10 versions'], grid: true }))
.pipe(rename('app.min.css'))
.pipe(dest('app/css'))
.pipe(browserSync.stream())
}
function images() {
return src('app/img/src/**/*')
.pipe(newer('app/img/dest'))
.pipe(imagemin())
.pipe(dest('app/img/dest'))
}
function cleanimg() {
return del('app/img/dest/**/*', { force: true })
}
function deploy() {
return src('app/')
.pipe(rsync({
root: 'app/',
hostname: 'username@yousite.com',
destination: 'yousite/public_html/',
include: [/* '*.htaccess' */], // Included files to deploy,
exclude: [ '**/Thumbs.db', '**/*.DS_Store' ],
recursive: true,
archive: true,
silent: false,
compress: true
}))
}
function startwatch() {
watch('app/sass/**/*', { usePolling: true }, styles)
watch(['app/js/**/*.js', '!app/js/**/*.min.js'], { usePolling: true }, scripts)
watch('app/img/src/**/*.{jpg,jpeg,png,webp,svg,gif}', { usePolling: true }, images)
watch(`app/**/*.{${fileswatch}}`, { usePolling: true }).on('change', browserSync.reload)
}
exports.assets = series(cleanimg, scripts, images)
exports.scripts = scripts
exports.styles = styles
exports.images = images
exports.cleanimg = cleanimg
exports.deploy = deploy
exports.default = series(scripts, images, styles, parallel(browsersync, startwatch))