Optimize JavaScript code using Closure Compiler Service API, within CLI, gulp and webpack.
npm install ncompiler -g
--no-optional
flag can be added if you do not want to handle character encoding.
npm install ncompiler -g --no-optional
Command that is provided this package, has several options similar to Java based Closure Compiler application.
ncompiler --output_wrapper_file banner.js --js_output_file out.js lib/**/*.js 1.js 2.js 3.js
For more details, please run command with --help
flag.
You can also use API in this package to get communicate with Closure Compiler Service. To use, install this package locally.
npm install ncompiler
Included sources in this package are both JavaScript and TypeScript.
import { compile, CompilationLevel, IApiOption, IApiResult, IApiFailedResult } from 'ncompiler';
let options: IApiOption = {
jsCode: 'console.log( "¡hola!" )',
compilationLevel: CompilationLevel.WhitespaceOnly,
};
compile(options)
.then(
(result: IApiResult) => console.log(result.compiledCode),
(reason: IApiFailedResult) => console.error(reason.message));
This package contains plugin for gulp. The plugin is stored in plugins.gulp
field. Function of the plugin takes only one optional argument that is same as for compile()
.
let ncompiler = require('ncompiler');
gulp.task('...', () =>
gulp
.src(...)
.pipe(ncompiler.plugins.gulp())
.pipe(gulp.dest(...))
);
This package contains plugin for webpack. The plugin is stored in plugins.webpack
field. Constructor of the plugin takes only one optional argument that is same as for compile()
.
let ncompiler = require('ncompiler');
module.exports = {
...,
plugins: [
...,
new ncompiler.plugins.webpack(),
],
};