-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type definitions are not generated for library mode build #2049
Comments
You can add https://github.com/ezolenko/rollup-plugin-typescript2 to your plugins to generate the types (check the docs for options). In your import typescript2 from "rollup-plugin-typescript2"
export default {
plugins: [
{
...typescript2(),
apply: 'build',
},
]
} |
I was wondering why this should need an extra plugin when everything is written in TypeScript and the Vite supports it out of the box. Adding the above mentioned plugin would involve the transpilation twice. |
Vite just strips out the types, and let you choose how to use the types (for example, using your IDE or running tsc on the side). Using the typescript compiler in Vite would slow down the processing pipeline |
FYI you don't need a plugin... you can also just use |
This does not generate type definitions of the component, but it is possible with the plugin, does it require additional configuration? |
@odex21 I've created good-enough-for-me declarations files by running this command after
Not sure if there is a better way, but it seems to work for my use case! |
Currently I use
import path from 'path'
import typescript from 'rollup-plugin-typescript2'
import json from '@rollup/plugin-json'
import image from '@rollup/plugin-image'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import vue from 'rollup-plugin-vue' // v5.x for vue2
import styles from 'rollup-plugin-styles'
import { createFilter } from '@rollup/pluginutils'
const filter = createFilter(/\.vue$/)
export default {
input: path.resolve(__dirname, 'src/index.ts'),
output: {
file: path.resolve(__dirname, `dist/${name}.dts.js`),
format: 'es',
externalLiveBindings: false
},
external: [
// external modules
],
plugins: [
// create a simple plugin to resect style for .vue file
{
name: 'resect-vue-style',
transform: async (code, id) => {
if (!filter(id)) return null
return {
code: code.replace(/<style.*>[\s\S]*<\/style.*>/ig, ''),
map: null
}
}
},
json({ namedExports: false }),
image(),
nodeResolve({ preferBuiltins: true }),
vue({ needMap: false }),
styles({
mode: 'extract',
onExtract: () => false
}),
typescript({
check: true,
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
tsconfigOverride: {
compilerOptions: {
sourceMap: false,
declaration: true,
declarationMap: true
},
exclude: ['**/__tests__']
}
})
]
} finished then remove the output file I make a script const fs = require('fs-extra')
const path = require('path')
const execa = require('execa')
main()
async function main() {
await execa('vite', ['build'], { stdio: 'inherit' })
await execa('rollup', ['-c'], { stdio: 'inherit' })
await fs.remove(path.resolve(__dirname,`dist/${name}.dts.js`))
}
{
"scripts": {
"build": "node build.js"
}
} |
This works perfectly fine in Vite. @yyx990803 mentioned
In package.json
Then This gives me a dist folder containing:
|
Describe the bug
Type definitions are not generated for library mode build
Reproduction
System Info
vite
version: 2.xThe text was updated successfully, but these errors were encountered: