
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
use-build is a bundler plugin help you to move logic and run it at build time
use use build directive to declare a build time file, in following code snippet, fetchMessage and zod schema validation is done at build time
// env.ts
"use build"
import { z } from "zod"
import { envSchema } from "./env-schema"
async function fetchMessage()
console.log("should only run on build time")
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
await delay(1000)
return "Hello world"
}
export const env = envSchema.parse(import.meta.env)
export const message = z.string().parse(await fetchMessage())
and you can use all export values by directly importing the build time file at runtime
import { useState } from "react"
import { container } from "./index.css"
import { message } from "./env"
export function Main() {
const [count, setCount] = useState(0)
return (
<div className={container}>
<button onClick={() => setCount(count => count + 1)}>count: {count}</button>
<p>{message}</p>
</div>
)
}
npm install -D use-build
// vite.config.ts
import { defineConfig } from "vite"
import { UseBuildPlugin } from "use-build/vite"
import react from "@vitejs/plugin-react"
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), UseBuildPlugin()]
})
use-build currently supports:
vite
rsbuild
in development 🚧
rspack
rolldown
All export values from build time file must be serializable.
HMR
Tests
typescript plugins
GitHub - egoist/vite-plugin-compile-time: Some compile-time magic for your Vite project
MIT.
FAQs
A vite plugin run script at build time and import at runtime
We found that use-build demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.