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

To help you get started, we’ve selected a few google-closure-compiler-js 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 tentone / nunuStudio / build / build / js / compiler.js View on Github external
const minify = (inName, outName) => {
    console.log(' Minifying ');
    
    const src = readFile(inName);
    
    // seems like there is no pretty print option available
    const flags = {
        jsCode: [{src}],
        languageIn: 'ECMASCRIPT5',
        languageOut: 'ECMASCRIPT5',
        compilationLevel: 'WHITESPACE_ONLY',
        warningLevel: 'QUIET',
    };
    
    const out = compile(flags);
    
    writeFile(outName, out.compiledCode);
};
github googleanalytics / autotrack / bin / build.js View on Github external
src: rollupResult.code,
      path: path.basename(output),
    }],
    compilationLevel: 'ADVANCED',
    useTypesForOptimization: true,
    outputWrapper:
        '(function(){%output%})();\n' +
        `//# sourceMappingURL=${path.basename(output)}.map`,
    assumeFunctionWrapper: true,
    rewritePolyfills: false,
    warningLevel: 'VERBOSE',
    createSourceMap: true,
    externs: [{src: externs}],
  };

  const closureResult = compile(closureFlags);

  if (closureResult.errors.length || closureResult.warnings.length) {
    const rollupMap = await new SourceMapConsumer(rollupResult.map);

    // Remap errors from the closure compiler output to the original
    // files before rollup bundled them.
    const remap = (type) => (item) => {
      let {line, column, source} = rollupMap.originalPositionFor({
        line: item.lineNo,
        column: item.charNo,
      });
      source = path.relative('.', path.resolve(__dirname, '..', source));
      return {type, line, column, source, desc: item.description};
    };

    throw {
github Rich-Harris / butternut / test / bench / closure-bench.js View on Github external
exports.minify = (input, sourcemap) => {
	const out = compile({
		jsCode: [{ src: input }],
		compilationLevel: 'SIMPLE',
		createSourceMap: sourcemap
	});

	return {
		code: out.compiledCode,
		map: out.sourceMap
	};
};
github teambition / teambition-sdk / tools / tasks / bundle.ts View on Github external
.then(() => {
      const source = fs.readFileSync(path.resolve(process.cwd(), output), 'utf8')
      const compilerFlags = {
        jsCode: [{ src: source }],
        compilationLevel: 'ADVANCED',
        languageIn: 'ECMASCRIPT6',
        createSourceMap: true
      }
      const result: any = compiler(compilerFlags)
      const minPath = `dist/bundle/${output.split('/').pop()!.split('.')[1]}.min.js`
      const code = result.compiledCode
      fs.writeFileSync(minPath, code, 'utf8')
      fs.writeFileSync(`${minPath}.map`, result.sourceMap, 'utf8')
      console.info(blue(minPath) + ' ' + getSize(code))
    })
    .catch((e: Error) => console.error(e))
github webmaxru / pwa-guide-ngpoland / gulpfile.js View on Github external
transformBundle: function (bundle) {
            var compilation = Object.assign({}, options, {
                jsCode: options.jsCode ? options.jsCode.concat({ src: bundle }) : [{ src: bundle }]
            });
            console.log('- Closure compiler is optimizing. It can take a minute or two...');
            var transformed = closure.compile(compilation);
            return { code: transformed.compiledCode, map: transformed.sourceMap };
        }
    };
github webmaxru / pwa-guide-ngpoland / gulpfile.ts View on Github external
transformBundle(bundle){
      const compilation = Object.assign({}, options, {
        jsCode: options.jsCode ? options.jsCode.concat({ src: bundle }) : [{ src: bundle }]
      });
	  console.log('- Closure compiler is optimizing. It can take a minute or two...');
      const transformed = closure.compile(compilation);
	  return { code: transformed.compiledCode, map: transformed.sourceMap };
    }
  }
github marko-js / marko / benchmark / size / minify.js View on Github external
gcc: function minifyGCC(src, file) {
        const gcc = require("google-closure-compiler-js");
        const options = {
            jsCode: [{ src: src }],
            languageIn: "ES5"
        };

        const out = gcc.compile(options);

        if (out.errors && out.errors.length) {
            console.error(out.errors);
            throw new Error(`Minification failed for ${file}`);
        }
        return out.compiledCode;
    },
    uglify: function minifyUglifyJS(src, file) {
github andrey-git / home-assistant-custom-ui / script / vulcanize.js View on Github external
function compileJs(file) {
  console.log('Reading ' + file);
  const content = fs.readFileSync(file, 'utf8');
  console.log('Compiling ' + file);
  const flags = {
    jsCode: [{src: content}],
  };
  const out = compile(flags);
  const newName = path.join('build', path.basename(file));
  console.log('Writing ' + newName);
  fs.writeFileSync(newName, out.compiledCode);
  console.log('Done writing');
}
github google / amp-pwa-demo / app.js View on Github external
    .then(code => closure.compile({jsCode: [{src: code}]}).compiledCode);
}
github babel / minify / scripts / benchmark.js View on Github external
"closure-compiler-js"(code) {
    const flags = {
      jsCode: [{ src: code }],
      env: "CUSTOM"
    };
    const out = compile(flags);
    return out.compiledCode;
  }

google-closure-compiler-js

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

Apache-2.0
Latest version published 4 years ago

Package Health Score

66 / 100
Full package analysis