Adding support for closure compiler and some documentation
in the README about how to use it. git-svn-id: http://svn.openlayers.org/trunk/openlayers@11448 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -1,14 +1,43 @@
|
||||
The OpenLayers build tool supports several different
|
||||
forms of compressing your javascript code, and a method
|
||||
of describing build profiles to create customized
|
||||
OpenLayers builds with only the components you need.
|
||||
|
||||
## HowTo: Build & deploy "Shrunk" Single File Library version of OpenLayers ##
|
||||
When building a file, you can choose to build with several
|
||||
different compression options to the Python-based build.py
|
||||
script. The following is an example script:
|
||||
|
||||
* Build:
|
||||
python build.py -c closure full OpenLayers-closure.js
|
||||
|
||||
cd build
|
||||
./build.py
|
||||
cd ..
|
||||
This script selects the 'closure' compression mechanism,
|
||||
uses a config file called 'full.cfg', and writes the output
|
||||
to OpenLayers-closure.js.
|
||||
|
||||
* Upload the result to the server: e.g.
|
||||
The options available for compression are:
|
||||
|
||||
scp build/OpenLayers.js openlayers@openlayers.org:openlayers.org/htdocs/code/
|
||||
* closure
|
||||
This requires you to have a closure-compiler.jar in your
|
||||
tools directory. You can do this by fetching the compiler
|
||||
from:
|
||||
|
||||
http://closure-compiler.googlecode.com/files/compiler-latest.zip
|
||||
|
||||
Then unzipping that file, and placing compiler.jar into tools
|
||||
and renaming it closure-compiler.jar.
|
||||
|
||||
* closure_ws
|
||||
This uses the closure compiler webservice. This will only work
|
||||
for files source Javascript files which are under 1MB. (Note that
|
||||
the default OpenLayers full build is not under 1MB.)
|
||||
|
||||
* jsmin
|
||||
jsmin is the default compiler, and uses the Python-based
|
||||
jsmin script to compress the Javascript.
|
||||
|
||||
* minimize
|
||||
This is a simple whitespace removing Python script, designed
|
||||
to fill in when other tools are unavailable.
|
||||
|
||||
* none
|
||||
None will leave the Javascript uncompressed.
|
||||
|
||||
|
||||
@@ -12,6 +12,11 @@ def build(config_file = None, output_file = None, options = None):
|
||||
have_compressor.append("jsmin")
|
||||
except ImportError:
|
||||
print "No jsmin"
|
||||
try:
|
||||
import closure
|
||||
have_compressor.append("closure")
|
||||
except ImportError, E:
|
||||
print "No closure (%s) % E"
|
||||
try:
|
||||
import closure_ws
|
||||
have_compressor.append("closure_ws")
|
||||
@@ -51,6 +56,8 @@ def build(config_file = None, output_file = None, options = None):
|
||||
minimized = minimize.minimize(merged)
|
||||
elif use_compressor == "closure_ws":
|
||||
minimized = closure_ws.minimize(merged)
|
||||
elif use_compressor == "closure":
|
||||
minimized = closure.minimize(merged)
|
||||
else: # fallback
|
||||
minimized = merged
|
||||
print "Adding license file."
|
||||
|
||||
21
tools/closure.py
Normal file
21
tools/closure.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import sys
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
path = os.path.join(os.path.dirname(__file__), "closure-compiler.jar")
|
||||
if not os.path.exists(path):
|
||||
raise Exception("No closure-compiler.jar at %s; read README.txt!" % path)
|
||||
|
||||
def minimize(code):
|
||||
ntf = tempfile.NamedTemporaryFile()
|
||||
ntf.write(code)
|
||||
ntf.flush()
|
||||
|
||||
ntf2 = tempfile.NamedTemporaryFile()
|
||||
|
||||
os.system("java -jar %s --js %s --js_output_file %s" % (path, ntf.name, ntf2.name))
|
||||
ntf2.seek(0)
|
||||
data = ntf2.read()
|
||||
ntf.close()
|
||||
ntf2.close()
|
||||
return data
|
||||
@@ -22,5 +22,7 @@ def minimize(code):
|
||||
response = conn.getresponse()
|
||||
data = response.read()
|
||||
conn.close()
|
||||
print "%.3f seconds to compile", time.time() - t
|
||||
if data.startswith("Error"):
|
||||
raise Exception(data)
|
||||
print "%.3f seconds to compile" % (time.time() - t)
|
||||
return data
|
||||
|
||||
Reference in New Issue
Block a user