Skip to content

Instantly share code, notes, and snippets.

@Insayt
Last active August 20, 2024 21:07
Show Gist options
  • Select an option

  • Save Insayt/272c9b81936a03884768 to your computer and use it in GitHub Desktop.

Select an option

Save Insayt/272c9b81936a03884768 to your computer and use it in GitHub Desktop.

Revisions

  1. Alex Insayt revised this gist Mar 13, 2015. 1 changed file with 35 additions and 35 deletions.
    70 changes: 35 additions & 35 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -4,15 +4,15 @@ var gulp = require('gulp'),
    watch = require('gulp-watch'),
    prefixer = require('gulp-autoprefixer'),
    uglify = require('gulp-uglify'),
    cssmin = require('gulp-cssmin'),
    sass = require('gulp-sass'),
    sourcemaps = require('gulp-sourcemaps'),
    rigger = require('gulp-rigger'),
    cssmin = require('gulp-minify-css'),
    imagemin = require('gulp-imagemin'),
    pngquant = require('imagemin-pngquant'),
    clean = require('gulp-clean'),
    connect = require('gulp-connect'),
    opn = require('opn');
    rimraf = require('rimraf'),
    browserSync = require("browser-sync"),
    reload = browserSync.reload;

    var path = {
    build: {
    @@ -36,68 +36,68 @@ var path = {
    img: 'src/img/**/*.*',
    fonts: 'src/fonts/**/*.*'
    },
    clean: 'build/'
    clean: './build'
    };

    var server = {
    var config = {
    server: {
    baseDir: "./build"
    },
    tunnel: true,
    host: 'localhost',
    port: '8001'
    port: 9000,
    logPrefix: "Frontend_Devil"
    };

    gulp.task('clean', function () {
    return gulp.src(path.clean, {read: false})
    .pipe(clean());
    });

    gulp.task('webserver', function() {
    connect.server({
    host: server.host,
    port: server.port,
    livereload: true
    });
    gulp.task('webserver', function () {
    browserSync(config);
    });

    gulp.task('openbrowser', function() {
    opn( 'http://' + server.host + ':' + server.port + '/build' );
    gulp.task('clean', function (cb) {
    rimraf(path.clean, cb);
    });

    gulp.task('html:build', function () {
    gulp.src(path.src.html)
    gulp.src(path.src.html)
    .pipe(rigger())
    .pipe(gulp.dest(path.build.html))
    .pipe(connect.reload());
    .pipe(reload({stream: true}));
    });

    gulp.task('js:build', function () {
    gulp.src(path.src.js)
    .pipe(rigger())
    .pipe(sourcemaps.init())
    .pipe(uglify())
    .pipe(sourcemaps.write())
    gulp.src(path.src.js)
    .pipe(rigger())
    .pipe(sourcemaps.init())
    .pipe(uglify())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest(path.build.js))
    .pipe(connect.reload());
    .pipe(reload({stream: true}));
    });

    gulp.task('style:build', function () {
    gulp.src(path.src.style)
    gulp.src(path.src.style)
    .pipe(sourcemaps.init())
    .pipe(sass())
    .pipe(sass({
    sourceMap: true,
    errLogToConsole: true
    }))
    .pipe(prefixer())
    .pipe(cssmin())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest(path.build.css))
    .pipe(connect.reload());
    .pipe(reload({stream: true}));
    });

    gulp.task('image:build', function () {
    gulp.src(path.src.img)
    gulp.src(path.src.img)
    .pipe(imagemin({
    progressive: true,
    svgoPlugins: [{removeViewBox: false}],
    use: [pngquant()]
    use: [pngquant()],
    interlaced: true
    }))
    .pipe(gulp.dest(path.build.img))
    .pipe(connect.reload());
    .pipe(reload({stream: true}));
    });

    gulp.task('fonts:build', function() {
    @@ -133,4 +133,4 @@ gulp.task('watch', function(){
    });


    gulp.task('default', ['build', 'webserver', 'watch', 'openbrowser']);
    gulp.task('default', ['build', 'webserver', 'watch']);
  2. Alex Insayt renamed this gist Feb 14, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. Alex Insayt renamed this gist Feb 12, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. Alex Insayt created this gist Feb 12, 2015.
    136 changes: 136 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,136 @@
    'use strict';

    var gulp = require('gulp'),
    watch = require('gulp-watch'),
    prefixer = require('gulp-autoprefixer'),
    uglify = require('gulp-uglify'),
    cssmin = require('gulp-cssmin'),
    sass = require('gulp-sass'),
    sourcemaps = require('gulp-sourcemaps'),
    rigger = require('gulp-rigger'),
    imagemin = require('gulp-imagemin'),
    pngquant = require('imagemin-pngquant'),
    clean = require('gulp-clean'),
    connect = require('gulp-connect'),
    opn = require('opn');

    var path = {
    build: {
    html: 'build/',
    js: 'build/js/',
    css: 'build/css/',
    img: 'build/img/',
    fonts: 'build/fonts/'
    },
    src: {
    html: 'src/*.html',
    js: 'src/js/main.js',
    style: 'src/style/main.scss',
    img: 'src/img/**/*.*',
    fonts: 'src/fonts/**/*.*'
    },
    watch: {
    html: 'src/**/*.html',
    js: 'src/js/**/*.js',
    style: 'src/style/**/*.scss',
    img: 'src/img/**/*.*',
    fonts: 'src/fonts/**/*.*'
    },
    clean: 'build/'
    };

    var server = {
    host: 'localhost',
    port: '8001'
    };

    gulp.task('clean', function () {
    return gulp.src(path.clean, {read: false})
    .pipe(clean());
    });

    gulp.task('webserver', function() {
    connect.server({
    host: server.host,
    port: server.port,
    livereload: true
    });
    });

    gulp.task('openbrowser', function() {
    opn( 'http://' + server.host + ':' + server.port + '/build' );
    });

    gulp.task('html:build', function () {
    gulp.src(path.src.html)
    .pipe(rigger())
    .pipe(gulp.dest(path.build.html))
    .pipe(connect.reload());
    });

    gulp.task('js:build', function () {
    gulp.src(path.src.js)
    .pipe(rigger())
    .pipe(sourcemaps.init())
    .pipe(uglify())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest(path.build.js))
    .pipe(connect.reload());
    });

    gulp.task('style:build', function () {
    gulp.src(path.src.style)
    .pipe(sourcemaps.init())
    .pipe(sass())
    .pipe(prefixer())
    .pipe(cssmin())
    .pipe(sourcemaps.write())
    .pipe(gulp.dest(path.build.css))
    .pipe(connect.reload());
    });

    gulp.task('image:build', function () {
    gulp.src(path.src.img)
    .pipe(imagemin({
    progressive: true,
    svgoPlugins: [{removeViewBox: false}],
    use: [pngquant()]
    }))
    .pipe(gulp.dest(path.build.img))
    .pipe(connect.reload());
    });

    gulp.task('fonts:build', function() {
    gulp.src(path.src.fonts)
    .pipe(gulp.dest(path.build.fonts))
    });

    gulp.task('build', [
    'html:build',
    'js:build',
    'style:build',
    'fonts:build',
    'image:build'
    ]);


    gulp.task('watch', function(){
    watch([path.watch.html], function(event, cb) {
    gulp.start('html:build');
    });
    watch([path.watch.style], function(event, cb) {
    gulp.start('style:build');
    });
    watch([path.watch.js], function(event, cb) {
    gulp.start('js:build');
    });
    watch([path.watch.img], function(event, cb) {
    gulp.start('image:build');
    });
    watch([path.watch.fonts], function(event, cb) {
    gulp.start('fonts:build');
    });
    });


    gulp.task('default', ['build', 'webserver', 'watch', 'openbrowser']);