ligershark / WebOptimizer

A bundler and minifier for ASP.NET Core
Apache License 2.0
764 stars 113 forks source link

Wrong js concatenating after minification in some cases #266

Open ogorodnikovInfopulse opened 1 year ago

ogorodnikovInfopulse commented 1 year ago

If we have setup like

//Concatenate all to one file and minify this file
pipeline.AddBundle(path, contentType, files)
             .EnforceFileExtensions(".js")
             .Concatenate() 
             .MinifyJavaScript()

and if some files are already minified, we will minify them one more time. It's wrong.

If we change sutup like

//Minify all non minified files and then concatenate .min to one file
pipeline.AddBundle(path, contentType, files)
            .EnforceFileExtensions(".js")
            .MinifyJavaScript()
            .Concatenate()

to minify all except already minified, then it's possible when

we need to add separator ';' to avoid wrong syntax like

(function(){})()(function(){})()

when correct syntaxt is (function(){})();(function(){})();

I guess the best solution is to add separator as parameter in .Concatenate() to have setup like

pipeline.AddBundle(path, contentType, files)
             .EnforceFileExtensions(".js")
             .MinifyJavaScript()
             .Concatenate(";") //with custom separator

Or add this separator as default between js files