Skip to content

Conversation

kevinmarrec
Copy link
Contributor

Description

Introduce the syncMode option to control the behavior of generating files.

Default to default

  • append: only append the new components to the existing files.
  • overwrite: overwrite the whole existing files with the current components.
  • default: use append strategy when using dev server, overwrite strategy when using build.

Linked Issues

Resolves #804 (Please confirm ⚠️)

Linked Pull Requests

Closes #844

Additional context

Current logic is removeUnused === !this._server, which means only remove unused components when building and is dependent on vite mode ("Is there a dev server ?").

To prevent any breaking change, a default mode is required to follow current behavior, while append mode will always append which means also append with vite build.

Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@kevinmarrec kevinmarrec marked this pull request as ready for review September 12, 2025 15:47
@kevinmarrec kevinmarrec requested a review from antfu as a code owner September 12, 2025 15:47
@antfu antfu merged commit 574443a into unplugin:main Sep 20, 2025
6 checks passed
@xiaweiss
Copy link

@kevinmarrec I found a bug

doc say default: use append strategy when using dev server, overwrite strategy when using build.

But in reality, the overwrite was executed when using dev server.

@xiaweiss
Copy link

@antfu 合并请求里,没有对 syncMode: 'default' 选项做任何处理,只是不等于 'append' 就默认执行了 'overwrite' 的效果。

导致在启动 dev-server 开发时,运行了一个页面,会把其他页面的 icon 自动导入全部删除。

 setupViteServer(server: ViteDevServer) {
    if (this._server === server)
      return

    this._server = server
    this._removeUnused = this.options.syncMode !== 'append'
    this.setupWatcher(server.watcher)
  }

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 this pull request may close these issues.

Why keeping unused?
3 participants