asp.netasp.net-mvcbundling-and-minificationasp.net-bundling

ASP.NET MVC how to produce the physical files of each bundle when publishing


Is it possible to actually get the bundles that the framework would generate in runtime, but as physical files when publishing an application?

For instance, if I have 3 files in a bundle: a.js, b.js and c.js (and/or a.min.js, b.min.js, c.min.js), and I publish the website, I want to get only mybundle.js (being its contents the combination in order of a, b and c minified versions).

Is this possible?


Solution

  • If you want the combined files at build time, you should look into using a task runner like gulp.

    Here's a sample from the accepted answer in the linked question:

    var gulp = require('gulp'),
        gp_concat = require('gulp-concat'),
        gp_rename = require('gulp-rename'),
        gp_uglify = require('gulp-uglify');
    
    gulp.task('js-fef', function(){
        return gulp.src(['file1.js', 'file2.js', 'file3.js'])
            .pipe(gp_concat('concat.js'))
            .pipe(gulp.dest('dist'))
            .pipe(gp_rename('uglify.js'))
            .pipe(gp_uglify())
            .pipe(gulp.dest('dist'));
    });
    
    gulp.task('default', ['js-fef'], function(){});
    

    If you want the combined files after publishing, you can view the page source in your browser and download the bundle.