JavaScript project type for Visual Studio?

I have tasks related to creating a JavaScript library that will then be used by several projects in a Visual Studio solution. Ideally, I would like to find a project type that for my JavaScript code will behave as if it were a C # class library, that is:

  • It will "compile" (minify, check by Closure, ...) the JavaScript code into some output **. js * file
  • This conclusion can be β€œtied” to other projects, for example. by ASP.NET MVC project
  • I could specify the "build order" of my projects (standard VS function)

Is this possible with VS 2010/11 or do I need to write some BAT / PowerShell files and script it myself?

A similar but slightly different question: Visual Studio project template for JavaScript / VBScript?

+47
javascript visual-studio visual-studio-2010 visual-studio-2015
Mar 02 2018-12-12T00:
source share
3 answers

Based on my experience with Asp.Net MVC development, Visual Studio has limited JavaScript support. I assume that you can do to imitate the behavior you want:

  • Create a project to store your JavaScript files, perhaps a class library project, it doesn't really matter if it supports Build Events. Put your JavaScript files in a new project.

  • Create a posting creation step in this project to minimize your JavaScript using an external tool. I am using YUI Compressor . The post post step should contain lines similar to the following:

    java -jar $ (ProjectDir) Scripts \ yuicompressor-2.4.7.jar $ (SolutionDir) Scripts \ yourJsFile.js -o $ (SolutionDir) Scripts \ yourJsFile.min.js --charset utf-8

  • Include this new project in your solution. Then, for your Asp.Net projects, configure your active server pages to link to JavaScript files, I use Razor syntax as an example. It can be difficult to determine a specific path:

@if (@Model.IsDebug) { <script src="@Url.Content("~/Scripts/yourJsFile.js")" type="text/javascript"> </script> } else { <script src="@Url.Content("~/Scripts/yourJsFile.min.js")" type="text/javascript"></script> } 

Again, it can be difficult to make sure that you can reference JavaScript files from your Asp.Net project exactly. But I'm sure there is a way to do this. Perhaps you can create your own post by copying JavaScript files to some common place. If you do this, you will also want to mark the post build event in your JavaScript project as β€œAlways Run,” so JavaScript files are always copied.

+9
Mar 02 2018-12-12T00:
source share
β€” -

Good question (+1). I decided to place all javascript files to separate the javascript project and use the related files in the right js files in the web / mvc project.

Thus, you get the opportunity to use the subversioning control from the side of the javascript project, as well as the compression and merging of js files from the side of separate common projects using all available tools.

+7
Apr 12 2018-12-12T00:
source share

I'm very interested! Please @ comment for me if anyone comes up with other / better ideas.

Option 1: ASP.NET Web Project with Web Essentials

If you just need a front panel javascript project, this is a simple option. Web Essentials is easy to use and install in Visual Studio. You can use this for easy minimization. Then you can use Qunit for testing. This is a pretty easy and easy entry point to the javascript client side.

Option 2: Node.js Tools for Visual Studio

Use Node.js Tools for Visual Studio . This will give you project templates for many of these good things. You can not use Node.js, especially if you just create a client-side js library, but Node.js is useful for testing, and you need / need npm to install all the other good things mentioned in my initial answer (Option 3) .

A lot of settings are connected with this. This may be an obstacle to entry for some .NET developers.

Option 3: Website Design

Here is what I have done in the past:

enter image description here

I actually created this project in Eclipse! (Do not hate me). Later I created a Visual Studio solution with a website project . I installed Node.js, which of course is not required, but I used it as a lightweight web server.

Then you can use Nuget or Bower to install other things, such as:

  • require.js for module management
  • jasmine for unit testing
  • grunt or gulp to build (minimize)
  • You can install jslint or jshint to fix the code.

Not all of these things are required. I think Bower is integrated in Visual Studio 2015. Some of them will require command line builds, but very few commands to run after setting it up.

+3
Apr 14 '16 at 2:11
source share



All Articles