i am currently learning about gulp.js. as i saw the tutorial and documentation of gulp.js, this code:
gulp.src('js/*.js')
.pipe(uglify())
.pipe(gulp.dest('minjs'));
makes the uglified javascript file with create new directory named 'minjs'. of course, i installed gulp-uglity with --dev-save option. there is no error message on the console so i don't know what is the problem. i tried gulp with "sudo", but still not working.
so i went to the root directory and searched all filesystem but there is no file named 'minjs' so i guess it just not working. why this is happening? anyone knows this problem, it would be nice why this is happening.
whole source code:
var gulp = require('gulp');
var uglify = require('gulp-uglify');
gulp.task('default', function() {
console.log('mifying scripts...');
gulp.src('js/*.js')
.pipe(uglify())
.pipe(gulp.dest('minjs'));
});
i am currently learning about gulp.js. as i saw the tutorial and documentation of gulp.js, this code:
gulp.src('js/*.js')
.pipe(uglify())
.pipe(gulp.dest('minjs'));
makes the uglified javascript file with create new directory named 'minjs'. of course, i installed gulp-uglity with --dev-save option. there is no error message on the console so i don't know what is the problem. i tried gulp with "sudo", but still not working.
so i went to the root directory and searched all filesystem but there is no file named 'minjs' so i guess it just not working. why this is happening? anyone knows this problem, it would be nice why this is happening.
whole source code:
var gulp = require('gulp');
var uglify = require('gulp-uglify');
gulp.task('default', function() {
console.log('mifying scripts...');
gulp.src('js/*.js')
.pipe(uglify())
.pipe(gulp.dest('minjs'));
});
Share
Improve this question
asked Jan 2, 2016 at 10:21
modernatormodernator
4,42714 gold badges48 silver badges77 bronze badges
8
-
Can you try
.pipe(gulp.dest('./minjs/'));
? – Manasov Daniel Commented Jan 2, 2016 at 10:28 -
it will create
minjs
folder relative to the directory containing yourgulpfile.js
. Did you check there ? – Arkantos Commented Jan 2, 2016 at 10:33 - Arkantos// yep. i checked, no 'minjs' directory ;( – modernator Commented Jan 2, 2016 at 10:40
- Manasov Daniel// just i tried, but nothing happens either. – modernator Commented Jan 2, 2016 at 10:41
-
how are you executing your gulp tasks ? You can go to the directory containing
gulpfile.js
and givegulp
for executing default task. Do you see any errors while doing this ? – Arkantos Commented Jan 2, 2016 at 11:05
2 Answers
Reset to default 10I had the same problem; you have to return the task inside the function:
gulp.task('default', function() {
return gulp.src("js/*.js")
.pipe(uglify())
.pipe(gulp.dest('minjs'));
Also, minjs
will not be a file, but a folder, where all your minified files are going to be saved.
Finally, if you want to minify only 1 file, you can specify it directly, the same with the location of the destination.
For example:
var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var uglify = require('gulp-uglify');
gulp.task('browserify', function() {
return browserify('./src/client/app.js')
.bundle()
// Pass desired output filename to vinyl-source-stream
.pipe(source('main.js'))
// Start piping stream to tasks!
.pipe(gulp.dest('./public/'));
});
gulp.task('build', ['browserify'], function() {
return gulp.src("./public/main.js")
.pipe(uglify())
.pipe(gulp.dest('./public/'));
});
Hope it helps!
Finally I resolved the question like this:
It was a directory mistake so the gulp task hasn't matched any files; then it couldn't create the dest directory (because no files in output).
const paths = {
dest: {
lib: './lib',
esm: './esm',
dist: './dist',
},
styles: 'src/ponents/**/*.less',
scripts: ['src/ponents/**/*.{ts,tsx}', '!src/ponents/**/demo/*.{ts,tsx}'],
};
At first my scripts was ['ponents/**/*.{ts,tsx}', '!ponents/**/demo/*.{ts,tsx}']
And that hasn't matched any files.