How to use google-closure-compiler - 10 common examples

To help you get started, we’ve selected a few google-closure-compiler 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 Erkaman / regl-anim / bin / gallery.js View on Github external
fs.writeFile(jsFile, bundle, function (err) {
    if (err) {
      throw err
    }

    console.log('minify ', jsFile, ' -> ', minFile)

    var closureCompiler = new ClosureCompiler({
      js: jsFile,
      compilation_level: 'SIMPLE',
      js_output_file: minFile
    })

    closureCompiler.run(function (exitCode, stdOut, stdErr) {
      fs.readFile(minFile, function (err, data) {
        if (err) {
          throw err
        }
        console.log('minified ', minFile)
        console.log('stdout: ', stdOut)
        console.log('stderr: ', stdErr)
        writePage(file, data) // output as div tag here.
      })
    })
github ionic-team / stencil / scripts / build-core.ts View on Github external
var ClosureCompiler = require('google-closure-compiler').compiler;

    var opts = {
      js: closurePrepareFilePath,
      externs: EXTERNS_CORE,
      language_out: 'ECMASCRIPT5',
      compilation_level: 'ADVANCED_OPTIMIZATIONS',
      assume_function_wrapper: 'true',
      warning_level: 'QUIET',
      rewrite_polyfills: 'false',
      // formatting: 'PRETTY_PRINT',
      // debug: 'true'
    };

    var closureCompiler = new ClosureCompiler(opts);

    return new Promise((resolve, reject) => {
      closureCompiler.run((exitCode: number, stdOut: string, stdErr: string) => {
        if (stdErr) {
          console.log('core, closureCompiler exitCode', exitCode, 'stdErr', stdErr);
          reject(stdErr);

        } else {
          var content = stdOut;

          var match = /function\(\){"tricks-are-for-closure"}/.exec(content);
          if (!match) {
            fs.writeFileSync(closurePrepareFilePath, content);
            throw 'postClosure: something done changed!'
          }
github ionic-team / stencil / src / bindings / web / scripts / build.core.js View on Github external
var ClosureCompiler = require('google-closure-compiler').compiler;

  var opts = {
    js: inputFilePath,
    externs: path.join(__dirname, 'externs.js'),
    language_out: 'ECMASCRIPT5',
    compilation_level: 'ADVANCED_OPTIMIZATIONS',
    assume_function_wrapper: 'true',
    warning_level: 'VERBOSE',
    rewrite_polyfills: 'false',
    warning_level: 'QUIET',
    // formatting: 'PRETTY_PRINT',
    // debug: 'true'
  };

  var closureCompiler = new ClosureCompiler(opts);

  return new Promise(function(resolve, reject) {
    console.log(closureCompiler.commandArguments.join(' '));

    closureCompiler.run(function(exitCode, stdOut, stdErr) {
      if (stdErr) {
        console.log('closureCompiler exitCode', exitCode, 'stdErr', stdErr);
        reject(stdErr);

      } else {
        util.writeFile(outputFilePath, stdOut).then(() => {
          resolve();
        });
      }
    });
  });
github teppeis / duck / src / compiler-core.ts View on Github external
async function compile(
  extendedOpts: ExtendedCompilerOptions
): Promise<{ stdout: string; stderr: string | undefined }> {
  let opts = extendedOpts.compilerOptions;
  if (isInAwsLambda()) {
    rewriteNodePathForAwsLambda(opts);
  }
  // Avoid `spawn E2BIG` error for too large arguments
  if (opts.js && opts.js.length > 100) {
    opts = convertToFlagfile(opts);
  }
  if (extendedOpts.warningsWhitelist) {
    opts.warnings_whitelist_file = createWarningsWhitelistFile(extendedOpts.warningsWhitelist);
  }
  const compiler = new ClosureCompiler(opts as any);
  if (extendedOpts.batch) {
    compiler.JAR_PATH = null;
    try {
      const { getNativeImagePath } = await import("google-closure-compiler/lib/utils");
      compiler.javaPath = getNativeImagePath();
    } catch {
      throw new Error("Installed google-closure-compiler is too old for batch mode.");
    }
  }
  return new Promise((resolve, reject) => {
    compiler.run((exitCode: number, stdout: string, stderr?: string) => {
      if (exitCode !== 0) {
        return reject(new CompilerError(stderr || "No stderr", exitCode));
      }
      resolve({ stdout, stderr });
    });
github ampproject / amphtml / build-system / compile / closure-compile.js View on Github external
nailgunPort,
        'org.ampproject.AmpCommandLineRunner',
        '--',
      ].concat(compilerOptions);
      pluginOptions.platform = ['native']; // nailgun-runner isn't a java binary
      initOptions.extraArguments = null; // Already part of nailgun-server
    } else {
      // For other platforms, or if nailgun is explicitly disabled, use AMP's
      // custom runner.jar
      closureCompiler.compiler.JAR_PATH = require.resolve(
        `../runner/dist/${nailgunPort}/runner.jar`
      );
    }
  }

  return closureCompiler.gulp(initOptions)(compilerOptions, pluginOptions);
}
github elix / elix / elements / demos / bower_components / shadydom / gulpfile.js View on Github external
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
 */

'use strict';

/* eslint-env node */
/* eslint-disable no-console */

let gulp = require('gulp');
let compilerPackage = require('google-closure-compiler');
let sourcemaps = require('gulp-sourcemaps');
let rollup = require('rollup-stream');
let rename = require('gulp-rename');
let source = require('vinyl-source-stream');
let buffer = require('vinyl-buffer');
let closureCompiler = compilerPackage.gulp();
let uglify = require('gulp-uglify');
let buble = require('rollup-plugin-buble')
let header = require('gulp-header');

let licenseHeader =
`/*
@license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
`;
github Kashomon / glift / deps / glift-core / dev / closure-compiler.js View on Github external
'use strict';


/**
 *
 */

const closureCompiler = require('google-closure-compiler').gulp({
  // extraArguments: ['-Xms2048m']
});

/**
 * defaultCompile passes defaults to the closureCompiler
 *
 * @param {string} outName whatever defaultCompile produces.
 *
 * @return {object} whatever closureCompiler returns.
 */
var defaultCompile = function(outName) {
  if (outName == '') {
    throw new Error('Name is required but was not provided')
  }

  return closureCompiler({
github golangtokyo / codelab / docs / bower_components / google-prettify / Gruntfile.js View on Github external
src: ['*.js', '*.css', 'skins/*.css'],
          dest: 'google-code-prettify/'
        }]
      }
    },

    // grunt-contrib-clean
    clean: {
      js: ['src/prettify.js', 'src/run_prettify.js', 'loader/*.js'],
      css: ['loader/*.css', 'loader/skins/*.css'],
      zip: ['distrib/*.zip']
    }
  });

  // load plugins that provide tasks
  require('google-closure-compiler').grunt(grunt);
  grunt.loadTasks('./tasks');
  grunt.loadNpmTasks('grunt-preprocess');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-compress');
  grunt.loadNpmTasks('grunt-contrib-clean');

  // register task aliases
  grunt.registerTask('default', [
    //'clean',
    'preprocess',
    'copy:prettify',
    'gcc',
    'copy:langs',
    'aliases',
github google / code-prettify / Gruntfile.js View on Github external
src: ['*.js', '*.css', 'skins/*.css'],
          dest: 'google-code-prettify/'
        }]
      }
    },

    // grunt-contrib-clean
    clean: {
      js: ['src/prettify.js', 'src/run_prettify.js', 'loader/*.js'],
      css: ['loader/*.css', 'loader/skins/*.css'],
      zip: ['distrib/*.zip']
    }
  });

  // load plugins that provide tasks
  require('google-closure-compiler').grunt(grunt);
  grunt.loadTasks('./tasks');
  grunt.loadNpmTasks('grunt-preprocess');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-compress');
  grunt.loadNpmTasks('grunt-contrib-clean');

  // register task aliases
  grunt.registerTask('default', [
    //'clean',
    'preprocess',
    'copy:prettify',
    'gcc',
    'copy:langs',
    'aliases',
github scurker / currency.js / Gruntfile.js View on Github external
'<%= minified %>': '<%= minified %>'
        }
      },
      options: {
        stripBanners: true,
        banner: '<%= banner %>',
        // Allow for the original banner to be stripped
        process: function(src, filepath) {
          return filepath === 'currency.js' ? src.replace(/^\/\*!/, '/*') : src;
        }
      }
    }

  });

  require('google-closure-compiler').grunt(grunt);
  require('matchdep').filterAll('grunt-*').forEach(grunt.loadNpmTasks);

  grunt.registerTask('build', ['closure-compiler', 'concat', 'sync']);
  grunt.registerTask('default', ['build']);

};