Documentation
¶
Overview ¶
Glosure is a convenient HTTP server for the Closure Compiler. It only responds to request for compiled JavaScript and returns error for any other requests.
Note: To force a compile on a request, pass request parameter "force=1".
Example ¶
// Parse the flags if you want to use glog.
flag.Parse()
// Creat a new compiler assuming javascript files are in "example/js".
cc := NewCompiler("./example/js/")
// Use strict mode for the closure compiler. All warnings are treated as
// error.
cc.Strict()
// Or use debug mode.
// cc.Debug()
// Use advanced optimizations.
cc.CompilationLevel = AdvancedOptimizations
http.Handle("/", GlosureServer(cc))
fmt.Println("Checkout http://localhost:8080/sample.min.js")
http.ListenAndServe(":8080", nil)
Index ¶
- Constants
- func GlosureServer(cc Compiler) http.Handler
- func GlosureServerWithRoot(root string) http.Handler
- func ServeHttp(res http.ResponseWriter, req *http.Request, cc *Compiler)
- type ClosureApiResult
- type ClosureError
- type ClosureWarning
- type CompilationLevel
- type Compiler
- func (cc *Compiler) Compile(relOutPath string) error
- func (cc *Compiler) CompileWithClosureApi(jsFiles []string, entryPkgs []string, outPath string) error
- func (cc *Compiler) CompileWithClosureJar(jsFiles []string, entryPkgs []string, outPath string) error
- func (cc *Compiler) Debug()
- func (cc *Compiler) Strict()
- type Formatting
- type Language
- type WarningClass
- type WarningLevel
Examples ¶
Constants ¶
View Source
const ( WhiteSpaceOnly CompilationLevel = "WHITESPACE_ONLY" SimpleOptimizations = "SIMPLE_OPTIMIZATIONS" AdvancedOptimizations = "ADVANCED_OPTIMIZATIONS" )
View Source
const ( Quiet WarningLevel = "QUIET" Default = "DEFAULT" Verbose = "VERBOSE" )
View Source
const ( EmcaScript3 Language = "ECMASCRIPT3" EmcaScript5 = "ECMASCRIPT5" EmcaScript5Strict = "ECMASCRIPT5_STRICT" )
View Source
const ( AccessControls = "accessControls" AmbiguousFunctionDecl = "ambiguousFunctionDecl" CheckEventfulObjectDisposal = "checkEventfulObjectDisposal" CheckRegExp = "checkRegExp" CheckStructDictInheritance = "checkStructDictInheritance" CheckTypes = "checkTypes" CheckVars = "checkVars" Const = "const" ConstantProperty = "constantProperty" Deprecated = "deprecated" DuplicateMessage = "duplicateMessage" Es3 = "es3" Es5Strict = "es5Strict" ExternsValidation = "externsValidation" FileoverviewTags = "fileoverviewTags" GlobalThis = "globalThis" InternetExplorerChecks = "internetExplorerChecks" InvalidCasts = "invalidCasts" MisplacedTypeAnnotation = "misplacedTypeAnnotation" MissingProperties = "missingProperties" MissingProvide = "missingProvide" MissingRequire = "missingRequire" MissingReturn = "missingReturn" NonStandardJsDocs = "nonStandardJsDocs" ReportUnknownTypes = "reportUnknownTypes" SuspiciousCode = "suspiciousCode" StrictModuleDepCheck = "strictModuleDepCheck" TypeInvalidation = "typeInvalidation" UndefinedNames = "undefinedNames" UndefinedVars = "undefinedVars" UnknownDefines = "unknownDefines" UselessCode = "uselessCode" Visibility = "visibility" )
View Source
const DefaultCompiledSuffix = ".min.js"
View Source
const DefaultSourceSuffix = ".js"
Variables ¶
This section is empty.
Functions ¶
func GlosureServer ¶
Creates an http.Handler using the closure compiler.
func GlosureServerWithRoot ¶
Creates a glosure http handler for the given root directory.
Types ¶
type ClosureApiResult ¶
type ClosureApiResult struct {
CompiledCode string
Errors []ClosureError `json:"errors"`
Warnings []ClosureWarning `json:"warnings"`
ServerErrors []struct {
Code int `json:"code"`
Error string `json:"error"`
} `json:"serverErrors"`
}
type ClosureError ¶
type ClosureWarning ¶
type CompilationLevel ¶
type CompilationLevel string
type Compiler ¶
type Compiler struct {
// Path containing all JavaScript sources.
Root string
// Compiled JavaScript suffix. Uses ".min.js" by default.
CompiledSuffix string
// JavaScript source suffix. Uses ".js" by default.
SourceSuffix string
// Error handler.
ErrorHandler http.HandlerFunc
// Path of Closure's "compiler.jar". By default Glosure downloads the latest
// compiler onto Compiler.Root.
CompilerJarPath string
// Compile source javascripts if not compiled or out of date.
CompileOnDemand bool
// Whether to use closure REST api instead of closure jar file. This is
// automatically set to true when java is not installed on the machine.
UseClosureApi bool
// Closure compiler compilation level. Valid levels are: WhiteSpaceOnly,
// SimpleOptimizations (default), AdvancedOptimizations.
CompilationLevel CompilationLevel
// Closure compiler warning level. Valid levels are: Quite, Default, and
// Verbose.
WarningLevel WarningLevel
// Formatting of the compiled output. Valid formattings are: PrettyPrint,
// and PrintInputDelimiter.
Formatting Formatting
// Whether to optimize out all unused JavaScript code.
OnlyClosureDependencies bool
// List of exern JavaScript files.
Externs []string
// Language
Language Language
// JavaScript files that should be included in every compilation.
BaseFiles []string
// Whether to perform an angular pass.
AngularPass bool
// Whether to process jQuery primitives.
ProcessJqueryPrimitives bool
// Warnings that should be treated as errors.
CompErrors []WarningClass
// Warnings.
CompWarnings []WarningClass
// Warnings that are suppressed.
CompSuppressed []WarningClass
// contains filtered or unexported fields
}
Compiler represents a contextual object for the closure compiler containing compilation options. To create a Compiler instance with default options use glosure.NewCompiler().
func NewCompiler ¶
func (*Compiler) CompileWithClosureApi ¶
func (*Compiler) CompileWithClosureJar ¶
type Formatting ¶
type Formatting string
const ( PrettyPrint Formatting = "pretty_print" PrintInputDelimiter = "print_input_delimiter" )
type WarningClass ¶
type WarningClass string
type WarningLevel ¶
type WarningLevel string
Click to show internal directories.
Click to hide internal directories.