google / google/closure-compiler
Producing CommonJS modules
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
Is it possible to use Closure compiler to produce a standalone CommonJS module, for use by dependent external (not managed by the compiler) JS code? That is, to produce a single file that exports its public symbols via CommonJS special `exports` variable?
The problem I'm running into is that:
* with `--process_common_js_modules`, the compiler renames `exports` to `module$path$to$source`, making it impossible to import the compiled source as a CommonJS module
* without `--process_common_js_modules`, the compiler does not resolve CommonJS `require` imports, so other CommonJS modules can't be used as the target module's building blocks.
I believe I understand the motivation for renaming `exports` (prevent name clashes between multiple CommonJS modules concatenated in the single compiled file), but this is not enough if the compiled file is meant to be imported by some other code. Ideally, the `exports` variable would not be renamed in the top-level module that defines the module's public symbols (it still needs to be renamed, as is already the case, in implementation modules the top-level module imports itself).
Contributor guide
Assessment
This issue has not been assessed yet.