Create an ES module with exports

已查看 150 次
跳至第一个未读帖子

Maksim Ivanov

未读,
2022年6月20日 23:34:532022/6/20
收件人 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

未读,
2022年6月21日 02:17:262022/6/21
收件人 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

未读,
2022年6月21日 10:30:122022/6/21
收件人 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

未读,
2022年6月21日 20:12:442022/6/21
收件人 Closure Compiler Discuss
From the information I gathered, this is not possible in the Closure Compiler.
回复全部
回复作者
转发
0 个新帖子