unplugin-ltsdi
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

unplugin-ltsdi

Rollup still does not tree shake dynamic imports (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,\<whatever>")

This will create file which exports what you specified in only param, like this:

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

npm i unplugin-ltsdi
Vite
// vite.config.ts
import LTSDI from 'unplugin-ltsdi/vite'

export default defineConfig({
  plugins: [
    LTSDI({ /* options */ }),
  ],
})

Example: playground/


Rollup
// rollup.config.js
import LTSDI from 'unplugin-ltsdi/rollup'

export default {
  plugins: [
    LTSDI({ /* options */ }),
  ],
}


Webpack
// webpack.config.js
module.exports = {
  /* ... */
  plugins: [
    require('unplugin-ltsdi/webpack')({ /* options */ })
  ]
}


Nuxt
// nuxt.config.js
export default {
  buildModules: [
    ['unplugin-ltsdi/nuxt', { /* options */ }],
  ],
}

This module works for both Nuxt 2 and Nuxt Vite


Vue CLI
// vue.config.js
module.exports = {
  configureWebpack: {
    plugins: [
      require('unplugin-ltsdi/webpack')({ /* options */ }),
    ],
  },
}


esbuild
// 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

// index.d.ts - for example

declare module 'comlink?*' {
  import comlink from 'comlink'
  export = comlink
}

Package Sidebar

Install

npm i unplugin-ltsdi

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

19.3 kB

Total Files

22

Last publish

Collaborators

  • logotip4ik_
  • logotip4ik