Skip to content

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

@Allen-1998

Description

@Allen-1998

问题描述

当我执行 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 主要是为了帮助遇到了同样问题的朋友,以及讨论有没有更好的解决方案。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy