I'm new to the scene of JavaScript development and am currently in the progress of getting a decent workflow going. I'm having some trouble understanding how Gulp works though. I've installed my dependencies using npm, and written a gulpfile as far as my capabilities goes.
var gulp = require('gulp'),
minifycss = require('gulp-minify-css'),
autoprefixer = require('gulp-autoprefixer'),
uglify = require('gulp-uglify'),
minifyhtml = require('gulp-minify-html'),
sass = require('sass'),
notify = require('gulp-notify');
gulp.task('js', function() {
return gulp.src('js/**/*.js')
.pipe(uglify({
outSourceMap: true
}))
.pipe(gulp.dest('dist/assets/js'));
});
//This task should compile my scss-files into corresponding css-files in the css-folder.
//If possible I would like to have it automatically detect which folder the file is in.
//Ie: scss/user/main.scss should compile to css/user/main.css
gulp.task('sass', function() {
return gulp.src('scss/*.scss')
.pipe(sass())
.pipe(gulp.dest('css'));
});
gulp.task('css', function() {
return gulp.src('css/*.css')
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(minifycss())
.pipe(gulp.dest('dist/assets/css'));
});
//This task should check all html-files in directory, and then minify them into corresponding folders in dist/assets/html.
//Ie: html/user/index.html should be minified into dist/assets/html/user/index.html.
gulp.task('html', function() {
return gulp.src('html/*/*.html')
.pipe(minifyhtml())
.pipe(gulp.dest('dist/assets/html'));
});
//I know run() is depreceated. What to do? How should these be written?
gulp.task('default', function() {
gulp.watch('scss/*.scss', function() {
gulp.run('sass')
});
gulp.watch(['html/user/*.html', 'html/support/*.html'], function() {
gulp.run('html');
});
gulp.watch('js/**/*.js', function() {
gulp.run('js');
});
gulp.watch('css/*.css', function() {
gulp.run('css');
});
});
It doesn't really work as I want to though, and googling while not knowing what to search for is really hard. I've read several blogs, but unfortunately haven't been able to grasp how to do it. I'm aware that I shouldn't use run(), but how should I be writing the code then?
If someone could explain what a dependency actually is, in plain English, I would be really grateful. At sea on this one as well.
Thanks for taking the time.
Anton
gulp.watchwithout using run. Gulp is relatively new, and still under development. You need to be willing to read a lot of source code to use it. This is the wrong place for "I'm new, help me" questions. Try Reddit or another forum-like environment.