# esbuild-plugin-filelastmodified

> A esbuild plugin to import the last time the file has been modified.

Latest version **2.0.4** (published 2021-11-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install esbuild-plugin-filelastmodified
pnpm add esbuild-plugin-filelastmodified
yarn add esbuild-plugin-filelastmodified
bun add esbuild-plugin-filelastmodified
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2021-11-13 |
| First published | 2021-03-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | g45t345rt |
| Maintainers | g45t345rt |

## Links

- npm: https://www.npmjs.com/package/esbuild-plugin-filelastmodified
- Repository: https://github.com/g45t345rt/esbuild-plugin-filelastmodified
- Homepage: https://github.com/g45t345rt/esbuild-plugin-filelastmodified#readme
- Issues: https://github.com/g45t345rt/esbuild-plugin-filelastmodified/issues
- npm.io page: https://npm.io/package/esbuild-plugin-filelastmodified

## Recent versions

- 2.0.4 (latest) — 2021-11-13
- 2.0.3 — 2021-10-01
- 2.0.2 — 2021-10-01
- 2.0.1 — 2021-09-30
- 2.0.0 — 2021-09-28
- 1.0.6 — 2021-09-27
- 1.0.5 — 2021-09-27
- 1.0.4 — 2021-09-27
- 1.0.3 — 2021-09-27
- 1.0.2 — 2021-03-31
- 1.0.1 — 2021-03-23
- 1.0.0 — 2021-03-23

## README

# esbuild-plugin-filelastmodified

A esbuild plugin to import the last time the file has been modified.

## Why

Avoid having to manually hardcode the date and change it every time you make an edit on your website pages. It's very usefull for displaying -> `Modified date: 2021-03-31` at the end of web pages.

## Install

```js
npm install esbuild-plugin-filelastmodified
```

## Apply plugin to esbuild

```js
import esbuild from 'esbuild'
import fileLastModified from 'esbuild-plugin-filelastmodified'

esbuild.build({
  ...,
  plugins: [
    fileLastModified()
  ]
})
```

## How I would actually use it in React

```js
// Home.js
import React from 'react'
import dayjs from 'dayjs'
import localizedFormat from 'dayjs/plugin/localizedFormat'
import lastModified from '__fileLastModified__' // <-- this gets resolve by the unix date time of this file
dayjs.extend(localizedFormat)

export default () => {
  return <div>{dayjs(lastModified).format('LLL')}</div>
}
```

### Conversion

#### Before

```js
import lastModified from '__fileLastModified__'
```

#### After

```js
const lastModified = 16165180636939285e-4 // unix date time
```

### Options

The plugin accepts the following options as first argument

#### `identifier`

By default the identifier is `__fileLastModified__`. If you have different requirements you can always pass another identifier to be used instead.
Must be a Regex!

ex: `fileLastModified({ identifier: /__FILE_LAST_MODIFIED__/ })`

---
_Source: https://npm.io/package/esbuild-plugin-filelastmodified · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
