-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
88 lines (78 loc) · 2.5 KB
/
gulpfile.babel.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
import { src, dest, watch, series, parallel } from 'gulp';
import yargs from 'yargs';
import sass from 'gulp-sass';
import cleanCss from 'gulp-clean-css';
import gulpif from 'gulp-if';
import del from 'del';
import webpack from 'webpack-stream';
import postcss from 'gulp-postcss';
import autoprefixer from 'autoprefixer';
import info from "./package.json";
const PRODUCTION = yargs.argv.prod;
// *** COMPRESS OUR SCSS STYLES *** //
export const CompressStyles = () => {
return src(['src/scss/bundle.scss'])
.pipe(sass().on('error', sass.logError))
.pipe(gulpif(PRODUCTION, postcss([ autoprefixer ])))
.pipe(gulpif(PRODUCTION, cleanCss({compatibility:'ie8'})))
.pipe(dest('dist/css'));
}
// *** BUNDLE OUR SCRIPTS *** //
export const BundleScripts = () => {
return src('src/js/FooterJS/bundleFooter.js')
.pipe(webpack({
module: {
rules: [
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: []
}
}
}
],
},
mode: PRODUCTION ? 'production' : 'development',
output: {
filename: 'bundleFooter.js'
},
}))
.pipe(dest('dist/js'));
}
// *** COPY OUR SOURCE FILES WHICH ARE NOT SCSS OR JS *** //
export const copySrcFiles = () => {
return src(['src/**/*','!src/{js,scss}','!src/{js,scss}/**/*'])
.pipe(dest('dist'));
}
// *** DELETE OUR DIST FOLDER *** //
export const cleanDist = () => del(['dist']);
// *** DELETE OUR BUILD FOLDER *** //
export const cleanBuild = () => del(['build']);
// *** WATCH FOR CHANGES IN OUR SCSS OR JS FOLDER *** //
export const watchForChanges = () => {
watch('src/scss/**/*.scss', CompressStyles);
watch('src/js/**/*.js',BundleScripts);
watch(['src/**/*','!src/{img,js,scss}','!src/{img,js,scss}/**/*'], copySrcFiles);
}
// *** COMPRESS ALL FILES FOR PRODUCTION *** //
export const compress = () => {
return src([
"**/*",
"!node_modules{,/**}",
"!bundled{,/**}",
"!src{,/**}",
"!.babelrc",
"!.gitignore",
"!gulpfile.babel.js",
"!package.json",
"!package-lock.json",
])
//.pipe(zip(`${info.name}.zip`))
.pipe(dest('build'));
};
// *** TIME TO RUN EVERYTHING *** //
export const dev = series(cleanDist, parallel(CompressStyles, copySrcFiles, BundleScripts), watchForChanges)
export const build = series(cleanBuild, cleanDist, parallel(CompressStyles, copySrcFiles, BundleScripts), compress)
export default dev;