Created
February 7, 2017 02:40
-
-
Save narenaryan/481cbbed9795330ef0003a9135e4932d to your computer and use it in GitHub Desktop.
A sample gulp file with minifies and watchers
This file contains hidden or 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
| var gulp = require("gulp"); | |
| var minifyHtml = require("gulp-minify-html"); | |
| var minifyCss = require("gulp-minify-css"); | |
| var uglify = require("gulp-uglify"); | |
| var concat = require("gulp-concat"); | |
| var paths = { | |
| scripts: "src/js/*.js", | |
| styles: "src/css/*.css", | |
| html: "src/*.html" | |
| } | |
| gulp.task("minify-html", function(){ | |
| gulp.src(paths.html) | |
| .pipe(minifyHtml()) | |
| .pipe(gulp.dest('.')); | |
| }); | |
| gulp.task("merge-minify-js", function(){ | |
| gulp.src(paths.scripts) | |
| .pipe(concat("main.min.js")) | |
| .pipe(uglify()) | |
| .pipe(gulp.dest("build/js")); | |
| }); | |
| gulp.task("merge-minify-css", function(){ | |
| gulp.src(paths.styles) | |
| .pipe(concat("custom.min.css")) | |
| .pipe(minifyCss()) | |
| .pipe(gulp.dest("build/css")); | |
| }); | |
| // Rerun the task when a file changes | |
| gulp.task('watch', function() { | |
| gulp.watch(paths.scripts, ['merge-minify-js']); | |
| gulp.watch(paths.styles, ['merge-minify-css']); | |
| gulp.watch(paths.html, ['minify-html']); | |
| }); | |
| gulp.task("default", ["watch", "minify-html", "merge-minify-js", "merge-minify-css"]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment