Highdown
Highdown

Reputation: 674

Visual Studio 2015 Bundler/Minifier Issues in Web/SPA project

We are using Typescript in Visual Studio 2015 to create a rather complex single page application. This is a web project, not MVC or .NET on the client. We are only using jQuery, JavaScript, CSS3, and HTML5 on the client and Web API 2.0/C# on the server. All files must be bundled/minified as part of the build process.

Issue

Up until recently, the madskristensen Bundler/Minifier has been working reliably to minify HTML files, and bundle/minify all CSS and JavaScript files into two separate files for download. A couple days back, VS started displaying an error dialog during the project build process. This occurs when one or more JavaScript files are edited and a build is initiated. The bundler/minifier tries to do its thing, but can't access the file(s).

I have found at least two other persons who have recently encountered the same issue. I have not found any solutions.

Error Message

The Bundler/Minifier process cannot access the file(s) because it or they are being used by another process. This warning message is displayed in a popup dialog (sometimes 20+ windows at a time) by the Bundler/Minifier. The file flagged for contention is the bundled JavaScript code (bundled.js). Apparently there is some kind of race condition that causes this issue. Once in a while, Visual Studio will build and generate the bundled/minified JavaScript file without issue (rare and unpredictable). Most of the time, VS will complete the minification process, but the size of the minified file is smaller than normal and it is corrupted.

We are using Windows 10. The latest version of the madskristensen Bundler/Minifier was installed a few days back. I have not been able to figure out where to find an earlier version to see if it is the problem. I have verified the issue on multiple PCs, but unfortunately, all our PCs have been updated with the latest version of software. We have verified that older project versions that did not have the problem in the past are all now exhibiting the same symptoms.

Questions 1: Where can one get older versions of the madskristensen Bundler/Minifier? I found links for Visual Studio 2013, but not 2015.

Question 2: Can the madskristensen Bundler/Minifier be run from a script file instead of being embedded into the Build flow? I tried using the Task Runner Explorer to set the process to run at pre and post build events, but the issue remained.

I am looking for a way to make the madskristensen Bundler/Minifier work. Any ideas would be greatly appreciated.

Updated Question 3: If the madskristensen Bundler/Minifier cannot be run from a batch file in the post build process, what are some alternatives?

Regards…

Upvotes: 0

Views: 2092

Answers (1)

Highdown
Highdown

Reputation: 674

Workaround Option

Since this issue is a show stopper for our testing/development process, we have had to come up with a viable near term alternative until the issue is hopefully resolved with the madskristensen Bundler/Minifier.

The Microsoft Ajax Minifier located at http://ajaxmin.codeplex.com/ is a viable alternative to bundle and minify our project JavaScript code. It did not take long to get a batch file running in the post build process in Visual Studio 2015.

Post Build Batch File

I included the following in the post build process: call cd "$(ProjectDir)" bundleMinifyJavaScript.bat (located in the project root dir)

In the batch file, I first changed to the project path and then executed the full path to the Ajax MInifier as follows:

cd "C:\Users\path…\projectName"

"C:\Program Files (x86)\Microsoft\Microsoft Ajax Minifier\ajaxminifier.exe" libs/jquery.js libs/typeahead.js … more files here … -out app/bundle.min.js –clobber

This process generates the equivalent bundled/minified code, which is placed in our app project folder. The clobber option allows the overwriting of the previous version of the bundle.min.js file.

This workaround supports generating an ordered list of JavaScript files in the bundle, which is required for our project.

I am still hoping for an option to use the madskristensen Bundler/Minifier because we still have to use it to minify our HTML.

Regards…

Upvotes: 2

Related Questions