Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/0xjacky/vite-plugin-build-id
https://github.com/0xjacky/vite-plugin-build-id
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/0xjacky/vite-plugin-build-id
- Owner: 0xJacky
- Created: 2024-05-11T14:02:08.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-11-02T18:03:50.000Z (10 days ago)
- Last Synced: 2024-11-02T18:17:18.480Z (10 days ago)
- Language: TypeScript
- Size: 164 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# vite-plugin-build-id
A Vite plugin that automatically generates a unique `build_id` each time the project is compiled.
Developed by [0xJacky](https://jackyu.cn/) and [Hintay](https://blog.kugeek.com/).
## Install
```bash
pnpm i -D vite-plugin-build-id
```## Usage
In `vite.config.ts`:
```ts
import { defineConfig } from 'vite'export default defineConfig({
plugins: [vitePluginBuildId()]
})
```This will create a `version.json` file in your `src` folder with the following structure:
```json
{
"version": "{the-verion-in-package.json}",
"build_id": 1,
"total_build": 1
}
```- **version**: Mirrors the version field from your `package.json`.
- **build_id**: Starts at `1` for each new version and increments with each build.
- **total_build**: Tracks the total number of builds since the plugin was first configured.If you leave the `disableBumpSameStatus` option enabled (its default setting), a `.status_hash` file will be created in the root directory to monitor file changes within the workspace. This file helps the plugin determine whether to increment the `build_id`.
To prevent it from being tracked by version control, add the following entry to your `.gitignore` file:
```
**/.status_hash
```### Tips
If you'd like to use a CI build number as the `build_id`, set the `buildIdEnv` option. For example, in a Drone CI environment:
```ts
import { defineConfig } from 'vite'export default defineConfig({
plugins: [
vitePluginBuildId({
buildIdEnv: 'DRONE_BUILD_NUMBER',
}),
]
})
```## Options
```ts
interface Options {
/**
* Prepares the version file before the Vite build process
*
* Default: `false`
* Useful for special cases where the version file needs to be available before the build.
*/
prepare?: boolean/**
* Specifies the destination folder
*
* Default is `src`
*/
destination?: string/**
* Enables inclusion of the latest git commit hash
*
* Default is `false`
* Compare git's commit hash with the last time it was generated to avoid unwanted build id bump.
*/
enableCommitHash?: boolean/**
* Disables build ID increment when no changes are detected in the git workspace
*
* Default is `true`
* Prevents `build_id` from incrementing if the current workspace status is unchanged.
*/
disableBumpSameStatus?: boolean/**
* Specifies the environment variable for setting the build ID
*
* Default is `true`
* Useful for integrating CI/CD build numbers as the build ID.
*/
buildIdEnv?: string
}
```