source: Dev/trunk/src/client/util/build/transforms/optimizer/uglify.js

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 1.3 KB
Line 
1/*jshint node:true */
2define([
3        "../../buildControl",
4        "../../fs",
5        "./stripConsole",
6        "dojo/_base/lang",
7        "dojo/has",
8        "dojo/has!host-node?dojo/node!uglify-js:"
9], function(bc, fs, stripConsole, lang, has, uglify){
10        if(!uglify){
11                throw new Error("Unknown host environment: only nodejs is supported by uglify optimizer.");
12        }
13
14        return function(resource, text, copyright, optimizeSwitch, callback){
15                copyright = copyright || "";
16
17                var options = bc.optimizeOptions || {};
18
19                if(optimizeSwitch.indexOf(".keeplines") > -1){
20                        options.gen_options = options.gen_options || {};
21                        options.gen_options.beautify = true;
22                        options.gen_options.indent_level = 0; //don't indent, just keep new lines
23                }
24                if(optimizeSwitch.indexOf(".comments") > -1){
25                        throw new Error("'comments' option is not supported by uglify optimizer.");
26                }
27
28                process.nextTick(function(){
29                        try{
30                                var result = copyright + "//>>built" + bc.newline + uglify(stripConsole(text), options);
31
32                                fs.writeFile(resource.dest, result, resource.encoding, function(err){
33                                        if(err){
34                                                bc.log("optimizeFailedWrite", ["filename", result.dest]);
35                                        }
36                                        callback(resource, err);
37                                });
38                        }catch(e){
39                                bc.log("optimizeFailed", ["module identifier", resource.mid, "exception", e + ""]);
40                                callback(resource, 0);
41                        }
42                });
43
44                return callback;
45        };
46});
Note: See TracBrowser for help on using the repository browser.