First Time Using Gulp - Where are my files being saved? [closed]
-
21-12-2019 - |
Question
Im trying to use Gulp for the first time, ive followed a number of tutorials and able to run Gulp, however i cannot find where my newly created files have been placed!
Here is my project structure:
GulpTest
Authenticated
Images
Javascript
NotAuthenticated
Images
Javascript
Quite a simple setup.
Within my root folder (GulpTest), i have a:
package.json file with:
{
"devDependencies": {
"gulp": "^3.5.2",
"gulp-rename": "^1.1.0",
"gulp-concat": "^2.1.7",
"gulp-uglify": "^0.2.1",
"gulp-jshint": "^1.5.0"
}
}
A a gulpfile.js file with:
// Include gulp
var gulp = require('gulp');
// Include Our Plugins
var jshint = require('gulp-jshint');
//var sass = require('gulp-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var paths = {
scripts: ['Authenticated/javascript*.js', 'NotAuthenticated/javascript*.js'],
};
// Lint Task
gulp.task('lint', function() {
return gulp.src('Authenticated/*.js')
//return gulp.src('js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// Compile Our Sass
//gulp.task('sass', function() {
// return gulp.src('scss/*.scss')
// .pipe(sass())
// .pipe(gulp.dest('css'));
//});
gulp.task('scripts', function() {
// Minify and copy all JavaScript (except vendor scripts)
return gulp.src(paths.scripts)
.pipe(uglify())
.pipe(concat('all.min.js'))
.pipe(gulp.dest('Authenticated/js'));
});
// Watch Files For Changes
gulp.task('watch', function() {
gulp.watch('Authenticated/*.js', ['lint', 'scripts']);
//gulp.watch('js/*.js', ['lint', 'scripts']);
//gulp.watch('scss/*.scss', ['sass']);
});
// Default Task
//gulp.task('default', ['lint', 'sass', 'scripts', 'watch']);
gulp.task('default', ['lint', 'scripts', 'watch']);
I've created a new folder within Authenticated called js, i thought the new code would/is created here??
Am i missing something?
Solution
Assuming that your js files have names like javascript1.js
they are minified and saved in the 'Authenticated/js' directory.
When you say
gulp.src(paths.scripts)
this will match all the files in the current working directory, that match the rules you passed to the src() function. In this case you passed
['Authenticated/javascript*.js', 'NotAuthenticated/javascript*.js']
so it will search for files in the two folders that begin with 'javascript' and end with '.js'. For example 'javascript_Something.js'
If you wanted to include any file that has the '.js' extension, just say
var paths = {
scripts: ['NotAuthenticated/*.js','Authenticated/*.js']
};
See the documentation for gulp.src() and for node-glob.