Last active
March 19, 2018 08:50
-
-
Save Tam/97618254639c971a79da to your computer and use it in GitHub Desktop.
Minimal Gulp setup w/ LESS +autoprefix/compress, JS +jshint/minify
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
var gulp = require('gulp'), | |
sourcemaps = require('gulp-sourcemaps'), | |
uglify = require("gulp-uglify"), | |
jshint = require("gulp-jshint"), | |
rename = require("gulp-rename"), | |
less = require("gulp-less"), | |
LessPluginCleanCSS = require('less-plugin-clean-css'), | |
cleancss = new LessPluginCleanCSS({ advanced: true }), | |
LessPluginAutoPrefix = require('less-plugin-autoprefix'), | |
autoprefixer = new LessPluginAutoPrefix({ browsers: ["last 2 versions"] }); | |
// JS | |
gulp.task('js', function () { | |
gulp.src(['public/assets/js/**/*.js', '!public/assets/js/**/*.min.js']) | |
.pipe(sourcemaps.init()) | |
.pipe(jshint()) | |
.pipe(jshint.reporter()) | |
.pipe(uglify().on('error', function(err){ console.log(err.message); })) | |
.pipe(rename({ suffix: ".min" })) | |
.pipe(sourcemaps.write(".")) | |
.pipe(gulp.dest('public/assets/js')); | |
}); | |
// Less | |
gulp.task('less', function () { | |
gulp.src('public/assets/less/style.less') | |
.pipe(less({ | |
plugins: [autoprefixer, cleancss] | |
}).on('error', function(err){ console.log(err.message); })) | |
.pipe(gulp.dest('public/assets/css')); | |
}); | |
// Watchers | |
gulp.task('watch', function () { | |
gulp.watch(['public/assets/js/**/*.js', '!public/assets/js/**/*.min.js'], ['js']); | |
gulp.watch(['public/assets/less/**/*'], ['less']); | |
}); | |
gulp.task('default', ['watch']); |
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
{ | |
"name": "tam-gulp", | |
"version": "0.0.1", | |
"devDependencies": { | |
"gulp": "*", | |
"jshint": "*", | |
"gulp-sourcemaps": "*", | |
"gulp-jshint": "*", | |
"gulp-less": "*", | |
"gulp-rename": "*", | |
"gulp-uglify": "*", | |
"gulp-util": "*", | |
"less-plugin-autoprefix": "*", | |
"less-plugin-clean-css": "*" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See Tam/start for the new updated version