Create an ES module with exports

151 views
Skip to first unread message

Maksim Ivanov

unread,
Jun 20, 2022, 11:34:53 PM6/20/22
to closure-comp...@googlegroups.com
Hello,

How do I make Closure Compiler preserve the ES "export" statements I write in the code?

To clarify my use case, I have a collection of .js files that I want to compile into a single ES module file that can be included by other projects (like Chrome Extensions; most likely they are built without Closure Compiler). Previously I successfully used traditional exports (goog.exportSymbol() et al.) for this, but now I'm trying to migrate this to ES "export" statements (the main driver is that my library will be used in Manifest V3 Chrome Extensions that require the usage of ES modules).


Thanks,
Maksim

rish...@google.com

unread,
Jun 21, 2022, 2:17:26 AM6/21/22
to Closure Compiler Discuss
You can use the --chunk_output_type=ES_MODULES flag. It will output es modules and cross chunk references will utilize the import and export statements. Would that suffice, or do you strictly require to collapse the chunks into a "single" ES module?

Maksim Ivanov

unread,
Jun 21, 2022, 10:30:12 AM6/21/22
to closure-comp...@googlegroups.com
When I tried "--chunk_output_type=ES_MODULES", it added an empty export to the file. The original "export" statement was lost, so this doesn't solve the problem of exporting a function to other (non-closure-compiled) code.


--

---
You received this message because you are subscribed to the Google Groups "Closure Compiler Discuss" group.
To unsubscribe from this group and stop receiving emails from it, 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/356fc4d2-f694-49cc-a7a5-9fad51ac976bn%40googlegroups.com.


Chinthoorie Yogalingam

unread,
Jun 21, 2022, 8:12:44 PM6/21/22
to Closure Compiler Discuss
From the information I gathered, this is not possible in the Closure Compiler.
Reply all
Reply to author
Forward
0 new messages