Registry / devops / esbuild-plugin-filelastmodified

esbuild-plugin-filelastmodified

JSON →
library2.0.4jsnpmunverified

An esbuild plugin that exports the last modified timestamp of specific files during the build process. Version 2.0.4 is the latest stable release, with no known breaking changes since v2.0.0. It returns a Unix timestamp (milliseconds) for requested files, integrated as a virtual module. Differentiator: simple, focused utility for cache busting or build-time file info without manual file system reads.

npm install esbuild-plugin-filelastmodified
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-FIL
E
esbuild-plugin-filelastmodified
devopsjavascriptv2.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.

fileLastModifiedPlugin
import { fileLastModifiedPlugin } from 'esbuild-plugin-filelastmodified'
const fileLastModifiedPlugin = require('esbuild-plugin-filelastmodified')
CommonJS require works as it also exports a default; prefer named import for clarity.
fileLastModifiedPlugin
const { fileLastModifiedPlugin } = require('esbuild-plugin-filelastmodified')
const fileLastModifiedPlugin = require('esbuild-plugin-filelastmodified').default
No default export, destructure directly.
fileLastModifiedPlugin
import fileLastModifiedPlugin from 'esbuild-plugin-filelastmodified'
import { fileLastModifiedPlugin } from 'esbuild-plugin-filelastmodified'
Default import also works since both named and default exports point to the same function.
FileLastModifiedPluginOptions
import type { FileLastModifiedPluginOptions } from 'esbuild-plugin-filelastmodified'
Type-only import for TypeScript users.

Shows how to set up the esbuild plugin and use virtual module imports to get file modification timestamps.

import { build } from 'esbuild'; import { fileLastModifiedPlugin } from 'esbuild-plugin-filelastmodified'; await build({ entryPoints: ['src/app.js'], bundle: true, outfile: 'dist/out.js', plugins: [ fileLastModifiedPlugin({ filter: /^.*\.json$/, namespace: 'filemod', }), ], }); // In your entry point, import the virtual module to get timestamps: import { 'filemod:./data.json' as timestamps }; // timestamps will be an object mapping file paths to last modified timestamps (Unix ms).
Debug
Known issues
gotchaPlugin expects the virtual module import path to start with the namespace prefix (default 'filemod:') — if you change the namespace, adjust imports accordingly.
fix
Ensure the import path matches the namespace configuration, e.g., 'my-ns:./file.js' if namespace is 'my-ns'.
affects: *
gotchaTimestamps are in milliseconds (Unix time); if you need seconds, divide by 1000.
fix
Use Math.floor(timestamp / 1000) to get seconds.
affects: *
gotchaThe plugin only watches files included in the esbuild build graph (via import statements). Files not imported anywhere will not have their timestamps tracked.
fix
Import the files you need timestamps for, even if they are not directly used in code.
affects: *
gotchaChanges to the monitored files will cause esbuild to rebuild only if those files are actually part of the build (i.e., imported). The plugin does not add files to the build graph automatically.
fix
Explicitly import any file you need timestamps for to ensure rebuilds trigger.
affects: *
Errors
Common errors & fixes
Error: The plugin "fileLastModifiedPlugin" doesn't have a `setup` function.
Importing the wrong export or using an outdated import pattern.
fix
Use the correct import: import { fileLastModifiedPlugin } from 'esbuild-plugin-filelastmodified'
Cannot find module 'esbuild-plugin-filelastmodified'
Package not installed or missing from dependencies.
fix
Run npm install esbuild-plugin-filelastmodified --save-dev
Upgrade
Version history
2.0.4latest on npm
Audit
Dependencies
esbuildrequiredpeer dependency required for plugin to work
Agent activity
2 hits · last 30 days
node
2
Resources
esbuild-plugin-filelastmodified — npm install esbuild-plugin-filelastmodified · libregistry