Skip to content

Commit

Permalink
docs: Instructions for adding shims configuration (#740)
Browse files Browse the repository at this point in the history
  • Loading branch information
rxliuli committed Oct 17, 2022
1 parent 5161f8f commit fd0d787
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/README.md
Expand Up @@ -488,6 +488,21 @@ For more details:
tsup --help
```

### Inject cjs and esm shims

Enabling this option will fill in some code when building esm/cjs to make it work, such as `__dirname` which is only available in the cjs module and `import.meta.url` which is only available in the esm module

```ts
import { defineConfig } from 'tsup'

export default defineConfig({
shims: true,
})
```

- When building the cjs bundle, it will compile `import.meta.url` as `typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href`
- When building the esm bundle, it will compile `__dirname` as `path.dirname(fileURLToPath(import.meta.url))`

## Troubleshooting

### error: No matching export in "xxx.ts" for import "xxx"
Expand Down

0 comments on commit fd0d787

Please sign in to comment.