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: README.md
+29-9
Original file line number
Diff line number
Diff line change
@@ -141,28 +141,48 @@ When generating type declarations (`.d.ts` files), this also bundles and tree-sh
141
141
```
142
142
143
143
### Aliases
144
-
Aliases can be configured in the [import map](https://nodejs.org/api/packages.html#imports), defined in `package.json#imports`.
145
144
146
-
For native Node.js import mapping, all entries must be prefixed with `#` to indicate an internal [subpath import](https://nodejs.org/api/packages.html#subpath-imports). _Pkgroll_ takes advantage of this behavior to define entries that are _not prefixed_ with `#` as an alias.
145
+
#### Import map
147
146
148
-
Native Node.js import mapping supports conditional imports (eg. resolving different paths for Node.js and browser), but _Pkgroll_ does not.
147
+
You can configure aliases using the [import map](https://nodejs.org/api/packages.html#imports) in `package.json#imports`.
149
148
150
-
> ⚠️ Aliases are not supported in type declaration generation. If you need type support, do not use aliases.
149
+
In Node.js, import mappings must start with `#` to indicate an internal [subpath import](https://nodejs.org/api/packages.html#subpath-imports). However, _Pkgroll_ allows defining aliases **without** the `#` prefix.
150
+
151
+
> [!NOTE]
152
+
> While Node.js supports conditional imports (e.g., different paths for Node.js vs. browsers), _Pkgroll_ does not.
You can also define aliases in `tsconfig.json` using `compilerOptions.paths`:
171
+
172
+
```json5
173
+
{
174
+
"compilerOptions": {
175
+
"paths": {
176
+
"@foo/*": ["./src/foo/*"],
177
+
"~bar": ["./src/bar/index.ts"]
178
+
}
179
+
}
180
+
}
181
+
```
182
+
183
+
> [!TIP]
184
+
> The community is shifting towards using import maps (`imports`) as the source of truth for aliases because of their wider support across tools like Node.js, TypeScript, Vite, Webpack, and esbuild.
185
+
166
186
### Target
167
187
168
188
_Pkgroll_ uses [esbuild](https://esbuild.github.io/) to handle TypeScript and JavaScript transformation and minification.
0 commit comments