Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var gulp = require('gulp'),
- util = require('gulp-util'),
- del = require('del'),
- concat = require('gulp-concat'),
- sourcemaps = require('gulp-sourcemaps'),
- changed = require('gulp-changed'),
- cached = require('gulp-cached'),
- remember = require('gulp-remember'),
- newer = require('gulp-newer'),
- rev = require('gulp-rev'),
- sync = require('browser-sync').create(),
- uglify = require('gulp-uglify'),
- jshint = require('gulp-jshint'),
- prefix = require('gulp-autoprefixer'),
- minifycss = require('gulp-minify-css'),
- imagemin = require('gulp-imagemin'),
- pngquant = require('imagemin-pngquant');
- var src = {
- markup: ['./views/**/*.html'],
- scripts: ['./assets/js/**/*.js'],
- styles: ['./assets/css/**/*.css'],
- images: './assets/img/**/*',
- fav: ['./assets/*.ico', './assets/*.png'],
- other: ['./assets/*.xml', './assets/*.txt'],
- modernizr: './bower_components/modernizer/modernizr.js',
- jquery: './bower_components/jquery/dist/jquery.min.js',
- normalize: './bower_components/normalize-css/normalize.css'
- };
- var dist = {
- scripts: './public/js',
- styles: './public/css',
- images: './public/img',
- root: './public'
- }
- gulp.task('clean', function() {
- return del(dist.root);
- });
- gulp.task('markup', function() {
- return gulp.src(src.markup)
- .pipe(gulp.dest(dist.root));
- });
- gulp.task('modernizr', function() {
- return gulp.src(src.modernizr)
- .pipe(uglify())
- .pipe(gulp.dest(dist.scripts));
- });
- gulp.task('jquery', function() {
- return gulp.src(src.jquery)
- .pipe(gulp.dest(dist.scripts));
- });
- gulp.task('scripts', function() {
- return gulp.src(src.scripts)
- //.pipe(changed('public'))
- .pipe(jshint())
- .pipe(jshint.reporter('jshint-stylish'))
- .pipe(jshint.reporter('fail'))
- //.pipe(sourcemaps.init())
- .pipe(uglify())
- .pipe(concat('scripts.js'))
- //.pipe(util.env.type === 'production' ? uglify() : util.noop())
- //.pipe(sourcemaps.write())
- .pipe(gulp.dest(dist.scripts));
- });
- gulp.task('normalize', function() {
- return gulp.src(src.normalize)
- .pipe(minifycss())
- .pipe(gulp.dest(dist.styles));
- })
- gulp.task('styles', function() {
- return gulp.src(src.styles)
- //.pipe(sourcemaps.init())
- .pipe(minifycss({compatibility: 'ie8'}))
- .pipe(concat('styles.css'))
- .pipe(prefix({
- browsers: ['last 2 version'],
- cascade: false
- }))
- //.pipe(sourcemaps.write())
- .pipe(gulp.dest(dist.styles));
- });
- gulp.task('images', function() {
- return gulp.src(src.images)
- .pipe(imagemin({
- optimizationLevel: 5,
- progressive: true,
- interlaced: true,
- multipass: true,
- svgoPlugins: [{removeViewBox: false}],
- use: [pngquant()]
- }))
- .pipe(gulp.dest(dist.images));
- });
- gulp.task('fav', function() {
- return gulp.src(src.fav)
- .pipe(imagemin({
- optimizationLevel: 5,
- use: [pngquant()]
- }))
- .pipe(gulp.dest(dist.root));
- });
- gulp.task('other', function() {
- return gulp.src(src.other)
- .pipe(gulp.dest(dist.root));
- });
- gulp.task('markup-watch', ['markup'], sync.reload);
- gulp.task('scripts-watch', ['scripts'], sync.reload);
- gulp.task('styles-watch', ['styles'], sync.reload);
- gulp.task('images-watch', ['images'], sync.reload);
- gulp.task('fav-watch', ['fav'], sync.reload);
- gulp.task('other-watch', ['other'], sync.reload);
- gulp.task('build', ['clean', 'markup', 'modernizr', 'jquery', 'scripts', 'normalize', 'styles', 'images', 'fav', 'other']);
- gulp.task('serve', ['build'], function() {
- sync.init({
- notify: false,
- port: 8080,
- server: {
- baseDir: dist.root
- }
- });
- /*
- gulp.watch(src.markup, ['markup-watch']);
- gulp.watch(src.scripts, ['scripts-watch']);
- gulp.watch(src.styles, ['styles-watch']);
- gulp.watch(src.images, ['images-watch']);
- gulp.watch(src.fav, ['fav-watch']);
- gulp.watch(src.other, ['other-watch']);
- */
- gulp.watch(src.markup).on('change', sync.reload);
- gulp.watch(src.scripts).on('change', sync.reload);
- gulp.watch(src.styles).on('change', sync.reload);
- gulp.watch(src.images).on('change', sync.reload);
- gulp.watch(src.fav).on('change', sync.reload);
- gulp.watch(src.other).on('change', sync.reload);
- });
- gulp.task('default', ['serve']);
Advertisement
Add Comment
Please, Sign In to add comment