In order to use closure library in our chrome extension, we created an empty source.js which only included all the modules from closure library that we required.
Sample source.js
(source.js goes inside myproject directory.)
goog.provide('myproject.start')
goog.require('goog.dom');
goog.require('goog.dom.query');
goog.require('goog.net.XhrIo');
Then we used closure-builder on this file and closure-library source to generate a single output file which contained all the relevant source of all closure library modules we required.
Relevant command:
closure-library/closure/bin/build/closurebuilder.py \
--root=closure-library/ \
--root=myproject/ \
--namespace="myproject.start"
--output_mode=compiled
--compilation_level=SIMPLE_OPTIMIZATIONS
Note, you cannot use ADVANCED_OPTIMIZATIONS
otherwise all unused functions will be stripped off which is not what we want.
Include this in manifest.json
"js": [
"compiled.js",
"content.js"
]
So, we need to generate compiled.js
only when we need to include some new module from closure-library code which was rare and not every time we change our content.js.