Skip to content

Instantly share code, notes, and snippets.

@BobbieGoede

BobbieGoede/gulpfile.js

Last active Feb 24, 2020
Embed
What would you like to do?
npm install -D gulp browserify babelify @babel/core @babel/preset-env vinyl-source-stream vinyl-buffer gulp-uglify gulp-htmlmin cssnano gulp-postcss del
const gulp = require("gulp");
const browserify = require("browserify");
const source = require("vinyl-source-stream");
const buffer = require("vinyl-buffer");
const babelify = require("babelify");
const uglify = require("gulp-uglify");
const htmlmin = require("gulp-htmlmin");
const postcss = require("gulp-postcss");
const cssnano = require("cssnano");
const del = require("del");
const paths = {
source: "./src",
build: "./build"
};
function javascriptBuild() {
return browserify({
entries: [`${paths.source}/scripts/main.js`],
transform: [babelify.configure({ presets: ["@babel/preset-env"] })]
})
.bundle()
.pipe(source("bundle.js"))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest(`${paths.build}/scripts`));
}
function htmlBuild() {
return gulp
.src(`${paths.source}/*.html`)
.pipe(htmlmin())
.pipe(gulp.dest(paths.build));
}
function cssBuild() {
return gulp
.src(`${paths.source}/styles/**/*.css`)
.pipe(postcss([cssnano()]))
.pipe(gulp.dest(`${paths.build}/styles`));
}
function cleanup() {
return del([paths.build]);
}
// Run using gulp or gulp build
exports.default = exports.build = gulp.series(
cleanup,
gulp.parallel(javascriptBuild, htmlBuild, cssBuild)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.