Answer the question
In order to leave comments, you need to log in
Gulp.js - why is the project structure not created immediately?
Briefly the essence of the problem. There are two tasks in task default:
1) First, bootstrap.min.js is built from only the required libraries and placed in the dist directory in the project root
2) Then two style files are built. Their final path is in dist/file1 and dist/file2 respectively.
Before starting, I delete the dist directory, run the task - only the dist folder with the bootstrap is created and that's it. I repeat the task - folders file1 and file2 appear with styles. The console shows that on the first and second runs, both tasks included in default were completed successfully. Then why does the full assembly take place only the second time?
Without deleting the dist folder before running, the situation is the same - first .js, after re-executing the styles folder.
Who faced?
/*Default Task==================================================*/
gulp.task('default', ['getbootjs','getshopcss','getbtbcss'], function() {});
/*==============================================================*/
/*Bootstrap JS Build==============================================*/
gulp.task('getbootjs', function () {
gulp.src(
'src/bootstrap/js/button.js'
//,'src/bootstrap/js/affix.js'
//,'src/bootstrap/js/alert.js'
//,'src/bootstrap/js/carousel.js'
//,'src/bootstrap/js/collapse.js'
//,'src/bootstrap/js/dropdown.js'
//,'src/bootstrap/js/modal.js'
//,'src/bootstrap/js/popover.js'
//,'src/bootstrap/js/scrollspy.js'
//,'src/bootstrap/js/tab.js'
//,'src/bootstrap/js/tooltip.js'
//,'src/bootstrap/js/transition.js'
)
.pipe(concat('bootstrap.js'))
.pipe(gulp.dest('dist/'));
});
/*==============================================================*/
/*SHOP CSS Min Build============================================*/
gulp.task('getshopcss', function() {
gulp.src('src/projects/shop/shop.less')
.pipe(less())
.pipe(gulp.dest('build/'))
.pipe(autoprefixer('last 3 versions'))
gulp.src(
'build/shop.css'
//,'src/plugins/css/plugin.css'
)
.pipe(concat('shop-plugins.css'))
.pipe(cssmin())
.pipe(rename('styles.css'))
.pipe(gulp.dest('dist/shop/'))
.pipe(connect.reload());
});
/*==============================================================*/
/*BTB CSS Min Build=============================================*/
gulp.task('getbtbcss', function() {
gulp.src('src/projects/btb/btb.less')
.pipe(less())
.pipe(gulp.dest('build/'))
.pipe(autoprefixer('last 3 versions'))
gulp.src(
'build/btb.css'
//,'src/plugins/css/plugin.css'
)
.pipe(concat('btb-plugins.css'))
.pipe(cssmin())
.pipe(rename('styles.css'))
.pipe(gulp.dest('dist/btb/'))
.pipe(connect.reload());
});
/*=================================================================*/
/*SHOP CSS Min Build============================================*/
gulp.task('getshopless', function() {
return gulp.src('./src/projects/shop/shop.less')
.pipe(less())
.pipe(gulp.dest('./build/css/'));
});
gulp.task('getshopplugins',['getshopless'], function() {
return gulp.src([
'src/plugins/css/plugin.css',
'src/plugins/css/plugin2.css'
])
.pipe(concat('shop-plugins.css'))
.pipe(gulp.dest('./build/css/'));
});
gulp.task('getshopstyles',['getshopplugins'], function() {
return gulp.src('./build/css/*.css')
.pipe(concat('shop-styles.css'))
.pipe(autoprefixer('last 15 versions'))
.pipe(cssmin())
.pipe(rename('styles.min.css'))
.pipe(gulp.dest('./dist/shop/'))
});
/*==============================================================*/
Answer the question
In order to leave comments, you need to log in
um... read the documentation about the done callback, about the fact that you can return a pipe from a task (it will work as a promise), split the getbtbcss task into two and write down the dependencies...
In short, you have a problem with the fact that the tasks are executed asynchronously, and you don't tell gulp when you're done with what and when you can start the next one.
/*Default Task==================================================*/
gulp.task('default', function() {
gulp.run(['getbootjs','getshopcss','getbtbcss']);
});
/*==============================================================*/
/*Bootstrap JS Build==============================================*/
gulp.task('getbootjs', function () {
return gulp.src('src/bootstrap/js/*.js')
.pipe(concat('bootstrap.js'))
.pipe(gulp.dest('dist/'))
.pipe(connect.reload());
});
/*==============================================================*/
/*SHOP CSS Min Build============================================*/
gulp.task('getshopcss', function() {
return gulp.src('src/projects/shop/shop.less')
.pipe(less())
.pipe(gulp.dest('build/'))
.pipe(autoprefixer('last 3 versions'))
.pipe(cssmin())
.pipe(rename('styles.css'))
.pipe(gulp.dest('dist/shop/'))
.pipe(connect.reload());
});
/*==============================================================*/
/*BTB CSS Min Build=============================================*/
gulp.task('getbtbcss', function() {
return gulp.src('src/projects/btb/btb.less')
.pipe(less())
.pipe(gulp.dest('build/'))
.pipe(autoprefixer('last 3 versions'))
.pipe(cssmin())
.pipe(rename('styles.css'))
.pipe(gulp.dest('dist/btb/'))
.pipe(connect.reload());
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question