Gulp adding to files, not rewriting

I am trying to merge my JS files and run them through Babel for a new project, but instead of overwriting the destination file each time the task starts, my gulpfile only adds the changes to the file. So my destination file is as follows:

console.log('hello'); //# sourceMappingURL=app.js.map console.log('goodbye'); //# sourceMappingURL=app.js.map 

What am I missing? Below is my gulpfile.

Thanks in advance.

 var gulp = require('gulp'); var sourcemaps = require("gulp-sourcemaps"); var uglify = require('gulp-uglify'); var rename = require('gulp-rename'); var concat = require('gulp-concat'); var babel = require('gulp-babel'); var browserSync = require('browser-sync').create(); var reload = browserSync.reload; gulp.task('js', function(){ return gulp.src("./app/js/*.js") .pipe(sourcemaps.init()) .pipe(concat("app.js")) .pipe(babel()) .pipe(sourcemaps.write(".")) .pipe(gulp.dest("./app/js/")); }); gulp.task('js-reload', ['js'], reload); gulp.task('serve', ['js'], function() { browserSync.init({ server: "./app" }); gulp.watch("./app/js/*.js").on('change', ['js-reload']); gulp.watch("./app/*.html").on('change', reload); }); gulp.task('default', ['js', 'serve']); 
+6
source share
1 answer

You read and write to the same destination directory. Therefore, the app.js file is first read, some things are added to it, and then the result is written to app.js, causing this addition. You must output to a different directory than what you are reading.

+1
source

Source: https://habr.com/ru/post/987836/


All Articles