Skip to content

Instantly share code, notes, and snippets.

@sturobson
Created March 19, 2015 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturobson/9a616c2cbebfc5059bf3 to your computer and use it in GitHub Desktop.
Save sturobson/9a616c2cbebfc5059bf3 to your computer and use it in GitHub Desktop.
gulpfil.js
var gulp = require('gulp'),
sass = require('gulp-sass'),
rename = require('gulp-rename'),
cssmin = require('gulp-minify-css'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
cache = require('gulp-cached'),
prefix = require('gulp-autoprefixer'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
minifyHTML = require('gulp-minify-html'),
size = require('gulp-size'),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
plumber = require('gulp-plumber'),
notify = require('gulp-notify'),
connect = require('gulp-connect-php');
gulp.task('scss', function() {
var onError = function(err) {
notify.onError({
title: "Gulp",
subtitle: "Failure!",
message: "Error: <%= error.message %>",
sound: "Beep"
})(err);
this.emit('end');
};
return gulp.src('scss/main.scss')
.pipe(plumber({errorHandler: onError}))
.pipe(sass())
.pipe(size({ gzip: true, showFiles: true }))
.pipe(prefix())
.pipe(rename('main.css'))
.pipe(gulp.dest('dist/css'))
.pipe(reload({stream:true}))
.pipe(cssmin())
.pipe(size({ gzip: true, showFiles: true }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/css'))
});
gulp.task('connect-sync', function() {
connect.server({}, function(){
browserSync({
proxy: 'localhost:8000'
});
});
})
gulp.task('deploy', function () {
return gulp.src('dist/**/*')
.pipe(deploy());
});
gulp.task('js', function() {
gulp.src('js/*.js')
.pipe(uglify())
.pipe(size({ gzip: true, showFiles: true }))
.pipe(concat('j.js'))
.pipe(gulp.dest('dist/js'))
.pipe(reload({stream:true}));
});
gulp.task('minify-html', function() {
var opts = {
comments:true,
spare:true
};
gulp.src('./*.php')
.pipe(minifyHTML(opts))
.pipe(gulp.dest('dist/'))
.pipe(reload({stream:true}));
});
gulp.task('watch', function() {
gulp.watch('scss/**/*.scss', ['scss']);
gulp.watch('js/*.js', ['js']);
gulp.watch('./*.php', ['minify-html']);
gulp.watch('img/*', ['imgmin']);
});
gulp.task('imgmin', function () {
return gulp.src('img/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest('dist/img'));
});
gulp.task('default', ['js', 'imgmin', 'minify-html', 'scss', 'watch', 'connect-sync']);
@sturobson
Copy link
Author

For some reason when it's running it's looking for CSS/JS files in the route and I want it to look for them in DIST/ most things I'm trying aren't working...

@seanislegend
Copy link

What's the folder structure?

@sturobson
Copy link
Author

the folder structure is

design patterns

  • gulpfiles.js
  • package.json
  • index.php
  • scss
  • img
  • dist
  • dist / css
  • dist / img

etc, does that make sense?

@bvdputte
Copy link

use "base: 'dist' option inside gulp.task('connect-sync', function(), no?

https://www.npmjs.com/package/gulp-connect-php

@steverydz
Copy link

Does this not work?

gulp.task('connect-sync', function() {
  connect.server({
    base: './dist'
  }, function(){
...

@sturobson
Copy link
Author

Hey Steve that doesn't seem to want to do anything. Adding /dist after localhost:8000 kinda works (I've got a php error because I'm minifying but that's something else.

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