forked from creativetimofficial/argon-dashboard-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
179 lines (161 loc) · 3.77 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/**
* Gulp file to automate the various tasks
* */
const autoprefixer = require('gulp-autoprefixer');
const browserSync = require('browser-sync').create();
const csscomb = require('gulp-csscomb');
const cleanCss = require('gulp-clean-css');
const del = require('del');
const gulp = require('gulp');
const postcss = require('gulp-postcss');
const sass = require('gulp-sass');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const wait = require('gulp-wait');
const sourcemaps = require('gulp-sourcemaps');
// Define paths
const paths = {
dist: {
base: 'dist',
img: 'dist/img',
libs: 'dist/vendor',
fonts: 'dist/fonts',
css: 'dist/css',
js: 'dist/js',
vendor: 'dist/vendor',
},
base: {
base: './public',
node: 'node_modules',
},
src: {
base: './public',
css: 'public/css/**/*.css',
js: 'public/js/**/*.js',
html: '**/*.html',
img: 'public/img/**/*.+(png|jpg|gif|svg)',
ejs: 'views/**/*.ejs',
fonts: 'public/fonts/**/*.+(eot|svg|ttf|woff|woff2)',
vendor: 'public/vendor/**/*',
scss: 'public/scss/**/*.scss',
},
};
// Compile SCSS for dev
function scssDev() {
return gulp
.src(paths.src.scss)
.pipe(wait(500))
.pipe(sass().on('error', sass.logError))
.pipe(postcss([require('postcss-flexbugs-fixes')])) // eslint-disable-line
.pipe(
autoprefixer({
browsers: ['> 1%'],
})
)
.pipe(csscomb())
.pipe(sourcemaps.init())
.pipe(cleanCss())
.pipe(sourcemaps.write())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(`${paths.src.base}/css`))
.pipe(browserSync.stream({ match: '**/*.css' }));
}
// Compile SCSS for prod
function scssProd() {
return gulp
.src(paths.src.scss)
.pipe(wait(500))
.pipe(sass().on('error', sass.logError))
.pipe(postcss([require('postcss-flexbugs-fixes')])) // eslint-disable-line
.pipe(
autoprefixer({
browsers: ['> 1%'],
})
)
.pipe(csscomb())
.pipe(gulp.dest(`${paths.dist.base}/css`));
}
// Minify CSS
function minifyCSS() {
return gulp
.src([`${paths.dist.css}/argon.css`])
.pipe(cleanCss())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(`${paths.dist.base}/css`));
}
// Minify JS
function minifyJS() {
return gulp
.src([`${paths.src.base}/js/argon.js`])
.pipe(uglify())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(`${paths.dist.base}/js`));
}
// Live reload
function serve(done) {
browserSync.init({
files: ['public/**/*', 'views/**/*'],
proxy: 'http://0.0.0.0:8000',
});
done();
}
// Watch for changes
function watch() {
gulp.watch(paths.src.scss, scssDev);
gulp.watch(paths.src.js, browserSync.reload);
gulp.watch(paths.src.html, browserSync.reload);
gulp.watch(paths.src.ejs, browserSync.reload);
}
// Clean
async function cleanDist(done) {
await del.sync(paths.dist.base);
done();
}
// Copy JS
async function copyJS(done) {
gulp.src([`${paths.src.js}`]).pipe(gulp.dest(`${paths.dist.js}`));
done();
}
// Copy images
async function copyImages(done) {
gulp.src([`${paths.src.img}`]).pipe(gulp.dest(`${paths.dist.img}`));
done();
}
// Copy fonts
async function copyFonts(done) {
gulp.src([`${paths.src.fonts}`]).pipe(gulp.dest(`${paths.dist.fonts}`));
done();
}
// Copy vendor
async function copyVendor(done) {
gulp.src([`${paths.src.vendor}`]).pipe(gulp.dest(`${paths.dist.vendor}`));
done();
}
// Build
const build = gulp.series(
cleanDist,
scssProd,
copyJS,
copyImages,
copyFonts,
copyVendor,
minifyJS,
minifyCSS
);
// Default
const defaultTask = gulp.series(scssDev, serve, watch);
module.exports = {
scssDev,
scssProd,
minifyCSS,
minifyJS,
serve,
watch,
cleanDist,
copyJS,
copyImages,
copyFonts,
copyVendor,
build,
default: defaultTask,
};