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