https://github.com/radiovisual/gulp-recipes
A collection of some useful gulp tasks
https://github.com/radiovisual/gulp-recipes
gulp-recipes gulp-tasks
Last synced: 5 months ago
JSON representation
A collection of some useful gulp tasks
- Host: GitHub
- URL: https://github.com/radiovisual/gulp-recipes
- Owner: radiovisual
- License: unlicense
- Created: 2016-09-30T11:10:51.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-01T15:07:40.000Z (over 9 years ago)
- Last Synced: 2025-02-04T17:50:28.603Z (over 1 year ago)
- Topics: gulp-recipes, gulp-tasks
- Size: 2.93 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gulp-recipes
> A collection of some useful gulp tasks.
:boom: :tropical_drink:
All of these snippets are for reference only. If you copy-paste you will almost certainly need to tweak things like the file paths, globs, etc.
### Concatenate/minify JavaScript dependencies
```js
var uglify = require('gulp-uglify');
gulp.task('build-deps', function() {
console.log('building dependencies to file: ./src/js/vendor/build/dependencies.min.js');
return gulp.src(['./dist/js/vendor/*.js'])
.pipe(uglify({
preserveComments: 'license'
}))
.pipe(concat('dependencies.min.js'))
.pipe(gulp.dest('./dist/js/vendor/build/'));
});
```
### Reload browser when dependencies have changed
```js
var browserSync = require('browser-sync').create();
gulp.task('browser-sync', function () {
browserSync.init({
server: {
baseDir: './dist'
}
});
gulp.watch(['./dist/*.html'], ['reload']);
gulp.watch(['./dist/css/*.css'], ['reload']);
gulp.watch(['./dist/js/*.js'], ['reload']);
});
gulp.task('reload', function () {
browserSync.reload();
});
```
### Upload project files via FTP
```js
var ftp = require( 'vinyl-ftp' );
gulp.task('ftp', function () {
var conn = ftp.create({
host: process.env.FTP_HOST,
user: process.env.FTP_USER,
password: process.env.FTP_PASS,
parallel: 2,
log: gutil.log
});
var globs = [
'dist/css/**/*',
'dist/js/**/*.js',
'dist/img/**/*',
'dist/.htaccess'
];
// using base = '.' will transfer everything to /public_html correctly
// turn off buffering in gulp.src for best performance
return gulp.src(globs, {base: '.', buffer: false})
.pipe(conn.newer( '/' )) // only upload newer files
.pipe(conn.dest( '/' ));
});
```
### Convert SASS to CSS
```js
var uglifycss = require('gulp-uglifycss');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
gulp.task('sass', function () {
return gulp.src(['./dist/sass/*.scss', '!./dist/sass/mixins.scss', '!./dist/sass/print.scss'])
.pipe(sass().on('error', sass.logError))
.pipe(uglifycss({
"maxLineLen": 80,
"uglyComments": true
}))
.pipe(concat('styles.min.css'))
.pipe(gulp.dest('./dist/css'));
});
```
### Convert all markdown files to html
```js
var gulp = require('gulp');
var wrapper = require('gulp-wrapper');
var markdown = require('gulp-markdown');
var html = {
header: '',
footer: ''
}
gulp.task('build-html', function () {
return gulp.src(files)
.pipe(markdown({gfm: true}))
.pipe(wrapper({
header: html.header,
footer: html.footer
}))
.pipe(gulp.dest('build/html'));
});
```
### Convert all markdown files to pdf
```js
var gulp = require('gulp');
var markdownpdf = require('gulp-markdown-pdf');
gulp.task('build-pdfs', ['build-html'], function () {
return gulp.src(files)
.pipe(markdownpdf({
cssPath: 'dependencies/pdf.css'
}))
.pipe(gulp.dest('build/pdf'));
});
```
### Concatenate all markdown files into a single html file
```js
var concat = require('gulp-concat');
var markdown = require('gulp-markdown');
var wrapper = require('gulp-wrapper');
gulp.task('concat-html', function() {
return gulp.src(files)
.pipe(concat('00-all-documents.md'))
.pipe(markdown({gfm: true}))
.pipe(wrapper({
header: html.header,
footer: html.footer
}))
.pipe(gulp.dest('build/html'));
});
```
### Concatenate all markdown files into a single pdf file
```js
var concat = require('gulp-concat');
var markdownpdf = require('gulp-markdown-pdf');
gulp.task('concat-pdf', function() {
return gulp.src('*.md')
.pipe(concat('00-all-documents.md'))
.pipe(markdownpdf({
cssPath: 'dependencies/pdf.css'
}))
.pipe(gulp.dest('build/pdf'));
});
```
### Copy folder from one location to another
```js
gulp.task('copy-dependencies', function() {
return gulp.src(['dependencies/**/*']).pipe(gulp.dest('build/html/dependencies'));
});
```