Closed mddanish00 closed 1 year ago
You want to add custom d.ts files to the build folder?
Yes. It is possible?
In theory,using copy plugin after build plugin should work.
export default defineConfig(() => {
return {
plugins: [buildPlugin(), copyPlugin()],
};
});
Sorry for the late reply. I tried that before in the exact order. It will not work at all if I put in src. So, I put the file in a different folder. It will come out with another error. I think Path does not exist or something. I think your plugin will probably create lib and es folder, but at the time of the copy, it still does not exist.
@Miracutor the vite-plugin-static-copy
also work,
dest
is relative to output dir dist
, the code below will copy the projectRoot/src/a/b/*.d.ts
to the folder projectRoot/lib
viteStaticCopy({
targets: [
{
src: 'projectRoot/src/a/b/*.d.ts',
dest: '../lib',
},
],
}),
I already refactored my project to not use that d.ts, so I no longer needed this. But for the sake of any future dev looking to do this, I tested with @samonxian suggestion with vite-plugin-static-copy
. It works with some addition.
viteStaticCopy({
targets: [
{
src: 'projectRoot/src/a/b/*.d.ts',
dest: '../lib',
transform: null,
},
],
}),
Without the transform: null, I get Error: EBUSY: resource busy or locked, copyfile
. Maybe because I also enable emitDeclaration? Anyway, this approach work.👍
emitDeclaration feature is wonderful but sometimes I need to write code in JavaScript and declare type manually using d.ts files. I tried to use ignoreInput and ignore d.ts files. (I used this array instead, ['**\/*.spec.*', '**\/*.test.*'])
But that will also process d.ts. file which I really don't need so, I restore ignoreInput to normal.
I tried to use the Vite feature like copying files from the public folder to the build folder but it will also ignore d.ts from the folder. I tried to use the Vite copy plugin but it is also the same...
Is there any way to add a manually created d.ts file (excluding vite.d.ts I don't know its function) into the build without processing it?