VS2010 using Yui-compressor to package and compress JS, CSS

Source: Internet
Author: User

Background: The JS, CSS files in a project developed by VS2010 are packaged (bundle) and Compressed (compress) sequentially.

Predecessor work: Install Java, download Yuicompressor-2.4.6.jar

JS For example, CSS analogy:

The first step: according to the project in the order of JS, the file list is written to Release.bundle, the content is as follows (relative to the Release.bundle path):

Jquery-1.5.1.js
Messagealert\msgbox.js
Jquery.form.js
Application.js

Step two: Make the cmd file, add the file under the root of the VS Startup project: Bundle.cmd; The file contents are as follows:

@ECHO off
TITLE Static Content Compressor and Bundle
SETLOCAL enableextensions
SETLOCAL enabledelayedexpansion

Cls

for/f%%i in ('%0 ') do SET cur_path=%%~dpi

ECHO working folder! cur_path:~0,-1!
ECHO.

SET filename= ""
SET yui_compressor_path= "%cur_path%yui-compressor\yuicompressor-2.4.6.jar"


COLOR A
ECHO%yui_compressor_path%
ECHO compressing static content started
ECHO.

ECHO compressing javascripts ...
ECHO.
Call:compress_bundle_content Scripts,release.js,release.min.js,release.bundle,js
ECHO.

ECHO compressing CSS ...
ECHO.
Call:compress_bundle_content Css,release.css,release.min.css,release.bundle,css
ECHO.

ECHO compressing static content done
Goto:end

: compress_bundle_content

CD%~1
SET filename=%~2
SET outfilename=%~3

for/f%%i in (%~4) do ECHO%%i

ECHO DELETE%~1\%filename%,%~1\%outfilename%
IF EXIST%filename% DEL%filename%
IF EXIST%outfilename% DEL%outfilename%

for/f%%i in (%~4) do TYPE%%i >>%filename%
Java-jar%yui_compressor_path%--type%~5--charset utf-8-o "%outfilename%" "! filename! "
ECHO into:%~1\%outfilename%

Cd..
Goto:end
: END

Step three: Add Build Events. Startup Project-"Properties-" generate event-"Pre-build Event command line: Add the following

If ' $ (configurationname) ' = = ' Release ' (
CD $ (ProjectDir)
Bundle.cmd
)

Fourth step: Rebuild the project with the release configuration.

Fifth step: View the results. Go to the file where Release.bundle is located, and view Release.min.js as packaged and compressed content.

Report:

An error occurred in the Output window: identifier is a reserved word

Reason: JS file contains debugger, can be removed.

VS2010 using Yui-compressor to package and compress JS, CSS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.