gulpfile.js (3030B)
1 var gulp = require('gulp'); 2 var less = require('gulp-less'); 3 var browserSync = require('browser-sync').create(); 4 var header = require('gulp-header'); 5 var cleanCSS = require('gulp-clean-css'); 6 var rename = require("gulp-rename"); 7 var uglify = require('gulp-uglify'); 8 var pkg = require('./package.json'); 9 10 // Set the banner content 11 var banner = ['/*!\n', 12 ' * Start Bootstrap - <%= pkg.title %> v<%= pkg.version %> (<%= pkg.homepage %>)\n', 13 ' * Copyright 2013-' + (new Date()).getFullYear(), ' <%= pkg.author %>\n', 14 ' * Licensed under <%= pkg.license.type %> (<%= pkg.license.url %>)\n', 15 ' */\n', 16 '' 17 ].join(''); 18 19 // Compile LESS files from /less into /css 20 gulp.task('less', function() { 21 return gulp.src('less/new-age.less') 22 .pipe(less()) 23 .pipe(header(banner, { pkg: pkg })) 24 .pipe(gulp.dest('css')) 25 .pipe(browserSync.reload({ 26 stream: true 27 })) 28 }); 29 30 // Minify compiled CSS 31 gulp.task('minify-css', ['less'], function() { 32 return gulp.src('css/new-age.css') 33 .pipe(cleanCSS({ compatibility: 'ie8' })) 34 .pipe(rename({ suffix: '.min' })) 35 .pipe(gulp.dest('css')) 36 .pipe(browserSync.reload({ 37 stream: true 38 })) 39 }); 40 41 // Minify JS 42 gulp.task('minify-js', function() { 43 return gulp.src('js/new-age.js') 44 .pipe(uglify()) 45 .pipe(header(banner, { pkg: pkg })) 46 .pipe(rename({ suffix: '.min' })) 47 .pipe(gulp.dest('js')) 48 .pipe(browserSync.reload({ 49 stream: true 50 })) 51 }); 52 53 // Copy vendor libraries from /node_modules into /vendor 54 gulp.task('copy', function() { 55 gulp.src(['node_modules/bootstrap/dist/**/*', '!**/npm.js', '!**/bootstrap-theme.*', '!**/*.map']) 56 .pipe(gulp.dest('vendor/bootstrap')) 57 58 gulp.src(['node_modules/jquery/dist/jquery.js', 'node_modules/jquery/dist/jquery.min.js']) 59 .pipe(gulp.dest('vendor/jquery')) 60 61 gulp.src(['node_modules/simple-line-icons/*/*']) 62 .pipe(gulp.dest('vendor/simple-line-icons')) 63 64 65 gulp.src([ 66 'node_modules/font-awesome/**', 67 '!node_modules/font-awesome/**/*.map', 68 '!node_modules/font-awesome/.npmignore', 69 '!node_modules/font-awesome/*.txt', 70 '!node_modules/font-awesome/*.md', 71 '!node_modules/font-awesome/*.json' 72 ]) 73 .pipe(gulp.dest('vendor/font-awesome')) 74 }) 75 76 // Run everything 77 gulp.task('default', ['less', 'minify-css', 'minify-js', 'copy']); 78 79 // Configure the browserSync task 80 gulp.task('browserSync', function() { 81 browserSync.init({ 82 server: { 83 baseDir: '' 84 }, 85 }) 86 }) 87 88 // Dev task with browserSync 89 gulp.task('dev', ['browserSync', 'less', 'minify-css', 'minify-js'], function() { 90 gulp.watch('less/*.less', ['less']); 91 gulp.watch('css/*.css', ['minify-css']); 92 gulp.watch('js/*.js', ['minify-js']); 93 // Reloads the browser whenever HTML or JS files change 94 gulp.watch('*.html', browserSync.reload); 95 gulp.watch('js/**/*.js', browserSync.reload); 96 });