This repository has been archived by the owner on May 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
160 lines (147 loc) · 4.14 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
* @function gulp
* @description the main gulp file for the task runner
* @version v1
*/
var gulp = require('gulp');
var browserSync = require('browser-sync');
var sass = require('gulp-sass');
var cleanCSS = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var plumber = require('gulp-plumber');
var concat = require('gulp-concat');
var imagemin = require('gulp-imagemin');
var prefix = require('gulp-autoprefixer');
var svgstore = require('gulp-svgstore');
var sourcemaps = require('gulp-sourcemaps');
var babel = require('gulp-babel');
/**
* @function variables
* @description variables which contain things used throughout this file
*/
// Site URL for Browser Sync
// - - - - - - - - - - - - - - - - - -
const siteURL = 'test-theme.uk';
// Main JS Variables
// - - - - - - - - - - - - - - - - - -
const js = {
jsFiles: './assets/js/vendor/**/*.js',
mainJSFile: './assets/js/scripts.js',
outputJSFile: './main.js',
outputJSFileCompressed: './main.min.js',
outputJSFileLocation: './assets/js/dist',
};
// Main CSS Variables
// - - - - - - - - - - - - - - - - - -
const css = {
sassFiles: './assets/scss/**/*.scss',
mainSassFile: './assets/scss/style.scss',
outputCSSFile: './main.css',
outputCSSFileCompressed: './main.min.css',
outputCSSFileLocation: './assets/css/dist'
};
// Autoprefixer Variables
// - - - - - - - - - - - - - - - - - -
const autoprefixerOptions = {
browsers: ['last 25 versions']
};
// Media Variables
// - - - - - - - - - - - - - - - - - -
const media = {
imgs: 'assets/imgs',
icons: 'assets/icons'
}
/**
* @function scripts
* @description pipes our vendor JS files, main JS file out and minifies it
* @version v1
*/
gulp.task('scripts', function () {
return gulp.src([js.jsFiles, js.mainJSFile])
.pipe(babel({
presets: ['env']
}))
.pipe(plumber())
.pipe(concat(js.outputJSFile)) // output main JavaScript file without uglify
.pipe(gulp.dest(js.outputJSFileLocation))
.pipe(uglify())
.pipe(concat(js.outputJSFileCompressed)) // output main JavaScript file w/ uglify
.pipe(gulp.dest(js.outputJSFileLocation))
.pipe(browserSync.reload({ stream: true }))
});
/**
* @function sass
* @description compiles our static .scss files into one main .css file
* @version v1
*/
gulp.task('styles', function () {
return gulp.src(css.mainSassFile)
.pipe(sourcemaps.init())
.pipe(sass({
includePaths: ['scss'],
onError: browserSync.notify
}).on('error', sass.logError))
.pipe(prefix(autoprefixerOptions, { cascade: true }))
.pipe(plumber())
.pipe(concat(css.outputCSSFile)) // output main CSS file without cleanCSS
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest(css.outputCSSFileLocation))
.pipe(cleanCSS())
.pipe(concat(css.outputCSSFileCompressed)) // output main CSS file w/ cleanCSS
.pipe(gulp.dest(css.outputCSSFileLocation))
.pipe(browserSync.reload({ stream: true }));
});
/**
* @function browser-sync
* @description generates BrowserSync for watching and refreshing page
* @version v1
*/
gulp.task('browser-sync', ['scripts', 'styles'], function () {
browserSync.init({
proxy: siteURL,
files: [
"*.php",
'**/*.php',
'*.twig',
'**/*.twig',
'gulpfile.js',
js.outputJSFileLocation + '/*.js',
css.outputCSSFileLocation + '/*.css'
]
});
});
/**
* @function imgs
* @description compresses static images
* @version v1
*/
gulp.task('imgs', function () {
gulp.src(media.imgs + '/*')
.pipe(imagemin())
.pipe(gulp.dest(media.imgs));
});
/**
* @function svgstore
* @description generates and creates svg icons using #symbol
* @version v1
*/
gulp.task('svgstore', function () {
return gulp.src(media.icons + '/*.svg')
.pipe(svgstore())
.pipe(gulp.dest(media.icons));
});
/**
* @function watch
* @description watchs the .js and .scss files for changes
* @version v1
*/
gulp.task('watch', function () {
gulp.watch(js.mainJSFile, ['scripts']);
gulp.watch(css.sassFiles, ['styles']);
});
/**
* @function default
* @description runs the default task, which is browser sync and watch tasks
* @version v1
*/
gulp.task('default', ['browser-sync', 'watch']);