Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Gulp not minifying files in wwwroot folders #4492


User avatar
0
michelmk2 created

Hi Guys,

I'm using the new version 5 template (.net core with jquery).

When i'm running the gulp --env prod command in my *.Web.Mvc folder, .min.js files are being generated in my /wwwroot/view-resources/areas/{name}/views/{name} folders. The min files are the same as the regular files though, the content is unminified Javascript.

I've specified the files to be minified in the bundle.config.js, like below:

{
            outputFileName: "wwwroot/view-resources/Areas/App/Views/test/_CreateOrEditModal.min.js",
            inputFiles: [
                "wwwroot/view-resources/Areas/App/Views/test/_CreateOrEditModal.js"
            ]
        }

What am I doing wrong here?

Thanks!


8 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    @michelmk2 can you try "gulp --prod" ?

  • User Avatar
    0
    michelmk2 created

    @ismcagdas. Nope! Same results. What's really strange is that it isn't working for the default items either.. E.g. ~wwwroot\view-resources\Views\Account\EmailActivation.min.js. Those min files are also just the regular files.

    Greetings,

  • User Avatar
    0
    ismcagdas created
    Support Team

    Can you add below pipe to your min:js task ? It will print out the error message if there is something wrong with existing files.

    .on('error', function (error) 
        { 
            gutil.log(error.message);
        });
    
  • User Avatar
    0
    michelmk2 created

    You mean, like this right?

    gulp.task("min:js", function () {
        var tasks = getBundles(regex.js).map(function (bundle) {
            var outputFileName = getOutputFileName(bundle.outputFileName);
            var outputFolder = getOutputFolder(bundle.outputFileName);
    
            return gulp.src(bundle.inputFiles)
                .pipe(concat(outputFileName))
                .pipe(gulp.dest(outputFolder));
        });
    
        if (gutil.env.prod) {
            var minifyTasks = getBundles(regex.js).map(function (bundle) {
                var outputFileName = getOutputFileName(bundle.outputFileName);
                var outputFolder = getOutputFolder(bundle.outputFileName);
    
                if (bundle.createMinified === false || outputFileName.endsWith('.min.js')) {
                    return null;
                }
    
                var minifiedJsOutputFile = outputFileName.substr(0, outputFileName.lastIndexOf(".")) + ".min.js";
                return gulp.src(bundle.inputFiles)
                    .pipe(concat(minifiedJsOutputFile))
                    .pipe(uglify())
                    .pipe(gulp.dest(outputFolder));
            });
    
            for (var i = 0; i < minifyTasks.length; i++) {
                if (minifyTasks[i] == null) {
                    continue;
                }
    
                tasks.push(minifyTasks[i]);
            }
        }
    
        return merge(tasks);
    }).on('error', function (error) {
        gutil.log(error.message);
    });
    

    Unfortunately this doesn't give me any errors :(.

  • User Avatar
    0
    ismcagdas created
    Support Team

    @michelmk2 can you send your project to us via email if it is not a problem for you ? We can find the problem faster in that way. You can use <a href="mailto:[email protected]">[email protected]</a>.

    Thanks.

  • User Avatar
    0
    alirizaadiyahsi created

    Hi @michelmk2, we resolved this issue.

    Check related change: <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/commit/3c552b4648377d8216256af0b01b37564b44e2dd#diff-16281b32d0eef5f5b47ce3b2c590de12">https://github.com/aspnetzero/aspnet-ze ... b2c590de12</a>

  • User Avatar
    0
    michelmk2 created

    <cite>alirizaadiyahsi: </cite> Hi @michelmk2, we resolved this issue.

    Check related change: <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/commit/3c552b4648377d8216256af0b01b37564b44e2dd#diff-16281b32d0eef5f5b47ce3b2c590de12">https://github.com/aspnetzero/aspnet-ze ... b2c590de12</a>

    Hi, Thanks for the link! What I see now, is that gulp generates *.min.min.js and *.min.min.css files. The min min files are no longered generated if I re-add the || outputFileName.endsWith('.min.js') line at the bundle.createMinified step. But then i'm back to my initial problem of the files not being minified :(.

    Greetings

  • User Avatar
    0
    michelmk2 created

    Ahh got it fixed! So what happens is that the last .js is trimmed of the output file names, and then .min.js is added. So that leaves you with .min.min.js.

    Changing var minifiedJsOutputFile = outputFileName.substr(0, outputFileName.lastIndexOf(".")) + ".min.js"; to var minifiedJsOutputFile = outputFileName.substr(0, outputFileName.lastIndexOf(".")) + ".js";

    And the same for css files, fixed the problem!

    Thanks guys!