Last active
February 24, 2020 00:42
-
-
Save BobbieGoede/dfc1ed93674f53b20086a77df1d56277 to your computer and use it in GitHub Desktop.
npm install -D gulp browserify babelify @babel/core @babel/preset-env vinyl-source-stream vinyl-buffer gulp-uglify gulp-htmlmin cssnano gulp-postcss del
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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