swc-project/swc

Autogenerated Named AMD module names

Aperta

#4014 aperta il 14 mar 2022

 (9 commenti) (0 reazioni) (0 assegnatari)Rust (1389 fork)batch import
enhancementhelp wanted

Metriche repository

Star
 (33.411 stelle)
Metriche merge PR
 (Merge medio 1g 18h) (37 PR mergiate in 30 g)

Descrizione

Describe the feature

Problem

Currently if I want to emit an AMD module, the emitted AMD module will be anonymous unless I set the "moduleId" config option in the .swcrc which will emit a named AMD module with the moduleId as the name.

The problem with this is that this means I need to generate a different .swcrc for each named module which feels very unnecessary.

Proposal

I'd like to propose making it possible to autogenerate the AMD module name based on a moduleRoot (or maybe moduleNameRoot) config option, and generate the AMD module name from the path of the current file relative to the root.

Some example moduleRoot values when transpiling /foo/bar/baz.ts:

  • "moduleRoot": "/" -> define("foo/bar/baz", ...)
  • "moduleRoot": "/foo" -> define("bar/baz", ...)

And obviously I'd want the source maps to work properly too.

If this is as straightforward as I think it is then I'd be willing to learn some Rust and try to implement this with some guidance.

Babel plugin or link to the feature description

No response

Additional context

The TypeScript compiler does something very similar when compiling to AMD with --outFile.

Guida contributor