Skip to content

Instantly share code, notes, and snippets.

@Tam
Last active March 19, 2018 08:50
Show Gist options
  • Save Tam/97618254639c971a79da to your computer and use it in GitHub Desktop.
Save Tam/97618254639c971a79da to your computer and use it in GitHub Desktop.
Minimal Gulp setup w/ LESS +autoprefix/compress, JS +jshint/minify
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']);
{
"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": "*"
}
}
@Tam
Copy link
Author

Tam commented Aug 19, 2016

See Tam/start for the new updated version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment