简体   繁体   中英

How do I include the dependencies for google closure

I run the very basic file:

goog.provide('test');

goog.require('goog.net.XhrIo');
goog.require('goog.json.Serializer');
goog.require('goog.dom');
goog.require('goog.ui.HoverCard');
goog.require('goog.positioning');
goog.require('goog.dom.dataset');

but I get

test.js:3: ERROR - required "goog.net.XhrIo" namespace never provided
goog.require('goog.net.XhrIo');

on compiling with

java -d32 -client -jar compiler/compiler.jar --js compiler/closure-library/closure/goog/base.js --js test.js --warning_level=VERBOSE

how does it know to look for the goog libraries?

Edit:

I also tried using the online one at: http://closure-compiler.appspot.com/home and still get:

    JSC_MISSING_PROVIDE_ERROR: required "goog.net.XhrIo" namespace never provided at line 3 character 0 in test.js
goog.require('goog.net.XhrIo');
^
JSC_MISSING_PROVIDE_ERROR: required "goog.json.Serializer" namespace never provided at line 4 character 0 in test.js
goog.require('goog.json.Serializer');
^
JSC_MISSING_PROVIDE_ERROR: required "goog.dom" namespace never provided at line 5 character 0 in test.js
goog.require('goog.dom');
^
JSC_MISSING_PROVIDE_ERROR: required "goog.ui.HoverCard" namespace never provided at line 6 character 0 in test.js
goog.require('goog.ui.HoverCard');
^
JSC_MISSING_PROVIDE_ERROR: required "goog.positioning" namespace never provided at line 7 character 0 in test.js
goog.require('goog.positioning');
^
JSC_MISSING_PROVIDE_ERROR: required "goog.dom.dataset" namespace never provided at line 8 character 0 in test.js
goog.require('goog.dom.dataset');

It's important to remember that Google Closure is a collection of tools .

Though the tools are synergistic, Google has maintained a fair degree of independence between these tools. The Closure Compiler can work without the Closure Library, the Closure Library can work without the Closure Compiler. Both can work without Closure Templates, etc.

The closurebuilder Python scripts were made and included with to provide some things the Closure Compiler lacked. Nowadays however, you should rarely have to use them.

The Closure Compiler fairly recently allowed wildcard expressions to solve this particular problem.

java -d32 -client -jar compiler/compiler.jar \
    --closure_entry_point=test               \
    --only_closure_dependencies              \
    --warning_level=VERBOSE                  \
    compiler/closure-library/**

Every file in compiler/closure-library/ is examined to see whether it provides the necessary namespaces. Anything other files will not be included ( only_closure_dependencies ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM