-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·140 lines (118 loc) · 3.18 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
'use strict';
const $ = require('gulp-load-plugins')();
const browser = require('browser-sync');
const gulp = require('gulp');
const yaml = require('js-yaml');
const fs = require('fs');
const yargs = require('yargs');
const rimraf = require('rimraf');
const rename = require('gulp-rename');
const cssnano = require('gulp-cssnano');
// Check for --production flag
const PRODUCTION = !!(yargs.argv.production);
// Load settings from config.yml
const {PATHS} = loadConfig();
function loadConfig() {
let ymlFile = fs.readFileSync('config.yml', 'utf8');
return yaml.load(ymlFile);
}
// Delete the "release" folder
// This happens every time a build starts
function clean(done) {
rimraf('release', done);
}
gulp.task(
'sass:style',
function () {
return gulp.src('src/scss/main.scss')
.pipe($.sourcemaps.init())
.pipe(
$.sass(
{
outputStyle: 'expanded'
}
)
)
.pipe($.autoprefixer())
.pipe($.if(PRODUCTION, $.cssnano()))
.pipe($.if(!PRODUCTION, $.sourcemaps.write()))
.pipe(gulp.dest('assets/css'))
.pipe($.rtlcss())
.pipe(rename({suffix: '-rtl'}))
.pipe(gulp.dest('assets/css'));
}
);
// Compiles Sass files into CSS
gulp.task('styles', gulp.series('sass:style'));
gulp.task(
'javascript:custom',
function () {
return gulp.src(PATHS.javascript.custom)
.pipe($.sourcemaps.init())
.pipe($.concat('app.js'))
.pipe(gulp.dest('assets/js'))
.pipe($.if(PRODUCTION, $.uglify({'mangle': false})))
.pipe($.if(!PRODUCTION, $.sourcemaps.write()))
.pipe(gulp.dest('assets/js'))
}
);
// Compiles JavaScript into a single file
gulp.task('javascript', gulp.series('javascript:custom'));
// Optimize images, move into assets directory
gulp.task(
'images:optimize',
function () {
return gulp.src(PATHS.images)
.pipe($.imagemin())
.pipe(gulp.dest('assets/img'))
}
);
gulp.task(
'copy:release',
function () {
return gulp.src(
[
'**/*',
'!.*',
'!config.yml',
'!gulpfile.js',
'!package.json',
'!yarn.lock',
'!release',
'!release/**/*',
'!docs',
'!docs/**/*',
'!node_modules',
'!node_modules/**/*'
]
)
.pipe(gulp.dest('release'))
}
);
// Browser-Sync watch files and inject changes
gulp.task('browsersync', function () {
// Watch these files
var files = [
PATHS.html,
];
browser.init(files, {
server: true
});
watch();
});
// Watch for changes to assets and php files.
function watch() {
gulp.watch('src/scss/**/*.scss').on('all', gulp.series(gulp.parallel('styles'), browser.reload));
gulp.watch('src/js/**/*.js').on('all', gulp.series('javascript', browser.reload));
gulp.watch('**/*.html').on('all', gulp.series(browser.reload));
}
// Clean directory and build the assets
gulp.task('default', gulp.series('styles', 'javascript', 'images:optimize'));
// Clean the directory, build the assets, and watch for file changes
gulp.task('watch', gulp.series('default', watch));
// Build the assets, run the server, and watch for file changes
gulp.task('server', gulp.series('default', 'browsersync', watch));
// Build project and copy to clean directory
gulp.task('release', gulp.series(clean, 'default', 'copy:release'));
// Initial build of the project
gulp.task('init', gulp.series('default'));