Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 14, 2024. It is now read-only.

Package for the JS version of closure-compiler for use via NPM

License

NotificationsYou must be signed in to change notification settings

google/closure-compiler-js

Note: This package is now deprecated. Distribution of the JavaScript version has been moved to the main npm distribution athttps://www.npmjs.com/package/google-closure-compiler. This package will continueto work, but no new versions of the package will be published.


Check, compile, transpile, optimize and compress JavaScript with Closure Compiler in JS.

This repo tracks issues related to the publication to npmjs.org and associated plugins.Any bugs not related to the plugins themselves should be reported to themain repository.

Unlike other packages, this allows Closure Compiler to run entirely in JS.Java is not required.

This is an experimental release - meaning some features are not available and performance may not be on-par with the Java implementation -details here.

Usage

These instructions will continue to work, but the package is deprecated.Development has moved tohttps://www.npmjs.com/package/google-closure-compiler.

First, install the latest version:

yarn add google-closure-compiler-js --dev# ornpm install --save-dev google-closure-compiler-js

The module supports modern web browsers as well as Node v4 LTS, and providescompile as a low-level method to compile JavaScript.By default, this compiles ES6 to ES5 and includes the default set of ECMAScript externs files.For example:

constcompile=require('google-closure-compiler-js').compile;constflags={jsCode:[{src:'const x = 1 + 2;'}],};constout=compile(flags);console.info(out.compiledCode);// will print 'var x = 3;\n'

Or to install the command-line version, do:

npm install -g google-closure-compiler-js

You should now be able to rungoogle-closure-compiler-js as a command.Thegoogle-closure-compiler-js command can read from stdin or from a file.For example:

google-closure-compiler-js code.js> minified.js

Rungoogle-closure-compiler-js --help for full usage information.

Build Systems

Webpack

Yourwebpack.config.js should look like this:

constClosureCompiler=require('google-closure-compiler-js').webpack;constpath=require('path');module.exports={entry:[path.join(__dirname,'app.js')],output:{path:path.join(__dirname,'dist'),filename:'app.min.js'},plugins:[newClosureCompiler({options:{languageIn:'ECMASCRIPT6',languageOut:'ECMASCRIPT5',compilationLevel:'ADVANCED',warningLevel:'VERBOSE',},})]};

Gulp

Yourgulpfile.js should contain a task like this:

constcompiler=require('google-closure-compiler-js').gulp();gulp.task('script',function(){returngulp.src('./path/to/src.js',{base:'./'})// your other steps here.pipe(compiler({compilationLevel:'SIMPLE',warningLevel:'VERBOSE',outputWrapper:'(function(){\n%output%\n}).call(this)',jsOutputFile:'output.min.js',// outputs single filecreateSourceMap:true,})).pipe(gulp.dest('./dist'));});

Flags

FlagDefaultUsage
angularPassfalseGenerate $inject properties for AngularJS for functions annotated with @ngInject
applyInputSourceMapstrueCompose input source maps into output source map
assumeFunctionWrapperfalseEnable additional optimizations based on the assumption that the output will be wrapped with a function wrapper. This flag is used to indicate that "global" declarations will not actually be global but instead isolated to the compilation unit. This enables additional optimizations.
checksOnlyfalseDon't generate output. Run checks, but no optimization passes.
compilationLevelSIMPLESpecifies the compilation level to use.
Options: WHITESPACE_ONLY, SIMPLE, ADVANCED
dartPassfalse
definesnullOverrides the value of variables annotated with@define, an object mapping names to primitive types
envBROWSERDetermines the set of builtin externs to load.
Options: BROWSER, CUSTOM
exportLocalPropertyDefinitionsfalse
generateExportsfalseGenerates export code for those marked with @export.
languageInES6Sets what language spec that input sources conform to.
languageOutES5Sets what language spec the output should conform to.
newTypeInffalseChecks for type errors using the new type inference algorithm.
outputWrappernullInterpolate output into this string, replacing the token%output%
polymerVersionnullSpecify the Polymer version pass to use.
preserveTypeAnnotationsfalse
processCommonJsModulesfalseProcess CommonJS modules to a concatenable form, i.e., supportrequire statements.
renamePrefixNamespaceSpecifies the name of an object that will be used to store all non-extern globals.
rewritePolyfillstrueRewrite ES6 library calls to use polyfills provided by the compiler's runtime.
useTypesForOptimizationfalseEnable or disable the optimizations based on available type information. Inaccurate type annotations may result in incorrect results.
warningLevelDEFAULTSpecifies the warning level to use.
Options: QUIET, DEFAULT, VERBOSE
jsCode[]Specifies the source code to compile.
externs[]Additional externs to use for this compile.
createSourceMapfalseGenerates a source map mapping the generated source file back to its original sources.

Languages

The Closure Compiler supports the following languages:

  • ECMASCRIPT3,ECMASCRIPT5 andECMASCRIPT5_STRICT
  • ECMASCRIPT6 andECMASCRIPT6_STRICT
  • ECMASCRIPT6_TYPED (experimental)
  • ECMASCRIPT_2017 (experimental)

Source Code

Unless you're using Gulp's or Webpack's plugins, you'll need to specify code via flags:

  • BothjsCode andexterns accept an array containing objects in the form{src, path, sourceMap}.
  • Usingpath you can construct a virtual filesystem for use with ES6 or CommonJS imports — although for CommonJS you'll have to setprocessCommonJsModules: true.

Transpilation

The JavaScript version of the Closure-Compiler is transpiled by GWT from the Java source.For more details on the differences in behavior see thesuper sourced files in the mainrepository.

Version History

Closure Compiler release notes can be found on themain repository wiki.

License

Copyright © 2017 The Closure Compiler Authors

Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.

About

Package for the JS version of closure-compiler for use via NPM

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors18


[8]ページ先頭

©2009-2025 Movatter.jp