Registry / devops / esbuild-plugin-write-file

esbuild-plugin-write-file

JSON →
library0.0.4jsnpmunverified

An esbuild plugin that writes files asynchronously in parallel before and after bundling. Version 0.0.4 is the latest stable release. It differentiates from other file-writing plugins by supporting both before and after hooks, allowing file creation at specific build lifecycle points. The plugin accepts an object with `before` and `after` properties, each mapping target paths to string content. It is lightweight with no external dependencies. Release cadence is low; the package has seen two releases. It is primarily for build tooling in Node.js environments.

npm install esbuild-plugin-write-file
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-WRI
E
esbuild-plugin-write-file
devopsjavascriptv0.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import writeFilePlugin from 'esbuild-plugin-write-file'
const writeFilePlugin = require('esbuild-plugin-write-file')
ESM-only package; default export is a plugin factory function.
type WriteFilePluginOptions
import type { WriteFilePluginOptions } from 'esbuild-plugin-write-file'
TypeScript users can import the options type for type safety.

Demonstrates basic usage of the plugin with before and after file writes. Uses environment variable for placeholder config.

import esbuild from 'esbuild'; import writeFilePlugin from 'esbuild-plugin-write-file'; await esbuild.build({ entryPoints: ['./src/index.js'], outfile: './dist/bundle.js', plugins: [ writeFilePlugin({ before: { './dist/config.json': JSON.stringify({ apiKey: process.env.API_KEY ?? '' }), }, after: { './dist/report.txt': 'Build completed successfully.', }, }), ], }); console.log('Build finished with file writes.');
Debug
Known issues
gotchaFile paths in before/after are relative to the current working directory (process.cwd()), not the esbuild root directory.
fix
Use absolute paths or paths relative to process.cwd(). For esbuild's outdir, ensure alignment.
affects: >=0.0.0
gotchaPlugin returns a promise but does not wait for writes to complete before esbuild's next plugin hook in some cases.
fix
Review plugin lifecycle; ensure writes are awaited if needed. Consider using onEnd for after writes.
affects: >=0.0.0
gotchaOverwrites existing files without warning; no atomicity guarantee.
fix
Check file existence manually before configuring plugin if overwrite prevention needed.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'esbuild-plugin-write-file'
Package not installed or ESM import used in CommonJS project without .mjs extension/type: module.
fix
Install package: npm install esbuild-plugin-write-file. If using CommonJS, use dynamic import: const writeFilePlugin = (await import('esbuild-plugin-write-file')).default;
TypeError: writeFilePlugin is not a function
Incorrect import; likely using require() and expecting default export directly.
fix
Use ESM import or dynamic import as shown in correct import.
Upgrade
Version history
0.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
esbuild-plugin-write-file — npm install esbuild-plugin-write-file · libregistry