swc-project/swc

Autogenerated Named AMD module names

オープン

#4,014 opened on 2022/03/14

 (9 件のコメント) (0 件のリアクション) (0 人の担当者)Rust (1,389 件のフォーク)batch import
enhancementhelp wanted

Repository metrics

Stars
 (33,411 個のスター)
PR merge metrics
 (平均マージ 1d 18h) (30d で 37 merged PRs)

説明

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.

コントリビューターガイド