vitejs / vite-plugin-vue

Vite Vue Plugins
MIT License
501 stars 154 forks source link

feat: add a feature option to support custom component id generator #461

Closed Jinjiang closed 1 week ago

Jinjiang commented 1 month ago

Description

To help developers customize the way it generates component id for particular cases.

Additional context

Added this option into features field:

/**
 * Customize the component ID generation strategy.
 * - `'filepath'`: hash the file path (relative to the project root)
 * - `'filepath-source'`: hash the file path and the source code
 * - `function`: custom function that takes the file path, source code,
 *   whether in production mode, and the default hash function as arguments
 * - **default:** `'filepath'` in development, `'filepath-source'` in production
 */
componentIdGenerator?:
  | 'filepath'
  | 'filepath-source'
  | ((
      filepath: string,
      source: string,
      isProduction: boolean | undefined,
      getHash: (text: string) => string,
    ) => string)

What is the purpose of this pull request?

Before submitting the PR, please make sure you do the following

pkg-pr-new[bot] commented 1 month ago

Open in Stackblitz

pnpm add https://pkg.pr.new/@vitejs/plugin-vue@461
pnpm add https://pkg.pr.new/@vitejs/plugin-vue-jsx@461

commit: 0c4af22