Skip to content

Instantly share code, notes, and snippets.

@zwacky
Last active June 5, 2020 22:57
Show Gist options
  • Save zwacky/3c0d3d8919865f8a3fed to your computer and use it in GitHub Desktop.
Save zwacky/3c0d3d8919865f8a3fed to your computer and use it in GitHub Desktop.
Example gulpfile.js to get it going with LESS and AngularJS
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var rimraf = require('rimraf');
var paths = {
less: ['./less/*.less'],
js: ['./js/app/*.js', './js/app/**/*.js'],
jsView: ['./js/app/views/*.html'],
dist: {
css: './public/css/',
js: './public/js/',
jsView: './public/views',
},
vendor: {
css: ['./vendor/twitter/bootstrap/dist/css/bootstrap.min.css'],
js: ['./js/vendor/*.js']
},
test: ['./js/tests/**.js']
};
/**
* removes css- and js-dist folder.
*/
gulp.task('clean', function() {
rimraf.sync(paths.dist.css);
rimraf.sync(paths.dist.js);
})
/**
* compiles less files into css.
*/
gulp.task('less', function() {
gulp.src(paths.less)
.pipe(plugins.concat('layout.css'))
.pipe(plugins.less())
.pipe(plugins.minifyCss())
.pipe(gulp.dest(paths.dist.css));
});
gulp.task('js', function() {
gulp.src(paths.js)
.pipe(plugins.concat('app.js'))
.pipe(plugins.uglify({mangle: false}))
.pipe(gulp.dest(paths.dist.js));
});
gulp.task('js-view', function() {
gulp.src(paths.jsView)
.pipe(gulp.dest(paths.dist.jsView));
});
gulp.task('watch', function() {
gulp.watch(paths.less, ['less', 'dist']);
console.log('watching directory:' + paths.less.join(', '));
gulp.watch(paths.js, ['js', 'dist']);
console.log('watching directory:' + paths.js.join(', '));
gulp.watch(paths.jsView, ['js-view', 'dist']);
console.log('watching directory:' + paths.jsView.join(', '));
});
/**
* copies vendor specific files to the public folder.
*/
gulp.task('vendor', function() {
gulp.src(paths.vendor.css)
.pipe(plugins.concat('vendor.css'))
.pipe(plugins.minifyCss())
.pipe(gulp.dest(paths.dist.css));
gulp.src(paths.vendor.js)
.pipe(plugins.concat('vendor.js'))
.pipe(plugins.uglify({mangle: false}))
.pipe(gulp.dest(paths.dist.js));
});
/**
* tests the testing directory with jasmine.
*/
gulp.task('test', function() {
gulp.src(paths.test)
.pipe(plugins.jasmine());
});
/**
* optimizes the output in terms of minification and concatenation.
*/
gulp.task('dist', function() {
// add some optimizations (?)
});
gulp.task('build', ['clean', 'vendor', 'less', 'js', 'js-view', 'dist']);
gulp.task('default', ['build']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment