https://github.com/luxass/unplugin-build-meta
Provide build metadata as a virutal module
https://github.com/luxass/unplugin-build-meta
build metadata unplugin
Last synced: 6 months ago
JSON representation
Provide build metadata as a virutal module
- Host: GitHub
- URL: https://github.com/luxass/unplugin-build-meta
- Owner: luxass
- License: mit
- Created: 2025-04-16T12:06:08.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-06-11T10:18:18.000Z (6 months ago)
- Last Synced: 2025-06-11T11:37:21.856Z (6 months ago)
- Topics: build, metadata, unplugin
- Language: TypeScript
- Homepage:
- Size: 487 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome-rstack - unplugin-build-meta
README
# unplugin-build-meta
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
Import build metadata into your JavaScript/TypeScript projects for Vite, Webpack, Rollup, esbuild and more. Powered by [unplugin](https://github.com/unjs/unplugin).
## Install
```bash
npm install -D unplugin-build-meta
```
## Usage
> [!TIP]
> You can view all examples [here](./examples).
Vite
```ts
// vite.config.ts
import buildMeta from "unplugin-build-meta/vite";
export default defineConfig({
plugins: [
buildMeta({ /* options */ }),
],
});
```
Rollup
```ts
// rollup.config.js
import buildMeta from "unplugin-build-meta/rollup";
export default {
plugins: [
buildMeta({ /* options */ }),
],
};
```
Webpack
```ts
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require("unplugin-build-meta/webpack").default({ /* options */ }),
],
};
```
Nuxt
```ts
// nuxt.config.js
export default defineNuxtConfig({
modules: [
["unplugin-build-meta/nuxt", { /* options */ }]
],
});
```
Astro
```ts
// astro.config.mjs
import { defineConfig } from "astro/config";
import buildMeta from "unplugin-build-meta/astro";
// https://astro.build/config
export default defineConfig({
integrations: [
buildMeta({
/* options */
})
]
});
```
esbuild
```ts
// esbuild.config.js
import { build } from "esbuild";
import buildMeta from "unplugin-build-meta/esbuild";
build({
/* ... */
plugins: [
buildMeta({
/* options */
}),
],
});
```
Farm
```ts
// farm.config.ts
import { defineConfig } from "@farmfe/core";
import vue from "@vitejs/plugin-vue";
import buildMeta from "unplugin-build-meta/farm";
export default defineConfig({
vitePlugins: [
vue(),
],
plugins: [
buildMeta({
/* options */
})
]
});
```
Rspack
```ts
// rspack.config.mjs
import rspack from "@rspack/core";
import buildMeta from "unplugin-build-meta/rspack";
/** @type {import('@rspack/core').Configuration} */
export default {
plugins: [
new rspack.HtmlRspackPlugin({
template: "./index.html"
}),
buildMeta()
],
};
```
Rolldown (Experimental)
```ts
// rolldown.config.js
import { defineConfig } from "rolldown";
import buildMeta from "unplugin-build-meta/rolldown";
export default defineConfig({
input: "./index.js",
plugins: [
buildMeta({
/* options */
}),
],
});
```
## Configuration
```ts
buildMeta({
// Whether to enable the git module (enabled by default)
git: true,
// Additional custom modules to include
extraModules: [
// Your custom modules here
]
});
```
By default, the git module is enabled. You can:
- Disable the git module by setting `git: false`
- Add custom modules using the `extraModules` array
- Create custom modules using `defineBuildMetaModule`
## Modules
### Git Module
The git module provides access to repository metadata from your code.
Import it in your code:
```ts
// Import all git metadata
import * as git from "virtual:build-meta/git";
// Or import specific values
import { branch, sha, shortSha } from "virtual:build-meta/git";
```
Available properties (all properties are nullable):
| Property | Type | Description |
|----------|------|-------------|
| `branch` | `string \| null` | Current git branch name |
| `sha` | `string \| null` | Full git commit hash |
| `shortSha` | `string \| null` | First 10 characters of the commit hash |
| `latestCommitMessage` | `string \| null` | Latest commit message |
| `commitAuthorName` | `string \| null` | Commit author name |
| `commitAuthorEmail` | `string \| null` | Commit author email |
| `commitAuthorDate` | `string \| null` | Commit author date |
| `commitCommitterName` | `string \| null` | Committer name |
| `commitCommitterEmail` | `string \| null` | Committer email |
| `commitCommitterDate` | `string \| null` | Committer date |
| `tag` | `string \| null` | Current tag (if any) |
| `tags` | `string[] \| null` | All tags pointing at current commit |
| `lastTag` | `string \| null` | Latest tag in the repository |
| `repositoryUrl` | `string \| null` | Repository URL (for GitHub repositories) |
### Runtime Module
The runtime module provides access to Node.js runtime information from your code.
Import it in your code:
```ts
// Import all runtime information
import * as runtime from "virtual:build-meta/runtime";
// Or import specific values
import { arch, platform, versions } from "virtual:build-meta/runtime";
```
Available properties:
| Property | Type | Description |
|----------|------|-------------|
| `platform` | `NodeJS.Platform` | The operating system platform (e.g., 'linux', 'darwin', 'win32') |
| `arch` | `NodeJS.Architecture` | The CPU architecture (e.g., 'x64', 'arm64') |
| `versions` | `NodeJS.ProcessVersions` | Version strings of Node.js and its dependencies |
### TypeScript
To get proper type support, make sure to include the type declarations:
```json
{
"compilerOptions": {
"types": [
"unplugin-build-meta/types"
]
}
}
```
## 📄 License
Published under [MIT License](./LICENSE).
[npm-version-src]: https://img.shields.io/npm/v/unplugin-build-meta?style=flat&colorA=18181B&colorB=4169E1
[npm-version-href]: https://npmjs.com/package/unplugin-build-meta
[npm-downloads-src]: https://img.shields.io/npm/dm/unplugin-build-meta?style=flat&colorA=18181B&colorB=4169E1
[npm-downloads-href]: https://npmjs.com/package/unplugin-build-meta