swc-project/swc

Autogenerated Named AMD module names

Ouverte

#4 014 ouverte le 14 mars 2022

 (9 commentaires) (0 réaction) (0 personne assignée)Rust (1 389 forks)batch import
enhancementhelp wanted

Métriques du dépôt

Stars
 (33 411 étoiles)
Métriques de merge PR
 (Merge moyen 1j 18h) (37 PRs mergées en 30 j)

Description

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.

Guide contributeur