Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/logotip4ik/unplugin-ltsdi
"Lazy" Tree shake dynamic imports
https://github.com/logotip4ik/unplugin-ltsdi
dynamic-import rollup tree-shake vite
Last synced: about 1 month ago
JSON representation
"Lazy" Tree shake dynamic imports
- Host: GitHub
- URL: https://github.com/logotip4ik/unplugin-ltsdi
- Owner: logotip4ik
- License: mit
- Created: 2023-02-03T16:49:22.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-01-19T22:35:36.000Z (11 months ago)
- Last Synced: 2024-09-18T02:22:19.726Z (3 months ago)
- Topics: dynamic-import, rollup, tree-shake, vite
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/unplugin-ltsdi
- Size: 331 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# unplugin-ltsdi
[Rollup still does not tree shake dynamic imports](https://github.com/rollup/rollup/issues/3447) (so vite as well), and fix is pretty simple - to create another file which will reexport functions that are needed. But i am too lazy, so i created this.
> TL;DR
>
> `import("comlink?only=wrap,expose,\")`This will create file which exports what you specified in `only` param, like this:
```js
export { wrap, expose } from 'comlink'
```On build rollup will tree shake that "file" and dynamic import won't weight as much as whole library
## Install
```bash
npm i unplugin-ltsdi
```Vite
```ts
// vite.config.ts
import LTSDI from 'unplugin-ltsdi/vite'export default defineConfig({
plugins: [
LTSDI({ /* options */ }),
],
})
```Example: [`playground/`](./playground/)
Rollup
```ts
// rollup.config.js
import LTSDI from 'unplugin-ltsdi/rollup'export default {
plugins: [
LTSDI({ /* options */ }),
],
}
```
Webpack
```ts
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-ltsdi/webpack')({ /* options */ })
]
}
```
Nuxt
```ts
// nuxt.config.js
export default {
buildModules: [
['unplugin-ltsdi/nuxt', { /* options */ }],
],
}
```> This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite)
Vue CLI
```ts
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-ltsdi/webpack')({ /* options */ }),
],
},
}
```
esbuild
```ts
// esbuild.config.js
import { build } from 'esbuild'
import LTSDI from 'unplugin-ltsdi/esbuild'build({
plugins: [LTSDI()],
})
```
## Typescript / Intellisense
Create a `.d.ts` shim for `?` import like this
```typescript
// index.d.ts - for exampledeclare module 'comlink?*' {
import comlink from 'comlink'
export = comlink
}
```