Provides utility functionalities to call closure tools in nodejs.
Last updated a year ago by theseanl .
LGPL-3.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install closure-tools-helper 
SYNC missed versions from official npm registry.

Closure Tools Helper

This module contains closure tools compiled jars and various helper function to make dependency management easier.

This module exports 4 functions:

const closureTools = require('closure-tools-helper');


Closure Compiler api

The closure compiler api abstracts the module system of closure compiler to something based on entry points, much similar to rollup.

(await closureTools.compiler(baseCompilerFlags, sourceGlob, entryPoints)).src()

Note the requirements of await, due to building compiler flag being an async operation. The plugin controls --module and -js compiler flags. All the other flags must be provided with baseCompilerFlags argument.

sourceGlob is a glob pattern that provides js sources to the compiler. All files referenced by entryPoints must be provided by the glob.

entryPoints is an array where each element follows the below interface.

interface ICompilerEntryPoint {
     * This is what is used in `goog.require()`.
     * `null` means there is no entry module, but it can have some extraSources.
     * module name, used in specifying dependencies, and also used in output file name.
     * Array of module names that this bundle depends on.
     * Any files that are not reachable via `goog.require`s but still need to be provided
     * to the compiler.

Closure Templates api

const compiler = require('closure-tools-helper');

gulp.task('build-soy', () => {
    return compiler.templates([.../* Command line args passed to SoyToJsSrcCompiler.jar */])

gulp.task('extract-soy-messages', () => {
    return compiler.extractTemplateMsg([.../* Command line args passed to SoyMsgExtractor.jar */])

Compiler apis returns a readable stream of the stdout. Users of the package should explicitly call .src() in order to turn the stream into flowing mode (same as google-closure-compiler gulp plugin).

Runtime i18n

Closure templates by default supports compile-time i18n. Provide a second argument TemplatesI18nOptions to post-process js files generated by soy compiler to enable i18n. Its interface is what follows:

interface ITemplatesI18nOptions {
     * This is a string to replace `goog.getMsg` with.
     * This is a string that will be appended right after the `goog.module(..)` expression.
     * This must match files generated by the compiler jar.
    outputPath?:string // If provided, files will be written to `outputPath/fileName`.

If runtime i18n is enabled, it will additionally transform legacy-style goog.provide modules into goog.module, so that a consumer can import the compiled templates by using const templates = goog.require(''), or import templates from '' if the consumer is using tsickle.


Import or reference ./third-party/soyutils.js or ./third-party/soyutils_usegoog.js.

Closure Stylesheets api

const compiler = require('closure-tools-helper');

gulp.task('build-gss', () => {
    return compiler.stylesheets([.../* Command line args passed to closure-stylesheets.jar */])

Compiler apis returns a readable stream of the stdout. User of the package should explicitly call .src() to turn the stream into a flowing mode.


yarn add
yarn add<specific-tag>



Current Tags

  • 1.0.0                                ...           latest (a year ago)

1 Versions

  • 1.0.0                                ...           a year ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (9)
Dev Dependencies (4)
Dependents (0)

Copyright 2014 - 2016 © |