Skip to content
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

[Feat Request] Is there any way to generate auto-import.d.ts manually? #464

Open
3 tasks done
floyd-li opened this issue Dec 28, 2023 · 3 comments
Open
3 tasks done
Labels
enhancement New feature or request

Comments

@floyd-li
Copy link

Clear and concise description of the problem

We use unplugin-auto-import in our project and it's really powerful!
the question is that when we develop locally it will auto generate auto-import.d.ts file and it cause conflict when merge code, so we add it into .gitignore and it will cause build error in CI system likeJenkins since it can not find the file like #288

Suggested solution

if there's any way to generate auto-import.d.ts file manually?

Alternative

No response

Additional context

No response

Validations

@floyd-li floyd-li added the enhancement New feature or request label Dec 28, 2023
@dvlden
Copy link

dvlden commented Jan 4, 2024

I am looking into this just now as well. Same thing, for Jenkins pipeline.
In some projects, we're using Vite SSG and the export command bound to it actually creates the auto generated files.

Not sure why that's not the case for build, but if you find out how to trigger it, let me know. I'll do the same, if I figure it out before someone else provides a feedback.

Looks like it should first build the output and then check for typescript errors.
vite build && vue-tsc --noEmit

For my use-case, I guess it's better to check for type errors in PR, rather than allowing it to pass to the build step.

@nathanielobrown
Copy link

nathanielobrown commented Mar 15, 2024

I'm also very interested in a way to generate this file manually for the same reasons. vite build does the job, but it's slow and I want a fast method so my type checking CI step can be speedy. Interestingly for https://github.com/unplugin/unplugin-vue-components vite optimize (which is fast) generates components.d.ts, I wonder if this project could be updated to do the same?

I've come up with a workaround for my project. I'd appreciate input from any Vite expert as to whether this is a good idea or not, but I'm instantiating the AutoImport plugin and calling the .buildStart method at module level before calling defineConfig. This has the affect that vite optimize generates auto-imports.d.ts.

I guess it might be better to separate out this hack so it's not run for every single Vite command or tool that uses the vite.config.ts file. Thoughts anyone?

Example:

import { defineConfig } from "vitest/config"
import Vue from "@vitejs/plugin-vue"
import Components from "unplugin-vue-components/vite"
import AutoImport from "unplugin-auto-import/vite"

const autoImportPlugin = AutoImport({
  imports: ["vue", "vue-router"],
  dts: "src/auto-imports.d.ts",
})

// Ensure .d.ts file is created when running `vite optimize`
autoImportPlugin.buildStart()

export default defineConfig({
  plugins: [
    Vue({
      include: [/\.vue$/],
    }),
    autoImportPlugin,
    Components({
      extensions: ["vue"],
      dts: "src/components.d.ts",
      include: [/\.vue$/, /\.vue\?vue/],
    }),
  ],
})

@vitjaz
Copy link

vitjaz commented May 13, 2024

Seems like we need to commit this files...
antfu comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants