2022-11-15 19:05:47 +00:00
|
|
|
const { src, dest, watch, parallel } = require("gulp");
|
2022-11-15 12:27:50 +00:00
|
|
|
const sass = require("gulp-sass")(require("sass"));
|
2022-11-15 19:05:47 +00:00
|
|
|
const browserify = require("browserify");
|
|
|
|
const babelify = require("babelify");
|
|
|
|
const source = require("vinyl-source-stream");
|
|
|
|
const buffer = require("vinyl-buffer");
|
|
|
|
const uglify = require("gulp-uglify");
|
|
|
|
const connect = require("gulp-connect");
|
|
|
|
|
|
|
|
const paths = {
|
|
|
|
html: {
|
|
|
|
all: "src/templates/**/*.html",
|
|
|
|
},
|
|
|
|
styles: {
|
|
|
|
all: "src/styles/**/*.scss",
|
|
|
|
main: "src/styles/main.scss",
|
|
|
|
},
|
|
|
|
scripts: {
|
|
|
|
all: "src/scripts/**/*.js",
|
|
|
|
main: "src/scripts/app.js",
|
|
|
|
},
|
|
|
|
output: "dist",
|
|
|
|
};
|
|
|
|
|
|
|
|
function server() {
|
|
|
|
connect.server({
|
|
|
|
root: "dist",
|
|
|
|
livereload: true,
|
|
|
|
port: 3000,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function sentinel() {
|
|
|
|
watch(paths.html.all, { ignoreInitial: false }, html);
|
|
|
|
watch(paths.styles.all, { ignoreInitial: false }, styles);
|
|
|
|
watch(paths.scripts.all, { ignoreInitial: false }, scripts);
|
|
|
|
}
|
|
|
|
|
|
|
|
function html() {
|
|
|
|
return src(paths.html.all).pipe(dest(paths.output));
|
|
|
|
}
|
2022-11-15 12:27:50 +00:00
|
|
|
|
|
|
|
function styles() {
|
2022-11-15 19:05:47 +00:00
|
|
|
return src(paths.styles.main)
|
|
|
|
.pipe(sass({ outputStyle: "compressed" }).on("error", sass.logError))
|
|
|
|
.pipe(dest(paths.output))
|
|
|
|
.pipe(connect.reload());
|
2022-11-15 12:27:50 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 19:05:47 +00:00
|
|
|
function scripts() {
|
|
|
|
return browserify(paths.scripts.main)
|
|
|
|
.transform(
|
|
|
|
babelify.configure({
|
|
|
|
presets: ["@babel/preset-env"],
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.bundle()
|
|
|
|
.pipe(source("bundle.js"))
|
|
|
|
.pipe(buffer())
|
|
|
|
.pipe(uglify())
|
|
|
|
.pipe(dest(paths.output))
|
|
|
|
.pipe(connect.reload());
|
2022-11-15 12:27:50 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 19:05:47 +00:00
|
|
|
exports.default = parallel(server, sentinel);
|