Skip to content

Instantly share code, notes, and snippets.

@kukac7
Last active August 29, 2015 14:10
Show Gist options
  • Save kukac7/879a7a0b30b5bfe1c26f to your computer and use it in GitHub Desktop.
Save kukac7/879a7a0b30b5bfe1c26f to your computer and use it in GitHub Desktop.
gulp
var gulp = require('gulp'),
del = require('del'),
uglify = require('gulp-uglify'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
ngAnnotate = require('gulp-ng-annotate'),
inject = require('gulp-inject'),
useref = require('gulp-useref'),
rev = require('gulp-rev'),
revReplace = require('gulp-rev-replace'),
filter = require('gulp-filter');
gulp.task('clean', function(cb) {
del('dist', cb);
});
gulp.task('style', function() {
return gulp.src('src/scss/**/*.scss')
.pipe(sass({style: 'compressed'}))
.pipe(autoprefixer('last 2 versions'))
.pipe(gulp.dest('.tmp'));
});
gulp.task('script', function() {
return gulp.src('src/js/**/*.js')
.pipe(gulp.dest('.tmp'));
});
gulp.task('inject', function() {
var target = gulp.src('src/index.html'),
sources = gulp.src(['.tmp/**/*.js', '.tmp/**/*.css'], {read: false});
return target
.pipe(inject(sources, {
addRootSlash: false
}))
.pipe(gulp.dest('src'));
});
gulp.task('useref', ['clean'], function() {
var assets = useref.assets();
return gulp.src('src/index.html')
.pipe(assets)
.pipe(assets.restore())
.pipe(useref())
.pipe(gulp.dest('dist'));
});
gulp.task('index', ['clean'], function() {
var jsFilter = filter('**/*.js'),
cssFilter = filter('**/*.css');
var assets = useref.assets();
return gulp.src('src/index.html')
.pipe(assets)
.pipe(rev())
.pipe(jsFilter)
.pipe(ngAnnotate())
.pipe(uglify({
compress: {
drop_console: true
}
}))
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe(cssFilter.restore())
.pipe(assets.restore())
.pipe(useref())
.pipe(revReplace())
.pipe(gulp.dest('dist'));
});
gulp.task('dev',['clean'], function() {
gulp.start('style', 'script', 'inject', 'index');
});
{
"name": "gulpteszt",
"version": "0.0.0",
"dependencies": {},
"devDependencies": {
"del": "~0.1.3",
"gulp": "~3.8.10",
"gulp-ng-annotate": "~0.3.6",
"gulp-rev": "~2.0.1",
"gulp-rev-replace": "~0.3.1",
"gulp-ruby-sass": "~0.7.1",
"gulp-uglify": "~1.0.1",
"gulp-useref": "~1.0.2",
"gulp-filter": "~1.0.2",
"gulp-inject": "~1.0.2",
"gulp-autoprefixer": "~2.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment