Minify/compress javascript and css on deployment in webapp2?
-
28-10-2019 - |
Question
Is it possible to make App Engine automatically minify certain javascript and css files upon deployment, just like Jinja2 automatically compiles templates for you? I've seen some Python scripts that do minification, but how do I integrate them with webapp2?
I'm using the latest Google App Engine version with Python 2.7.
Solution
You can write a simple script to do so.
# -- update_batch.py --
import sys
import os
def main():
if len(sys.argv) == 1:
return
appId = sys.argv[1]
print "appId", appId
# Your script to minify javascipt
#os.chdir(r".\template")
#cmd = r'jscom.py ./js/new/xxx_plugin.js xxx_plugin.js %s.appspot.com'%appId
#os.system(cmd)
os.chdir("..")
# Perform appcfg.py to update GAE server
cmd = r'"C:\Program Files\Google\google_appengine\appcfg.py"'
os.system(cmd + " update . " + " -A %s"%appId)
#os.system(cmd + " backends . " + " update worker " + " -A %s"%appId)
if __name__ == "__main__":
main()
# Usage update_batch.py YOUR_APP_ID_HERE
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow