vite-plugin-dts
vite-plugin-dts copied to clipboard
Add option to exclude import paths from transformation
The new feature from https://github.com/qmhc/vite-plugin-dts/issues/73 allows excluding types just from the aliases. In my scenario, I have a monorepo where each project is an individual project and can have other monorepo's projects in dependency. I'm using 'build.rollupOptions.external' to prevent bundling the other projects into the project itself.
I propose to make 'aliasesExclude' less strict and allow it for any import-path match or respecting the value in the build.rollupOptions.external
.
Config as example:
build: {
lib: {
entry: './index.ts',
name: 'some-project',
formats: ['es'],
fileName: () => 'index.js'
},
rollupOptions: {
external: ['@monorepo/shared']
}
},
resolve: {
alias: [
{
find: /^\/?@monorepo\/([\w-]+)/,
replacement: `${path.resolve(__dirname, '../')}/$1/index.ts`
}
]
},
In the meantime, I have written a workaround:
beforeWriteFile: (filePath, content) => {
return {
filePath,
content: content.replace(/(import\s+.*?\s+from)\s+["'].*?\.\.\/shared\/index.ts["'];/g, '$1 "@monorepo/shared";')
}
}
So it will replace any ../shared/index.ts
for @monorepo/shared