CLOSURE-COMPILER(1)

πŸ“¦
version 20130227+rhino Β· 3 versions
, in debian bookworm, debian trixie, ubuntu noble

okay bestie, hydrate, get comfy, we're reading a man page together πŸ’– This is the manual page for closure-compiler, and yep it lives in section 1 of the manual. It's a long one so it comes in two parts, and this is part 1. No skipping, we're doing the whole thing. 🫢


✨ NAME ✨

closure-compiler β€” the optimising compiler for ECMAScript (JavaScript) programs. It makes your JS go zoom. πŸŽοΈπŸ’¨

🌈 SYNOPSIS 🌈

closure-compiler [ OPTION ... ]
closure-compiler --help

πŸŽ€ DESCRIPTION πŸŽ€

The Closure Compiler Application is the command-line interface to the Closure Compiler, which is part of the Closure Tools project. iykyk.

So what does it actually do, bestie? The Closure Compiler is a tool for making ECMAScript (JavaScript) download and run faster. It:

  • parses your program,
  • analyzes it,
  • removes dead code,
  • and rewrites + minimizes whatever's left over. 🧹✨

It also checks syntax, variable references, and types, and it warns you about common pitfalls. It's giving "your strict but loving friend who reads your code and tells you the truth." πŸ’…


πŸ’– OPTIONS πŸ’–

Okay this is the big one. Every single flag, no cap, no skips.

  • --help β€” tells you how to use the Closure Compiler Application. The classic "just ask for help" move.
  • --version β€” prints the Closure Compiler version, and it goes to stderr, not stdout. Noted. πŸ‘€
  • --accept_const_keyword β€” allows usage of the const keyword. Let const live.
  • --angular_pass β€” generates $inject properties for AngularJS, for functions annotated with @ngInject.
  • --charset CHARSET β€” specifies CHARSET as the input and output charset for all files. By default, we accept UTF-8 as input and output US_ASCII. The duality. πŸ¦‹
  • --closure_entry_point ENTRYPOINT β€” specifies entry point ENTRYPOINT to the program. These must be goog.provide'd symbols. Any goog.provide'd symbols that are not a transitive dependency of the entry points get removed. Files without goog.provides, and their dependencies, will always be left in. If any entry points are specified, then the manage_closure_dependencies option gets set to true and all files get sorted in dependency order. It just does that automatically, bestie. πŸ‘‘
  • --common_js_entry_module MODULEFILE β€” specifies the root of your common JS dependency hierarchy to be MODULEFILE. That's your main script. The main character. ⭐
  • --common_js_module_path_prefix PREFIX β€” specifies a path prefix PREFIX to be removed from CommonJS module names. Trimming the fat. βœ‚οΈ
  • --compilation_level LEVEL β€” sets the compilation level to LEVEL.

Values: WHITESPACE_ONLY, SIMPLE_OPTIMIZATIONS, ADVANCED_OPTIMIZATIONS.

  • --create_name_map_files β€” specifies that variable renaming and property renaming map files will be produced as {binary name}_vars_map.out and {binary name}_props_map.out.
Note that this flag cannot be used in conjunction with either variable_map_output_file or property_map_output_file. Pick a lane, babe. πŸ™ˆ
  • --create_source_map MAPFILE β€” specifies a source map file MAPFILE; a map mapping the generated source files back to the original source file will be output to the specified path. The %outname% placeholder expands to the name of the output file that the source map corresponds to. πŸ—ΊοΈβœ¨
  • --debug β€” enables debugging options. Turn it on, see what happens, we love a little chaos. πŸ’€
  • --define DEFINITION, --D DEFINITION, -D DEFINITION β€” overrides the value of a variable annotated @define. The format of DEFINITION is <name>[=<val>], where <name> is the name of a @define variable and <val> is a boolean, number, or a single-quoted string that contains no single quotes. If [=<val>] is omitted, the variable is marked true.
  • --externs EXTERNFILE β€” specifies that the file EXTERNFILE contains JavaScript externs.

You can specify this option multiple times to specify additional EXTERNFILE files. Stack 'em. πŸ₯ž

  • --extra_annotation_name TAGNAME β€” specifies TAGNAME to append to the whitelist of tag names in JSDoc.

You can specify this option multiple times to append additional TAGNAME values.

  • --flagfile FILE β€” specifies that FILE contains additional command-line options. A file of options, iconic. πŸ“„
  • --formatting FORMATOPTION β€” specifies the formatting option FORMATOPTION to apply to the output JS.

Values: PRETTY_PRINT, PRINT_INPUT_DELIMITER, SINGLE_QUOTES

  • --generate_exports β€” generates export code for those marked with @export.
  • --js INFILE β€” specifies INFILE as an input filename.

You can specify this option multiple times to append additional INFILE names.

  • --js_output_file OUTFILE β€” specifies OUTFILE as the primary output filename.

If not specified, output is written to stdout. Surprise! 🎁

  • --jscomp_error WARNCLASS β€” makes the named class of warnings WARNCLASS an error. 😀

See Warning Classes, below, for the list of valid WARNCLASS names.

  • --jscomp_off WARNCLASS β€” turns off the named class of warnings WARNCLASS. πŸ™ˆ

See Warning Classes, below, for the list of valid WARNCLASS names.

  • --jscomp_warning WARNCLASS β€” makes the named class of warnings WARNCLASS a normal warning.

See Warning Classes, below, for the list of valid WARNCLASS names.

  • --language_in LANGSPEC β€” specifies the input sources conform to the language LANGSPEC.

Values: ECMASCRIPT3 (default), ECMASCRIPT5, ECMASCRIPT5_STRICT

  • --logging_level LEVEL β€” specifies LEVEL as the logging level (standard java.util.logging.Level values) for Compiler progress. It does not control errors or warnings for the JavaScript code under compilation. Different thing, bestie, don't get it twisted. πŸ’…
  • --manage_closure_dependencies β€” automatically sorts dependencies so that a file that goog.provides symbol X will always come before a file that goog.requires symbol X. If an input provides symbols, and those symbols are never required, then that input will not be included in the compilation. Bye, unused code. πŸ‘‹
  • --module MODULESPEC β€” specifies the JavaScript module specification MODULESPEC.

The format for MODULESPEC is <name>:<num-js-files>[:[<dep>,...][:]]]. Module names must be unique. Each dep is the name of a module that this module depends on. Modules must be listed in dependency order, and JS source files must be listed in the corresponding order. Where --module flags occur in relation to --js flags is unimportant. Provide the value auto to trigger module creation from CommonJS modules.

  • --module_output_path_prefix PREFIX β€” specifies the filename prefix PREFIX for filenames of compiled JS modules. <module-name>.js will be appended to this prefix. Directories will be created as needed. Use with --module.
  • --module_wrapper WRAPPER β€” specifies WRAPPER as output wrapper for a JavaScript module (optional).

The format of WRAPPER is <name>:<wrapper>. The module name must correspond with a module specified using --module. The wrapper must contain %s as the code placeholder. The %basename% placeholder can also be used to substitute the base name of the module output file.

  • --only_closure_dependencies β€” only includes files in the transitive dependency of the entry points (specified by closure_entry_point). Files that do not provide dependencies will be removed. This supersedes manage_closure_dependencies. It's the upgrade, periodt. πŸ‘‘
  • --output_manifest MANIFESTFILE β€” prints out a list of all the files in the compilation to MANIFESTFILE.

If --manage_closure_dependencies is on, this will not include files that got dropped because they were not required.

The %outname% placeholder expands to the JS output file. If you're using modularization, using %outname% will create a manifest for each module. One for each, we love to see it. πŸ“‹βœ¨

  • --output_module_dependencies DEPFILE β€” prints out a JSON file DEPFILE of dependencies between modules. 🧾
  • --output_wrapper WRAPPER β€” interpolates output into WRAPPER at the place denoted by the marker token %output%. Use marker token %output|jsstring% to do js string escaping on the output.
  • --print_ast β€” prints a dot file describing the internal abstract syntax tree, and exits. 🌳
  • --print_pass_graph β€” prints a dot file describing the passes that will get run, and exits.
  • --print_tree β€” prints out the parse tree and exits.
  • --process_closure_primitives β€” processes built-ins from the Closure library, such as goog.require(), goog.provide(), and goog.exportSymbol().
  • --process_common_js_modules β€” processes CommonJS modules to a concatenable form.
  • --process_jquery_primitives β€” processes built-ins from the JQuery library, such as jQuery.fn and jQuery.extend().
  • --property_map_input_file MAPFILE β€” specifies MAPFILE as containing the serialized version of the property renaming map produced by a previous compilation.
  • --property_map_output_file MAPFILE β€” saves the serialized version of the property renaming map produced to MAPFILE.
  • --source_map_format FORMAT β€” produces the source map in format FORMAT.

Values: V1, V2, V3, DEFAULT. DEFAULT produces V2.

  • --summary_detail_level LEVEL β€” specifies the compilation summary detail level LEVEL.

Values: 0 (never print summary), 1 (print summary only if there are errors or warnings), 2 (print summary if the checkTypes diagnostic group is enabled, see --jscomp_warning), 3 (always print summary). The default level is 1.

  • --third_party β€” checks source validity but does not enforce Closure style rules and conventions. Guest mode, basically. πŸ™ˆ
  • --transform_amd_modules β€” transforms AMD to CommonJS modules. A glow-up, fr. πŸ¦‹
  • --translations_file TRANSFILE β€” specifies TRANSFILE as the source of translated messages. Currently only supports XTB.
  • --translations_project PROJECT β€” scopes all translations to the specified project.

When specified, use different message ids so that messages in different projects can have different translations.

  • --use_only_custom_externs β€” specifies that the default externs should be excluded.
  • --use_types_for_optimization β€” experimental: performs additional optimizations based on available information.
⚠️ Inaccurate type annotations may result in incorrect results. This one is highkey a risk, bestie, be careful.
  • --variable_map_input_file MAPFILE β€” specifies MAPFILE as containing the serialized version of the variable renaming map produced by a previous compilation.
  • --variable_map_output_file MAPFILE β€” saves the serialized version of the variable renaming map produced to MAPFILE.
  • --warning_level LEVEL β€” specifies the warning level to use.

Values: QUIET, DEFAULT, VERBOSE.

  • --warnings_whitelist_file LISTFILE β€” suppresses warnings listed in LISTFILE. Each line should be of the form <file-name>:<line-number>? <warning-description>.

πŸ’€ Warning Classes πŸ’€

The jscomp_error, jscomp_warning, and jscomp_off flags all require a WARNCLASS warning class name as a parameter. These are the names that are valid:

  • accessControls
  • ambiguousFunctionDecl
  • checkRegExp
  • checkTypes
  • checkVars
  • const
  • constantProperty
  • deprecated
  • duplicateMessage
  • es5Strict
  • externsValidation
  • fileoverviewTags
  • globalThis
  • internetExplorerChecks
  • invalidCasts
  • misplacedTypeAnnotation
  • missingProperties
  • nonStandardJsDocs
  • suspiciousCode
  • strictModuleDepCheck
  • typeInvalidation
  • undefinedNames
  • undefinedVars
  • unknownDefines
  • uselessCode
  • visibility

πŸŽ€ EXAMPLE πŸŽ€

Okay bestie, here's the whole thing in one tiny little line, the moment you've been waiting for:

closure-compiler --js hello.js --js_output_file hello-compiled.js

That's it. That's the ritual. ✨

This command creates a new file called hello-compiled.js, which contains the compiled program. So you feed it hello.js, it does its little compiler thing, and boom β€” you've got a whole new baby file sitting there with your compiled code inside it. slay. πŸ’…


πŸ“œ HISTORY πŸ“œ

So the Closure Tools project? It's an effort by Google engineers to open source the tools used in many of Google's sites and web applications, for use by the wider Web development community. Basically they were like "we built these iconic little tools for ourselves, let's share them with everyone" and honestly? we love that for us. 🫢

This manual page was written by Ben Finney <ben+ecmascript@benfinney.id.au> to document the closure-compiler command for Debian. It is free software and may be used by others under the terms of the Apache license, version 2.0. So it's not just free as in "free to read," it's actually free free. 🌈


πŸ‘‘ AUTHOR πŸ‘‘

Ben Finney <ben+ecmascript@benfinney.id.au>

(Yes, that's the whole section. Short and iconic, main character energy, no notes.) πŸ’œ


Apache license, version 2.0.


And that's a wrap on the whole page, bestie!! πŸ¦‹ This version is the one from 2014-01-07, and it lives in the CLOSURE-COMPILER(1) section of the manual β€” so if you ever forget any of this, you know exactly where to find it. Go compile something gorgeous. πŸ“πŸ’–

πŸ“¦ where this page comes from