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

在 vite 的 preview 模式下 components.d.ts 文件被修改 #419

Closed
Allen-1998 opened this issue Jun 13, 2022 · 1 comment · Fixed by #447
Closed

在 vite 的 preview 模式下 components.d.ts 文件被修改 #419

Allen-1998 opened this issue Jun 13, 2022 · 1 comment · Fixed by #447

Comments

@Allen-1998
Copy link

问题描述

当我执行 vite preview 预览打包后的结果时,components.d.ts 文件总是会自动被修改,例如 element plus 的导入会被移除掉:
image

我知道我可以通过放弃对文件的更改来恢复它,但是每次都要手动执行这一步会感觉有些麻烦。

尝试的解决方案

目前我的处理方式是通过判断 process.env.NODE_ENV === ‘production’ 来控制这个插件的引入,就像下面一样:

const isProduction = process.env.NODE_ENV === 'production'

export default defineConfig({
  plugins: [
    // other plugins ...
    !isProduction &&
      Components({
        // components options ...
      }),
  ],
})

因为预览环境下实际上并不需要使用这个插件,所以通过这种方式可以解决我遇到的问题。

更多

提出这个 issue 主要是为了帮助遇到了同样问题的朋友,以及讨论有没有更好的解决方案。

@Allen-1998
Copy link
Author

或许有办法使 vite 插件只在开发环境下启用吗?我查阅了文档但是没有找到相关的内容,比较接近理想中答案的是docs: vite plugins,或许可以给这里的 apply 添加一种新的属性,例如 development

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

Successfully merging a pull request may close this issue.

1 participant