You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/FAQs.md
+47Lines changed: 47 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,53 @@ After you set up a repository, you can substitute in any tools you'd like.
7
7
8
8
If you think the tool would be broadly useful to most consumers of this template, feel free to [file a feature request](https://github.com/JoshuaKGoldberg/create-typescript-app/issues/new?assignees=&labels=type%3A+feature&projects=&template=03-feature.yml&title=%F0%9F%9A%80+Feature%3A+%3Cshort+description+of+the+feature%3E) to add it in.
9
9
10
+
## How can I add dual CommonJS / ECMAScript Modules emit?
11
+
12
+
First, I'd suggest reading [TypeScript Handbook > Modules - Introduction](https://www.typescriptlang.org/docs/handbook/modules/introduction.html) to understand how CommonJS (CJS) and ECMAScript (ESM) came to be.
13
+
14
+
Then:
15
+
16
+
1. In `tsup.config.ts`, change the [tsup `format` option](https://tsup.egoist.dev/#bundle-formats) from `["esm"]` to `["cjs", "esm"]`
17
+
2. Add a [`package.json``"exports"` entry](https://nodejs.org/api/packages.html#subpath-exports) like:
18
+
19
+
<!-- eslint-disable jsonc/sort-keys -->
20
+
21
+
```jsonc package.json
22
+
{
23
+
"exports": {
24
+
".": {
25
+
"types": {
26
+
"import":"./lib/index.d.ts",
27
+
"require":"./lib/index.d.cts"
28
+
},
29
+
"import":"./lib/index.js",
30
+
"require":"./lib/index.cjs"
31
+
}
32
+
}
33
+
}
34
+
```
35
+
36
+
<!-- eslint-enable jsonc/sort-keys -->
37
+
38
+
That should be it!
39
+
40
+
To be safe, consider checking with [arethetypeswrong](https://arethetypeswrong.github.io):
41
+
42
+
1. Run `pnpm build`
43
+
2. Run `npm pack`
44
+
3. Upload that generated `.tgz` file to [arethetypeswrong.github.io](https://arethetypeswrong.github.io)
45
+
46
+
### Why doesn't `create-typescript-app` have an option to dual emit CJS and ESM?
47
+
48
+
Dual CJS/ESM emit is a stopgap solution while the JavaScript ecosystem migrates towards full ESM support in most-to-all popular user packages.
49
+
Most packages newly created with `create-typescript-app` should target just ESM by default.
50
+
51
+
Some packages published with `create-typescript` legitimately need dual CJS/ESM output because they're used by frameworks that don't yet fully support ESM.
52
+
That's reasonable.
53
+
54
+
Unless you know a package needs to support a CJS consumer, please strongly consider keeping it ESM-only (the `create-typescript-app` default).
55
+
ESM-only packages have a smaller footprint by virtue of including fewer files.
56
+
10
57
## Is there a way to pull in template updates to previously created repositories?
0 commit comments