How to use the google-closure-compiler.compiler function in google-closure-compiler

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 regl-project / regl / bin / build-min.js View on Github external
.on('close', function () {
    console.log('minifying script: ', UNCHECKED_FILE)

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

    closureCompiler.run(function (exitCode, stdOut, stdErr) {
      console.log('closure stdout:', stdOut)
      console.log('closure stderr:', stdErr)
      process.exit(exitCode)
    })
  })
github FontoXML / fontoxpath / build.js View on Github external
return new Promise((resolve, reject) => {
		console.log('Starting closure compiler build');
		new Compiler({
			assume_function_wrapper: true,
			debug: !!doDebugBuild,
			language_in: 'stable',
			rewrite_polyfills: false,
			generate_exports: true,
			language_out: 'ES5_STRICT',
			create_source_map: './dist/fontoxpath.js.map',
			source_map_location_mapping: `${TEMP_BUILD_DIR}|../${TEMP_BUILD_DIR}`,
			jscomp_warning: reportUnknownTypes ? ['reportUnknownTypes'] : [],
			jscomp_error: [
				'accessControls',
				'checkDebuggerStatement',
				'checkRegExp',
				'checkTypes',
				'checkVars',
				'const',
github SaulDoesCode / Crafter.js / build.js View on Github external
function BundlePolyfills() {
    let path = './polyfills/';
    new ClosureCompiler({
        js: fs.readdirSync(path).map(file => {
            if (file.includes('.js')) return path + file
        }),
        compilation_level: 'SIMPLE',
        language_in: 'ECMASCRIPT5_STRICT',
        language_out: 'ECMASCRIPT5_STRICT',
        js_output_file: './dist/polyfills.min.js'
    }).run(() => {
        console.log('Success -> Polyfills Bundled and Minified!\n');
    });
}
github surma / underdash / generate_site.js View on Github external
return new Promise((resolve, reject) => {
    const compiler = new closure({
      js: file,
      compilation_level: 'ADVANCED'
    })
    .run((exitCode, stdOut, stdErr) => {
      if (exitCode === 0) return resolve(stdOut);
      reject(stdErr);
    });
  });
}
github raphamorim / react-ape / scripts / rollup / plugins / closure-plugin.js View on Github external
return new Promise((resolve, reject) => {
    const closureCompiler = new ClosureCompiler(flags);
    closureCompiler.run(function(exitCode, stdOut, stdErr) {
      if (!stdErr) {
        resolve(stdOut);
      } else {
        reject(new Error(stdErr));
      }
    });
  });
}