🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

google-closure-compiler

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-closure-compiler

Check, compile, optimize and compress Javascript with Closure-Compiler

20250609.0.0
latest
Version published
Weekly downloads
160K
3.48%
Maintainers
4
Weekly downloads
 
Created

What is google-closure-compiler?

The google-closure-compiler npm package is a powerful tool for optimizing JavaScript code. It can be used to minify, transpile, and optimize JavaScript, making it faster and more efficient. It also provides advanced features like dead code elimination, type checking, and more.

What are google-closure-compiler's main functionalities?

Minification

This feature allows you to minify JavaScript files, reducing their size and improving load times. The code sample demonstrates how to use the google-closure-compiler to minify a JavaScript file.

const closureCompiler = require('google-closure-compiler').compiler;
const compiler = new closureCompiler({
  js: 'input.js',
  compilation_level: 'SIMPLE',
  js_output_file: 'output.min.js'
});
compiler.run((exitCode, stdOut, stdErr) => {
  console.log(stdOut);
  console.error(stdErr);
});

Transpilation

This feature allows you to transpile JavaScript code from one version of ECMAScript to another. The code sample demonstrates how to transpile ECMAScript 6 code to ECMAScript 5 using google-closure-compiler.

const closureCompiler = require('google-closure-compiler').compiler;
const compiler = new closureCompiler({
  js: 'input.js',
  language_in: 'ECMASCRIPT6',
  language_out: 'ECMASCRIPT5',
  js_output_file: 'output.transpiled.js'
});
compiler.run((exitCode, stdOut, stdErr) => {
  console.log(stdOut);
  console.error(stdErr);
});

Dead Code Elimination

This feature allows you to eliminate dead code, which is code that is never executed, from your JavaScript files. The code sample demonstrates how to use the google-closure-compiler to perform dead code elimination.

const closureCompiler = require('google-closure-compiler').compiler;
const compiler = new closureCompiler({
  js: 'input.js',
  compilation_level: 'ADVANCED',
  js_output_file: 'output.optimized.js'
});
compiler.run((exitCode, stdOut, stdErr) => {
  console.log(stdOut);
  console.error(stdErr);
});

Type Checking

This feature allows you to perform type checking on your JavaScript code, helping to catch type-related errors. The code sample demonstrates how to enable type checking using google-closure-compiler.

const closureCompiler = require('google-closure-compiler').compiler;
const compiler = new closureCompiler({
  js: 'input.js',
  jscomp_warning: 'checkTypes',
  js_output_file: 'output.checked.js'
});
compiler.run((exitCode, stdOut, stdErr) => {
  console.log(stdOut);
  console.error(stdErr);
});

Other packages similar to google-closure-compiler

FAQs

Package last updated on 11 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts