write in front: when the front end of the formal deployment, JavaScript files generally need to compress, and generate the corresponding Sourcemap file, for some small project development, here is a simple way.
====== Body begins ======
1. Download the Google-closure-compiler file:
Download from here: Download
2. Copy the Compiler.jar from the compressed package to the directory of JavaScript files that need to be compressed.
3. Open the command line CMD,CD to the directory and run the following command:
Java-jar Compiler.jar--js test.js--js_output_file test.min.js--create_source_map test-min.js.map
(1) need to install Java Runtime environment.
(2)-jar parameter specifies the jar file, here is Compiler.jar
The--JS parameter specifies the JavaScript source file
The--js_output_file parameter specifies the compressed JavaScript file to be generated
The--create_source_map parameter specifies the source map file to generate
(3) Here is the Test.js source file is compressed into a test.min.js file, and a source map file is generated Test-min.js.map
4. Add the Soure Map reference description at the end of the compressed file (test.min.js).
@ sourcemappingurl=test-min.js.map
Note: after adding the source map reference description, the current side refers to the compressed version of the JS file, using Chrome's developer tool can still locate the specific error line number, you can change in the uncompressed file and then compress.
5. More usage:
(1) Compiling multiple JavaScript files:
The--JS parameter specifies multiple JavaScript source files, which are merged.
(2) View Help
Java-jar Compiler.jar--help
Finish
Document Information
- Copyright Disclaimer: Free Reprint-Non-commercial-non-derivative-maintain attribution (Creative Commons 3.0 license)
- This article is for original articles, welcome reprint, follow up this blog will be updated constantly, so please keep this document information.
- This address: http://www.cnblogs.com/wuguanglei/p/4782769.html
Compressing JavaScript file methods