Support importScripts ?

24 views
Skip to first unread message

Jackie Han

unread,
Mar 13, 2021, 7:29:22 AM3/13/21
to Closure Compiler Discuss
Hi

I would like closure compiler can import all files specified by importScripts and output a single bundle minified file. But I don't find closure compiler support it.

For example, a service woker file sw.js, that use importScripts(a.js, b.js ...) statement import multiple js files.
java -jar $CLOSURE_JAR --js_output_file="sw.min.js" "sw.js"
I hope above command can bundle and minify a.js, b.js, sw.js together and output sw.min.js . But current it only minify sw.js file.

Seems to have a long history, I don't know why closure compiler not support. However, it supports JS module (import statment).

Jackie Han

unread,
Mar 13, 2021, 7:42:48 AM3/13/21
to Closure Compiler Discuss
Work around method is easy.

Let sw.js only contains  importScripts() statements, then
java -jar $CLOSURE_JAR --js_output_file="sw.min.js" "a.js" "b.js" ...

Bradford Smith

unread,
Mar 15, 2021, 1:23:36 PM3/15/21
to Closure Compiler Discuss
Hi,

Yes, the workaround method you pointed out is easy.
When the number of imported scripts is relatively small, it's easy to manually create a closure-compiler command line that compiles them all.
When the number is large, it should still be relatively easy to create a script or something to pull the list out of your source code and create the closure-compiler command line.

Adding a feature like this into closure-compiler would require that we clearly define what use-cases we support,
which may be harder than you think, and then define appropriate command line options and determine how the feature will interact with lots of other things, etc.

These would definitely be open-source-only use-cases since we don't have any inside Google.
Past experience tells me that adding more open-source-only use-cases is not a good idea, because we cannot support them well.
They don't serve the open source community well, and they create a drag on our ability to improve support for our primary use-cases.

Sorry & best regards,
Bradford

Jackie Han

unread,
Mar 15, 2021, 1:51:29 PM3/15/21
to closure-comp...@googlegroups.com
In the past, I fed all files to closure-compiler, and then generated a single large file. That works well.

Recently, I tried to use importScripts for worker and import/export for ES modules. I just realized that it doesn't automatically discover other files like JavaScript/Browser engine does. Since it is designed this way, that is Ok.

Anyway, thank you for your reply.

--

---
You received this message because you are subscribed to a topic in the Google Groups "Closure Compiler Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/closure-compiler-discuss/4wTs_JUyFnQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to closure-compiler-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/closure-compiler-discuss/dd47e3c2-83b5-4971-ba33-cf6eddafa3a1n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages