Gulp bundle then minify

I am creating 3 mini-packages for my application. I have 2 tasks to do this, reduce and stratify. Minify is package dependent. If I run minify, both tasks run without errors. Packages are created, but mini files are not. If I remove the package dependency, I can run minify on my own and the thumbnail files will be created successfully. It makes me think, maybe files are used when the trigger of the minimization task (since the package is not finished yet?). How to make it wait until the files are completely ready? Can I stream a stream? Or maybe combine them into one task? The reason that they are currently not a single task is that they output 2 files per bundle (unminified and minipack).

var outFolder = __dirname + '\\Scripts\\dist'; var appBundles = [ { scripts: ['Scripts/Common/**/*.js'], output: 'eStore.common.js' }, { scripts: ['Scripts/Checkout/**/*.js'], output: 'eStore.checkout.js' }, { scripts: ['Scripts/ProductDetail/**/*.js'], output: 'eStore.product.js' } ]; gulp.task('bundle', bundle); gulp.task('minify', ['bundle'], minify); // this one doesn't work gulp.task('minifyOnly', minify); // this one works function bundle() { appBundles.forEach(function (appBundle) { gulp.src(appBundle.scripts) .pipe(concat(appBundle.output)) .pipe(sourcemaps.init()) .pipe(sourcemaps.write(outFolder + '\\maps')) .pipe(gulp.dest(outFolder)) .on('error', errorHandler); }); } function minify() { appBundles.forEach(function(appBundle) { var bundleSrc = outFolder + '\\' + appBundle.output; gulp.src(bundleSrc) .pipe(rename({ extname: '.min.js' })) .pipe(uglify()) .pipe(gulp.dest(outFolder)) .on('error', errorHandler); }); } 
+6
source share
1 answer

Ask the minify task to use the same source files as for the package task. "concat" will be used in both tasks. Thus, minify does not depend on the result of the package task.

 function minify() { appBundles.forEach(function (appBundle) { console.log('Creating minified bundle for: ' + appBundle.output); gulp.src(appBundle.scripts) .pipe(concat(appBundle.output)) .pipe(rename({ extname: '.min.js' })) .pipe(uglify()) .pipe(gulp.dest(outFolder)) .on('error', errorHandler); }); } function bundle() { appBundles.forEach(function (appBundle) { console.log('Creating bundle and sourcemaps: ' + appBundle.output); gulp.src(appBundle.scripts) .pipe(concat(appBundle.output)) .pipe(sourcemaps.init()) .pipe(sourcemaps.write(outFolder + '\\maps')) .pipe(gulp.dest(outFolder)) .on('error', errorHandler); }); } 
+2
source

All Articles