swc-project/swc

Autogenerated Named AMD module names

开放

#4,014 创建于 2022年3月14日

 (9 条评论) (0 个反应) (0 位负责人)Rust (1,389 个派生)batch import
enhancementhelp wanted

仓库指标

星标
 (33,411 个星标)
PR 合并指标
 (平均合并 1天 18小时) (30 天内合并 37 个 PR)

描述

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.

贡献者指南