-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
126 lines (108 loc) · 3.78 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// VARIABLES & PATHS
let preprocessor = 'scss', // Preprocessor (sass, scss, less, styl)
fileswatch = 'html,htm,txt,json,md,woff2', // List of files extensions for watching & hard reload (comma separated)
imageswatch = 'jpg,jpeg,png,webp,svg', // List of images extensions for watching & compression (comma separated)
baseDir = 'app', // Base directory path without «/» at the end
online = true; // If «false» - Browsersync will work offline without internet connection
let paths = {
scripts: {
src: [
// 'node_modules/jquery/dist/jquery.min.js', // npm vendor example (npm i --save-dev jquery)
'node_modules/choices.js/public/assets/scripts/choices.min.js',
// 'node_modules/slim-select/dist/slimselect.min.js',
baseDir + '/js/app.js' // app.js. Always at the end
],
dest: baseDir + '/js',
},
styles: {
src: baseDir + '/' + preprocessor + '/main.*',
dest: baseDir + '/css',
},
images: {
src: baseDir + '/images/src/**/*',
dest: baseDir + '/images/dest',
},
deploy: {
hostname: '[email protected]', // Deploy hostname
destination: 'yousite/public_html/', // Deploy destination
include: [/* '*.htaccess' */], // Included files to deploy
exclude: [ '**/Thumbs.db', '**/*.DS_Store' ], // Excluded files from deploy
},
cssOutputName: 'app.min.css',
jsOutputName: 'app.min.js',
}
// LOGIC
const { src, dest, parallel, series, watch } = require('gulp');
const sass = require('gulp-sass');
const scss = require('gulp-sass');
const less = require('gulp-less');
const styl = require('gulp-stylus');
const cleancss = require('gulp-clean-css');
const concat = require('gulp-concat');
const browserSync = require('browser-sync').create();
const uglify = require('gulp-uglify-es').default;
const autoprefixer = require('gulp-autoprefixer');
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: baseDir + '/' },
notify: false,
online: online
})
}
function scripts() {
return src(paths.scripts.src)
.pipe(concat(paths.jsOutputName))
.pipe(uglify())
.pipe(dest(paths.scripts.dest))
.pipe(browserSync.stream())
}
function styles() {
return src(paths.styles.src)
.pipe(eval(preprocessor)())
.pipe(concat(paths.cssOutputName))
.pipe(autoprefixer({ overrideBrowserslist: ['last 10 versions'], grid: true }))
.pipe(cleancss( {level: { 1: { specialComments: 0 } },/* format: 'beautify' */ }))
.pipe(dest(paths.styles.dest))
.pipe(browserSync.stream())
}
function images() {
return src(paths.images.src)
.pipe(newer(paths.images.dest))
.pipe(imagemin())
.pipe(dest(paths.images.dest))
}
function cleanimg() {
return del('' + paths.images.dest + '/**/*', { force: true })
}
function deploy() {
return src(baseDir + '/')
.pipe(rsync({
root: baseDir + '/',
hostname: paths.deploy.hostname,
destination: paths.deploy.destination,
include: paths.deploy.include,
exclude: paths.deploy.exclude,
recursive: true,
archive: true,
silent: false,
compress: true
}))
}
function startwatch() {
watch(baseDir + '/**/' + preprocessor + '/**/*', styles);
watch(baseDir + '/**/*.{' + imageswatch + '}', images);
watch(baseDir + '/**/*.{' + fileswatch + '}').on('change', browserSync.reload);
watch([baseDir + '/**/*.js', '!' + paths.scripts.dest + '/*.min.js'], scripts);
}
exports.browsersync = browsersync;
exports.assets = series(cleanimg, styles, scripts, images);
exports.styles = styles;
exports.scripts = scripts;
exports.images = images;
exports.cleanimg = cleanimg;
exports.deploy = deploy;
exports.default = parallel(images, styles, scripts, browsersync, startwatch);