How to use the uglify-js.Compressor function in uglify-js

To help you get started, we’ve selected a few uglify-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pokemontrades / flairhq / node_modules / grunt-contrib-uglify / tasks / lib / uglify.js View on Github external
}

    // Need to call this before we mangle or compress,
    // and call after any compression or ast altering
    if (options.expression === false) {
      topLevel.figure_out_scope({ screw_ie8: options.screwIE8, cache: topLevelCache });
    }

    if (options.compress !== false) {
      if (options.compress === true) {
        options.compress = {};
      }
      if (options.compress.warnings !== true) {
        options.compress.warnings = false;
      }
      var compressor = UglifyJS.Compressor(options.compress);
      topLevel = topLevel.transform(compressor);

      // Need to figure out scope again after source being altered
      if (options.expression === false) {
        topLevel.figure_out_scope({screw_ie8: options.screwIE8, cache: topLevelCache});
      }
    }

    var mangleExclusions = { vars: [], props: [] };
    if (options.reserveDOMProperties) {
      mangleExclusions = UglifyJS.readDefaultReservedFile();
    }

    if (options.exceptionsFiles) {
      try {
        options.exceptionsFiles.forEach(function(filename) {
github qooxdoo / qooxdoo / tool / grunt / task / package / dependency / lib / depAnalyzer.js View on Github external
tree = qxCoreEnv.optimizeEnvCall(tree, envMap);
            cache.write(curCacheId, JSON.stringify(tree, adjustRegexLiteral));
          }
        } else {
          tree = qxCoreEnv.optimizeEnvCall(tree, envMap);
          if (cache) {
            cache.write(curCacheId, JSON.stringify(tree, adjustRegexLiteral));
          }
        }
      }

      // reparse tree for if condition removal
      // and as consequence more accurate deps
      var ast = U2.AST_Node.from_mozilla_ast(tree);
      ast.figure_out_scope();
      var compressor = U2.Compressor({warnings: false});
      ast = ast.transform(compressor);
      // TODO: once 'to_mozilla_ast()' is available in the next release
      // (this should be v2.4.16) we should use it instead of reparsing
      // with esprima.
      //
      // see:
      //   https://github.com/mishoo/UglifyJS2#keeping-comments-in-the-output
      //   http://rreverser.com/using-mozilla-ast-with-uglifyjs/
      //
      // var code = ast.print_to_string({ comments: function(){ return true; } });
      // treeOptimized = ast.to_mozilla_ast();
      var code = ast.print_to_string();
      treeOptimized = esprima.parse(code, {comment: true, loc: true});
      depsOptimized = findUnresolvedDeps(treeOptimized, envMap, cache, {
        flattened: false, variants: false
      });
github youzan / fast-uglifyjs-plugin / lib / worker.js View on Github external
});
        };
    } else {
        uglify.AST_Node.warn_function = function (warning) { // eslint-disable-line camelcase
            process.send({
                cmd: 'warning', msg: warning
            });
        };
    }
    uglify.base54.reset();
    var ast = uglify.parse(task.input, {
        filename: task.file
    });
    if (options.compress !== false) {
        ast.figure_out_scope();
        var compress = uglify.Compressor(options.compress); // eslint-disable-line new-cap
        ast = ast.transform(compress);
    }
    if (options.mangle !== false) {
        ast.figure_out_scope();
        ast.compute_char_frequency(options.mangle || {});
        ast.mangle_names(options.mangle || {});
        if (options.mangle && options.mangle.props) {
            uglify.mangle_properties(ast, options.mangle.props);
        }
    }
    var output = {};
    output.comments = Object.prototype.hasOwnProperty.call(options, "comments") ? options.comments : /^\**!|@preserve|@license/;
    output.beautify = options.beautify;
    for (var k in options.output) {
        output[k] = options.output[k];
    }
github lrsjng / fquery / plugins / uglifyjs / index.js View on Github external
uglifyjs: function (options) {

			var fquery = this,
				settings = _.extend({}, defaults, options),
				UglifyJS = require('uglify-js'),
				compressor = UglifyJS.Compressor(settings.compressor);

			return this.edit(function (blob) {

				try {

					var header = getHeaderComment(settings.header, blob.content),
						ast = UglifyJS.parse(blob.content, {filename: blob.source});

					ast.figure_out_scope();
					ast = ast.transform(compressor);
					ast.figure_out_scope();
					ast.compute_char_frequency();
					ast.mangle_names();

					blob.content = header + ast.print_to_string(settings.beautifier);
github telerik / kendo-ui-core / build / kendo-meta.js View on Github external
function minify(code, filename) {
    var ast;
    if (code instanceof U2.AST_Node) {
        ast = code;
    } else {
        ast = U2_parse(code, { filename: filename });
    }
    var compressor = U2.Compressor({
        unsafe       : true,
        hoist_vars   : true,
        warnings     : false,
        pure_getters : true,
    });
    ast.figure_out_scope();
    ast = ast.transform(compressor);
    ast.figure_out_scope();
    ast.compute_char_frequency();
    ast.mangle_names({
        except: [ "define" ]
    });
    return ast;
}
github jlooper / MIKE / sample-app / public / kendo / bower_components / kendo-ui / src / build / kendo-meta.js View on Github external
function minify(code, filename) {
    var ast;
    if (code instanceof U2.AST_Node) {
        ast = code;
    } else {
        ast = U2_parse(code, { filename: filename });
    }
    var compressor = U2.Compressor({
        unsafe       : true,
        hoist_vars   : true,
        warnings     : false,
        pure_getters : true,
    });
    ast.figure_out_scope();
    ast = ast.transform(compressor);
    ast.figure_out_scope();
    ast.compute_char_frequency();
    ast.mangle_names({
        except: [ "define" ]
    });
    return ast;
}
github fanatid / django-requests-monitor / grunt.js View on Github external
grunt.registerTask("minjs", "Generate minifed JavaScript and SourceMap from file", function() {
    var toplevel = UglifyJS.parse(fs.readFileSync(path.join(__dirname, grunt.config("coffee.dest"))).toString());
    toplevel.figure_out_scope();
    var compressed_ast = toplevel.transform(UglifyJS.Compressor());
    compressed_ast.figure_out_scope();
    compressed_ast.compute_char_frequency();
    compressed_ast.mangle_names();

    var source_map = UglifyJS.SourceMap();
    var stream = UglifyJS.OutputStream({source_map: source_map});
    compressed_ast.print(stream);
    fs.writeFileSync(path.join(__dirname, grunt.config("coffee.dest")), stream.toString());
    //fs.writeFileSync(path.join(__dirname, grunt.config("coffee.dest") + ".map"), source_map.toString());
  });
};
github daffl / connect-injector / examples / minify.js View on Github external
var uglify = function (code) {
  var toplevel = UglifyJS.parse(code);

  toplevel.figure_out_scope();

  var compressor = UglifyJS.Compressor({
    warnings: false
  });
  var compressed = toplevel.transform(compressor);

  compressed.figure_out_scope();
  compressed.compute_char_frequency();
  compressed.mangle_names();

  return compressed.print_to_string();
};
github johno / naka / cli.js View on Github external
).then(stream => {
      fs.writeFileSync('dist/bundle.js', stream)

      const ast = Uglify.parse(stream)
      ast.figure_out_scope()
      const compressor = Uglify.Compressor()
      const compressedAst = ast.transform(compressor)
      fs.writeFileSync('dist/bundle.min.js', compressedAst.print_to_string())
    })
}