官术网_书友最值得收藏!

Configuring Visual Studio

In this recipe, we will demonstrate how to add CoffeeScript support to Visual Studio.

Getting ready

If you are on the Windows platform, you can use Microsoft's Visual Studio software. You can download Microsoft's free Express edition (Express 2013 for Web) from http://www.microsoft.com/express.

How to do it...

If you are a Visual Studio user, Version 2010 and above can work quite effectively with CoffeeScript through the use of Visual Studio extensions.

If you are doing any form of web development with Visual Studio, the Web Essentials extension is a must-have.

To install Web Essentials, perform the following steps:

  1. Launch Visual Studio.
  2. Click on the Tools menu and select the Extensions and Updates menu option. This will display the Extensions and Updates window (shown in the next screenshot).
  3. Select Online in the tree on the left-hand side to display the most popular downloads.
  4. Select Web Essentials 2012 from the list of available packages and then click on the Download button. This will download the package and install it automatically.
  5. Once the installation is finished, restart Visual Studio by clicking on the Restart Now button.

    Tip

    You will likely find Web Essentials 2012 ranked highly in the list of Most Popular packages. If you do not see it, you can search for Web Essentials using the Search box in the top-right corner of the window.

    How to do it...

Once installed, the Web Essentials package provides many web development productivity features, including CSS helpers, tools to work with Less CSS, enhancements to work with JavaScript, and, of course, a set of CoffeeScript helpers.

To add a new CoffeeScript file to your project, you can navigate to File | New Item or press Ctrl + Shift + A. This will display the Add New Item dialog, as seen in the following screenshot. Under the Web templates, you will see a new CoffeeScript File option. Select this option and give it a filename, as shown here:

How to do it...

When we have our CoffeeScript file open, Web Essentials will display the file in a split-screen editor. We can edit our code in the left-hand pane, while Web Essentials displays a live preview of the JavaScript code that will be generated for us.

The Web Essentials CoffeeScript compiler will create two JavaScript files each time we save our CoffeeScript file: a basic JavaScript file and a minified version. For example, if we save a CoffeeScript file named employee.coffee, the compiler will create employee.js and employee.min.js files.

Tip

Though I have only described two editors to work with CoffeeScript files, there are CoffeeScript packages and plugins for most popular text editors, including Emacs, Vim, TextMate, and WebMatrix.

主站蜘蛛池模板: 苏尼特左旗| 芷江| 武宁县| 贵南县| 正定县| 阿拉善左旗| 车致| 马关县| 红安县| 绥滨县| 甘泉县| 京山县| 安龙县| 眉山市| 嘉定区| 彰武县| 津南区| 新蔡县| 普兰店市| 吴旗县| 锡林郭勒盟| 英山县| 孟津县| 武强县| 乾安县| 原阳县| 汉阴县| 盐池县| 高陵县| 永吉县| 昌吉市| 东丽区| 南丰县| 郑州市| 余江县| 赤城县| 新巴尔虎右旗| 昭苏县| 莎车县| 唐山市| 富民县|