A
A
Andrey Dyrkov2015-04-01 18:52:24
gulp.js
Andrey Dyrkov, 2015-04-01 18:52:24

Help writing gulp config.?

I'm writing a config for my project and I can't figure it out.

  • there is gulp default - it compiles everything, minimizes hangs watch and uses connect
  • there is gulp build - it should clean the dist folder and rebuild the project without watch and connect

But in one task this does not work, you have to constantly write clear and then only build.
I want to be able to build the project so that dist contains the folders and files I need (if folders are created using preprocessors only for them, but what about pictures and fonts?) and all this in one task.
How to do it?
Here is my source...
var gulp = require('gulp'),
  concatCSS = require('gulp-concat-css'),
  minifyCSS = require('gulp-minify-css'),
  rename = require('gulp-rename'),
  sass = require('gulp-sass'),
  jsmin = require('gulp-jsmin'),
  jade = require('gulp-jade'),
  clean = require('gulp-clean'),
  connect = require('gulp-connect'),
  //folder app
  app = './dist/';

//DEFAULT TASK
gulp.task('default',[
            'watch',
            'css',
            'scripts',
            'jade',
            'connect'
          ]
);

//
//connect
//
gulp.task('connect',function(){
  connect.server({
            livereload:true,
            root:app
          });
});



//build
gulp.task('build',[
            'clear',//выдаёт ошибку(если его нету то всё ок)
            'jade',
            'css',
            'scripts',
            'removefonts',
            'removeimage'
          ]);
//clear dist
gulp.task('clear',function(){
  return gulp.src(app+'*',{read:false})
    .pipe(clean());
});



//
//remove folders
//

gulp.task('removefonts',function(){
  gulp.src('fonts/*')
    .pipe(gulp.dest(app+'fonts/'));
});
gulp.task('removeimage',function(){
  gulp.src('images/*.*')
    .pipe(gulp.dest(app+'images/'));
});


//
//css
//
gulp.task('css',function(){
  gulp.src('sass/*.scss')
    .pipe(sass())
    .pipe(concatCSS('style.css'))
    .pipe(minifyCSS())
    .pipe(rename('style.min.css'))
    .pipe(gulp.dest(app+'css/'))
    .pipe(connect.reload());
});

//
//scripts minify and rename
//
gulp.task('scripts',function(){
  gulp.src('js/*.js')
    .pipe(jsmin())
    .pipe(rename({suffix: '.min'}))
    .pipe(gulp.dest(app+'js/'));
});

//
//conver jade to html
//
gulp.task('jade',function(){
  gulp.src('jade/*.jade')
    .pipe(jade())
    .pipe(gulp.dest(app))
    .pipe(connect.reload());
});

//
// watch files
//
gulp.task('watch',function(){
  gulp.watch('sass/*.scss',['css']);
  gulp.watch('js/*.js',['scripts']);
  gulp.watch('jade/*.jade',['jade']);
});



// command list
/*

gulp - компилирует jade,sass; минифицирует js; смотрит за изменениями в файлах и создаёт сервер
^ использовать для стандартной работы с файлами

gulp build - чистит dist и пересобирает проект
 ^ использовать если в проекте произошли важные изменения
...

*/

if it comes in handy, it gives this error, I think that clear simply does not have time to delete ..
b381ce5fcff2461d9ac46b2db30bbc98.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey, 2015-04-01
@VIKINGVyksa

Use run-sequence
https://www.npmjs.com/package/run-sequence
The examples deal with exactly your problem:

gulp.task('build', function(callback) {
  runSequence('build-clean',
              ['build-scripts', 'build-styles'],
              'build-html',
              callback);
});

R
Ruslan, 2015-04-01
@rOOse

Or just do this:

gulp.task('build', ['clean'], function(){
  gulp.start(['jade', 'css', 'js', 'etc']);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question