forked from cssninjaStudio/krypton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
208 lines (187 loc) Β· 5.29 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import gulp from "gulp";
import gulpSass from "gulp-sass";
import concat from "gulp-concat";
import imagemin from "gulp-imagemin";
import sourcemaps from "gulp-sourcemaps";
import autoprefixer from "gulp-autoprefixer";
import panini from "panini";
import sassCompiler from "sass";
import del from "del";
import browserify from "browserify";
import babelify from "babelify";
import source from "vinyl-source-stream";
import logSymbols from "log-symbols";
import BrowserSync from "browser-sync";
import options from "./config.js";
const { src, dest, watch, series, parallel } = gulp;
const browserSync = BrowserSync.create();
const nodepath = "node_modules/";
const sass = gulpSass(sassCompiler);
//Load Previews on Browser on dev
function livePreview(done) {
browserSync.init({
server: {
baseDir: options.paths.dist.base,
},
port: options.config.port || 5000,
});
done();
}
//Copy latest installed Bulma
function setupBulma() {
console.log("\n\t" + logSymbols.info, "Installing Bulma Files..\n");
return src([nodepath + "bulma/*.sass", nodepath + "bulma/**/*.sass"]).pipe(
dest("src/sass/")
);
}
//Compile Scss code
function compileSCSS() {
console.log(logSymbols.info, "Compiling App SCSS..");
return src(["src/scss/main.scss"])
.pipe(
sass({
outputStyle: "compressed",
sourceComments: "map",
sourceMap: "scss",
// includePaths: bourbon,
}).on("error", sass.logError)
)
.pipe(autoprefixer("last 2 versions"))
.pipe(dest("dist/css"))
.pipe(browserSync.stream());
}
//Compile HTML partials with Panini
function compileHTML() {
console.log(logSymbols.info, "Compiling HTML..");
panini.refresh();
return src("src/pages/**/*.html")
.pipe(
panini({
root: "src/pages/",
layouts: "src/layouts/",
partials: "src/partials/",
helpers: "src/helpers/",
data: "src/data/",
})
)
.pipe(dest("dist"))
.pipe(browserSync.stream());
}
//Concat JS
function concatJs() {
console.log(logSymbols.info, "Compiling Vendor Js..");
return src(["src/vendor/js/*"])
.pipe(sourcemaps.init())
.pipe(concat("app.js"))
.pipe(sourcemaps.write("./"))
.pipe(dest("dist/js"))
.pipe(browserSync.stream());
}
//Concat CSS Plugins
function concatCssPlugins() {
console.log(logSymbols.info, "Compiling Plugin styles..");
return src([
nodepath + "simplebar/dist/simplebar.min.css",
nodepath + "plyr/dist/plyr.css",
nodepath + "codemirror/lib/codemirror.css",
nodepath + "codemirror/theme/shadowfox.css",
"src/vendor/css/*",
])
.pipe(sourcemaps.init())
.pipe(concat("app.css"))
.pipe(sourcemaps.write("./"))
.pipe(dest("dist/css"))
.pipe(browserSync.stream());
}
//Reset Panini Cache
function resetPages(done) {
console.log(logSymbols.info, "Clearing Panini Cache..");
panini.refresh();
done();
}
//Triggers Browser reload
function previewReload(done) {
console.log(logSymbols.info, "Reloading Browser Preview.");
browserSync.reload();
done();
}
//Copy images
function copyImages() {
return src(`${options.paths.src.img}/**/*`).pipe(
dest(options.paths.dist.img)
);
}
//Optimize images
function optimizeImages() {
return src(`${options.paths.src.img}/**/*`)
.pipe(imagemin())
.pipe(dest(options.paths.dist.img));
}
// Let's write our task in a function to keep things clean
function javascriptBuild() {
// Start by calling browserify with our entry pointing to our main javascript file
return (
browserify({
entries: [`${options.paths.src.js}/main.js`],
// Pass babelify as a transform and set its preset to @babel/preset-env
transform: [babelify.configure({ presets: ["@babel/preset-env"] })],
})
// Bundle it all up!
.bundle()
// Source the bundle
.pipe(source("bundle.js"))
// Then write the resulting files to a folder
.pipe(dest(`dist/js`))
);
}
function copyFonts() {
console.log(logSymbols.info, "Copying fonts to dist folder.");
return src(["src/fonts/*"])
.pipe(dest("dist/fonts"))
.pipe(browserSync.stream());
}
function watchFiles() {
watch(
`${options.paths.src.base}/**/*.html`,
series(compileHTML, previewReload)
);
watch(["src/scss/**/*", "src/scss/*"], compileSCSS);
watch(
`${options.paths.src.js}/**/*.js`,
series(javascriptBuild, previewReload)
);
watch(`${options.paths.src.img}/**/*`, series(copyImages, previewReload));
console.log(logSymbols.info, "Watching for Changes..");
}
function devClean() {
console.log(logSymbols.info, "Cleaning dist folder for fresh start.");
return del([options.paths.dist.base]);
}
const buildTasks = [
devClean,
resetPages,
parallel(
concatJs,
copyFonts,
concatCssPlugins,
compileSCSS,
javascriptBuild,
compileHTML
),
];
export const build = (done) => {
series(devClean, resetPages, parallel(...buildTasks, optimizeImages))();
done();
};
export default (done) => {
series(
devClean,
resetPages,
parallel(...buildTasks, copyImages),
parallel(livePreview, watchFiles)
)();
done();
};
export const setup = () => {
series(setupBulma);
};