unplugin-ltsdi
v0.1.1
Published
"Lazy" Tree shake dynamic imports
Downloads
2
Readme
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.config.ts
import LTSDI from 'unplugin-ltsdi/vite'
export default defineConfig({
plugins: [
LTSDI({ /* options */ }),
],
})
Example: playground/
// rollup.config.js
import LTSDI from 'unplugin-ltsdi/rollup'
export default {
plugins: [
LTSDI({ /* options */ }),
],
}
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-ltsdi/webpack')({ /* options */ })
]
}
// nuxt.config.js
export default {
buildModules: [
['unplugin-ltsdi/nuxt', { /* options */ }],
],
}
This module works for both Nuxt 2 and Nuxt Vite
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-ltsdi/webpack')({ /* options */ }),
],
},
}
// 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
}