-
Notifications
You must be signed in to change notification settings - Fork 1
/
full-build.gulpfile.babel.js
175 lines (157 loc) · 3.76 KB
/
full-build.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
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
import { parallel, series, watch } from "gulp";
import { css, js, lib, sass } from "@coldfrontlabs/gulp-templates";
const paths = {
css: {
source: "dist/css",
destination: "dist/css",
selector: "**/*.css",
},
js: {
source: "src/js",
destination: "dist/js",
selector: "**/*.js",
},
lib: {
source: [
"node_modules/awesome-package/dist/*",
"node_modules/another-awesome-package/dist/*",
],
destination: "dist/lib",
},
sass: {
source: "src/scss",
destination: "src/scss",
selector: "**/*.{sass,scss}",
},
min: "**/*.min.*",
map: "**/*.map",
};
/**
* Lints and fixes all JS files.
*
* @returns {object} - Gulp stream.
*/
export const lintScripts = () => {
const source = `${paths.js.source}/${paths.js.selector}`;
return js.fix({
source,
});
};
lintScripts.description = "Lints and fixes all JS files.";
/**
* Lints and fixes all Sass files.
*
* @returns {object} - Gulp stream.
*/
export const lintStyles = () => {
const source = `${paths.sass.source}/${paths.sass.selector}`;
return sass.fix({
source,
});
};
lintStyles.description = "Lints and fixes all Sass files.";
/**
* Compiles all JS files using Babel.
*
* @returns {object} - Gulp stream.
*/
export const compileScripts = () => {
const source = `${paths.js.source}/${paths.js.selector}`;
const { destination } = paths.js;
return js.compile({
source,
destination,
sourcemap: true,
});
};
compileScripts.description = "Compiles all JS files using Babel.";
/**
* Compiles all Sass files into CSS.
*
* @returns {object} - Gulp stream.
*/
export const compileStyles = () => {
const source = `${paths.js.source}/${paths.js.selector}`;
const { destination } = paths.css;
return sass.compile({
source,
destination,
sourcemap: true,
});
};
compileStyles.description = "Compiles all Sass files into CSS.";
/**
* Minifies all compiled JS files.
*
* @returns {object} - Gulp stream.
*/
export const minifyScripts = () => {
const { destination } = paths.js;
const source = [
`${destination}/${paths.js.selector}`,
`!${paths.min}`,
`!${paths.map}`,
];
return js.minify({
source,
destination,
sourcemap: true,
sourcemapOptions: { loadMaps: true },
});
};
minifyScripts.description = "Minifies all compiled JS files.";
/**
* Minifies all CSS files.
*
* @returns {object} - Gulp stream.
*/
export const minifyStyles = () => {
const source = [
`${paths.css.source}/${paths.css.selector}`,
`!${paths.min}`,
`!${paths.map}`,
];
const { destination } = paths.css;
return css.minify({
source,
destination,
sourcemap: true,
sourcemapOptions: { loadMaps: true },
});
};
minifyStyles.description = "Minifies all CSS files.";
/**
* Fetches all required libraries and moves them into the dist directory.
*
* @returns {object} - Gulp stream.
*/
export const fetchLibs = () => {
const { source, destination } = paths.lib;
return lib.fetch({
source,
destination,
});
};
fetchLibs.description =
"Fetches all required libraries and moves them into the dist directory.";
const build = parallel(
series(lintScripts, compileScripts, minifyScripts),
series(lintStyles, compileStyles, minifyStyles),
fetchLibs
);
build.description =
"Lints, fixes, compiles, and minifies all source files and fetches libraries.";
const watchFiles = () => {
watch(
`${paths.js.source}/${paths.js.selector}`,
series(lintScripts, compileScripts, minifyScripts)
);
watch(
`${paths.sass.source}/${paths.sass.selector}`,
series(lintStyles, compileStyles, minifyStyles)
);
};
watchFiles.description =
"Watches all source files and lints, fixes, compiles and minifies them accordingly.";
export { watchFiles as watch };
export default build;