I'm trying to ignore a folder within a gulp task, but it doesn't seem to work.
Here are the different tests I have done: all without success: the files are copied into the destination folder.
gulp.task('dev', function () {
return gulp.src([
//sources
'./src/**/*',
// first test
'!src/*views/*',
// second test
'!src/**views/'
])
.pipe(cleanDest('./dev/'))
//destination
.pipe(gulp.dest('./dev/'));
});
Has anyone of you ever encountered the problem and managed to work around it / solve it?
Thank you in advance for your help
Assuming they are .js files the below works for me:
return gulp.src(['./src/!(*views)/*.js'])
this will ignore the folder views.
gulp.task('dev', function () {
return gulp.src(['./src/**/*', '!src/**/views'])
.pipe(cleanDest('./dev/'))
.pipe(gulp.dest('./dev/'));
});
Related
do I understand this wrong or is something not right here?
I have this piece of code
gulp.task("minifyScripts", function () {
return gulp.src("assets/scripts/*.js")
.pipe(uglify())
.pipe(rev())
.pipe(gulp.dest('assets/scripts/min'))
.pipe(rev.manifest())
.pipe(revDel())
.pipe(gulp.dest('assets/scripts'))
.pipe(livereload())
.pipe(browserSync.stream());
});
My understanding was that this should remove old .js file when one with new hash is created, but its not...
Do you have any idea? Thanks so much!
You need to specify either dest in the options, or base in the manifest options—unless you're writing everything to the root directory.
Try:
pipe(revDel({dest: "assets/scripts/min"})
Seems that rev-del has a number of users, including myself, who are unable to get the plug-in to delete the old static files after gulp-rev hashes them.
Switching over to gulp-rev-delete-original simply worked OOB.
In the OP's use case, the updated solution would be:
const revDel = require("gulp-rev-delete-original")
gulp.task("minifyScripts", function () {
return gulp.src("assets/scripts/*.js")
.pipe(uglify())
.pipe(rev())
.pipe(revDel()) // call just after rev()
.pipe(gulp.dest('assets/scripts/min'))
.pipe(rev.manifest())
//.pipe(revDel()) ==> move to just after rev()
.pipe(gulp.dest('assets/scripts'))
.pipe(livereload())
.pipe(browserSync.stream());
});
I don't understand what i'm doing wrong. I want to clean up my dist/browser folder, but absolutely noothing happens, not even an error.
const gulp = require("gulp");
const gulpElm = require('gulp-elm');
const clean = require('gulp-clean');
const del = require('del');
gulp.task("clean-dist/browser-folder", () => {
console.log("this gets logged - and nothing happens.");
return gulp.src('dist/**', {read: false})
.pipe(clean({force: true}));
});
// i commented this out but this 2 aproaches below using del module also don't work
// gulp.task("clean-dist/browser-folder", () => {
// return del([ "dist/browser"], {force:true});
// });
// gulp.task("clean-dist/browser-folder", async () => {
// return await del([ "dist/browser/**", "!dist/browser" ], {force:true});
// });
//
gulp.task("default", [ "clean-dist/browser-folder" ]);
Also i used function (){} instead of lambda. Exact same result. WTCrap is happening?
All questions i reaserched plus the docs suggest i'm doing things correctly.
Am i missing something very obvious - i'm just blinded to it right now ? Thanks :)
Crap! i found it. So basically my gulp scripts are in a gulp folder like so (sorry i forgot to mention this in the question - since i wasn't thinking is somehow relevant) :
rootOfProject/gulp/firstGulpScript.js
rootOfProject/gulp/secondGulpScript.js
// and the cleaning path:
rootOfProject/dist/browser/crap.js
I need multiple gulp script files since is a project with multiple apps which require separate compilation in separate locations and such. Seemed nicer to split each app in it's own gulp file. Thinking back at this it might not have been the brightest idea.
Now what happens, in my clean() task to delete crap.js i have :
return del([ "dist/browser/crap.js"], { force : true });
But gulp looks into:
rootOfProject/gulp/dist/browser/crap.js - which of course is wrong location.
I am supposed to write this instead:
return del([ "../dist/browser/crap.js"], { force : true }); - note the ../ in front of the path here. As such the new location will be:
rootOfProject/dist/browser/crap.js - which is the correct location to start cleaning.
There was nothing to clean in rootOfProject/gulp/dist .. that's why i wasn't getting any errors. The task was running just fine, but nothing was beeing deleted form dist/... With no errors things were even more confusing
This hole mess lost me 2-3 hours..
Hopefully if somebody finds an issue like this they will be more careful about the path specified - when the gulp script file is not in the root of the project.
I have the following code:
gulp.task('watch:Feature', function() {
gulp.watch(['./js/Feature/**/*.ts', '!./js/Feature/.gulp-tsc-tmp*.ts'], function () { console.log("Test"); });
});
I've substituted my typescript build task for console.log("Test") and am copying a file with the name: .gulp-tsc-tmp-1151023-9976-e1a1h3.ts into the Feature directory, which causes "Test" to be output to the console.
I've tried all sorts of exclude patterns including specifying the exact filename I'm copying into the directory, none of which seem to work.
What would be the correct way of ignoring files with a particular prefix?
I encountered this a few weeks back and was informed that feature was removed, I didn't have time to establish if that was true but certainly none of my previously working 'ignores' were working on updated release.
The correct way to ignore files in a watch in gulp 4 is this:
gulp.watch('js/Feature/**/*.ts', {
ignored: 'js/Feature/.gulp-tsc-tmp*.ts'
}, function () {
console.log('Test');
});
See the documentation.
I was having this problem too, and solved it by removing "./" from the beginning of my paths:
gulp.task('watch:Feature', function() {
gulp.watch(['js/Feature/**/*.ts', '!js/Feature/.gulp-tsc-tmp*.ts'], function () { console.log("Test"); });
});
I'm using this Gulp Watch sample: https://github.com/floatdrop/gulp-watch/blob/master/docs/readme.md#starting-tasks-on-events.
var gulp = require('gulp');
var watch = require('gulp-watch');
var batch = require('gulp-batch');
gulp.task('build', function () { console.log('Working!'); });
gulp.task('watch', function () {
watch('**/*.js', batch(function () {
gulp.start('build');
}));
});
When I run it on my Windows 8 machine, it only runs the first time I change a file:
C:\test>gulp watch
[08:40:21] Using gulpfile C:\test\gulpfile.js
[08:40:21] Starting 'watch'...
[08:40:21] Finished 'watch' after 2.69 ms
[08:40:31] Starting 'build'...
Working!
[08:40:31] Finished 'build' after 261 µs
Next time nothing happens. Why?
For me it was adding a "return" to the task:
gulp.task('styles', function(){
return gulp.src('css/styles.css')
.pipe(autoprefixer())
.pipe(gulp.dest('build'));
});
If you read the documentation closely, you see the following phrase:
You can pass plain callback, that will be called on every event or wrap it in gulp-batch to run it once
So, that's basically the deal with gulp-batch. To constantly watch it, just remove the batch call:
gulp.task('build', function (done) {
console.log('Working!');
done();
});
gulp.task('watch', function () {
watch('app/*.js', function () {
gulp.start('build');
});
});
(and add the 'done' callback to build to let Gulp know when you're finished).
Btw... I'm not sure, but I think gulp-watch is meant to not only watch files, but also directly returning a vinyl object. So actually using the built-in gulp.watch should have the same effect:
gulp.task('watch', function () {
gulp.watch('app/**/*.js', ['build']);
});
This appears to be known issue
I had the same problem and used the same as ddprrt. The difference was using directory glob (wildcard) as apposed to absolute path.
I changed this:
gulp.task('watch', function() {
gulp.watch('sass/shortcutcss/*.scss', ['sass'])
});
to this:
gulp.task('watch', function() {
gulp.watch('sass/**/*.scss', ['sass'])
});
This problem made me crazy for a weekend. I tried all:
Add done()-Event
Rename/Touch/Clear target CSS
Be more specific with the filepaths
But the (reason for this problem and) the solution was so easy that I felt pathetic after that:
Just update your nodejs installation, mine was 0.12.x! No wonder that this doesn't worked.
After that the watch event works again. Sometimes it goes wrong again, too. But in this cases just save your file a second time and it get recognized. (I think foundation/gulp watch checks for changes to fast and while your file get replaced with the new uploaded one)
Long story:
For me it did not work for long time. All seems to be set right but run only once.
But suddenly I started with parcel js on another project and same thing happened with their builtn watch. So I looked for the answer and I found out that problem was with my Vim settings.
Answer what helped me is this one from #acobster https://stackoverflow.com/a/55435197/2686510
In short:
Update .vimrc by adding set backupcopy=yes
I use gulp-react to compile jsx to js. I need to save folder structure while compiling.
The code below works good for single folder of all files, but I need dumanic destination
var gulp = require('gulp');
var react = require('gulp-react');
gulp.task('default', function () {
return gulp.src('template.jsx')
.pipe(react())
.pipe(gulp.dest('dist')); // in this line need dumanic destination
});
Any Ideas?
Problem solved like this
gulp.src('./public/js/**/.')