-
Notifications
You must be signed in to change notification settings - Fork 284
/
Copy pathgulpfile.js
100 lines (90 loc) · 3.24 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
let syntax = 'sass', // Syntax - .sass or .scss
fileswatch = 'html,htm,txt,json,md,woff2', // List of files extensions for watching & hard reload
gmWatch = false // true/false GraphicsMagick watching "img/_src" folder.
// Install gm Linux/WSL: sudo apt update; sudo apt install graphicsmagick
// Install gm Git Bash: https://sourceforge.net/projects/graphicsmagick/files/
import pkg from 'gulp'
const { src, dest, parallel, series, watch } = pkg
import browserSync from 'browser-sync'
import gulpSass from 'gulp-sass'
import * as dartSass from 'sass'
const sass = gulpSass(dartSass)
import postCss from 'gulp-postcss'
import cssnano from 'cssnano'
import concat from 'gulp-concat'
import uglify from 'gulp-uglify'
import autoprefixer from 'autoprefixer'
import rsyncModule from 'gulp-rsync'
import imageResize from 'gulp-image-resize'
import {deleteAsync} from 'del'
function browsersync() {
browserSync.init({
server: {
baseDir: 'app/'
},
ghostMode: { clicks: false },
notify: false,
online: true,
// tunnel: 'yousutename', // Attempt to use the URL https://yousutename.loca.lt
})
}
function scripts() {
return src([
'app/libs/jquery/dist/jquery.min.js',
'app/js/common.js', // Always at the end
])
.pipe(concat('scripts.min.js'))
// .pipe(uglify()) // Mifify js (opt.)
.pipe(dest('app/js'))
.pipe(browserSync.stream())
}
function styles() {
return src([`app/${syntax}/**/*.${syntax}`])
.pipe(sass({ 'include css': true }))
.pipe(postCss([
autoprefixer({ grid: 'autoplace' }),
cssnano({ preset: ['default', { discardComments: { removeAll: true } }] })
]))
.pipe(concat('main.min.css'))
.pipe(dest('app/css'))
.pipe(browserSync.stream())
}
function img1x() {
return src('app/img/_src/**/*.*', { encoding: false })
.pipe(imageResize({ width: '50%' }))
.pipe(dest('app/img/@1x/'))
}
function img2x() {
return src('app/img/_src/**/*.*', { encoding: false })
.pipe(imageResize({ width: '100%' }))
.pipe(dest('app/img/@2x/'))
}
async function cleanimg() {
await deleteAsync('app/img/@*', { force: true })
}
function rsync() {
return src('app/') // Без звёздочек!
.pipe(rsyncModule({
root: 'app/',
hostname: '[email protected]',
destination: 'yousite/public_html/',
clean: true, // Mirror copy with file deletion
// include: ['*.htaccess'], // Includes files to deploy
exclude: ['**/Thumbs.db', '**/*.DS_Store'], // Excludes files from deploy
recursive: true,
archive: true,
silent: false,
compress: true
}))
}
function startwatch() {
watch([`app/${syntax}/**/*.${syntax}`], { usePolling: true }, styles)
watch(['app/js/common.js', 'app/libs/**/*.js'], { usePolling: true }, scripts)
watch([`app/**/*.{${fileswatch}}`], { usePolling: true }).on('change', browserSync.reload)
gmWatch && watch(['app/img/_src/**/*'], { usePolling: true }, img) // GraphicsMagick watching image sources if allowed
}
export { scripts, styles, rsync, cleanimg }
export let img = parallel(img1x, img2x)
export let assets = series(img, scripts, styles)
export default gmWatch ? series(img, scripts, styles, parallel(browsersync, startwatch))
: series(scripts, styles, parallel(browsersync, startwatch))