Search code examples
javascript.netbundling-and-minification

is it possible to not mangling in .NET minification?


To bundle and minify the files of my application I'm using .NET Bundling and Minification feature (and it's complicated to use any other tool, so I would like to find a solution for this).

As a remark and just in case it could help, I'm trying to minify angular files, files compiled from typescript and regular javascript files.

The problem is that when I execute the application I got some javascript exceptions related mostly to angular. I think it's not useful but maybe it could help, so this is the main exception I get:

Error: [$injector:unpr] Unknown provider: tProvider <- t <- highChartSeriesMappingService http://errors.angularjs.org/1.5.5/$injector/unpr?p0=tProvider%20%3C-%20t%20%3C-%20highChartSeriesMappingService [Rest of the exception trace][...]

If I just bundle them and no minify my files, by setting this instruction myScriptBundle.Transforms.Clear(), it works fine. Obviously, this action also avoids the mangling of variables, classes...names.

In order to be sure of what was happening, I used grunt and its plugin grunt-contrib-uglify to bundle and minify. At the beginning I had the same problem as before because of the basic configuration I used for the task:

      uglify: {
            options: {
                preserveComments: false
            },
            myScript: {
                files: {
                    'myScript.min.js': conf.myScript
                }
            }
        }

Where conf is a reference to a json file with the url of the files to minify. But when I set the mangle property to false (here you have more info about it):

      uglify: {
            options: {
                preserveComments: false,
                mangle: false
            },
            myScript: {
                files: {
                    'myScript.min.js': conf.myScript
                }
            }
        }

It works fine too. It leads me to think that is the mangling of some classes names the root of the problem.

As you can see, I reached a solution using grunt but I would like to find a way to avoid mangling with .NET. Any idea?


Solution

  • After read the post of @AbdelrhmanMohamed and check again my project's files I realized that it was a problem related to angular and its array sytntax; some files lacked the dependencies injection through the array strings, so when those files where minimizied and the functions' names where mangled caused my exception in execution time.

    To sum up, .NET bndling and minification process seems to work fine. If you work with angular you just have to be sure that all your classes which depend of other modules have the array string with those dependencies defined.