# egg-static

> static server plugin for egg

Latest version **2.3.1** (published 2023-02-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install egg-static
pnpm add egg-static
yarn add egg-static
bun add egg-static
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.1 |
| Published | 2023-02-13 |
| First published | 2016-05-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=14.0.0 |
| Dependencies | 5 |
| Unpacked size | 8.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 89 |
| Author | dead_horse |
| Maintainers | gemwuu, eggjs-admin, fengmk2, atian25, dead_horse, popomore, wanghx, hyj1991, killagu, coolme200, mansonchor.zzw, hubcarl |
| Keywords | egg, egg-plugin, eggPlugin, static |

## Links

- npm: https://www.npmjs.com/package/egg-static
- Repository: https://github.com/eggjs/egg-static
- Homepage: https://github.com/eggjs/egg-static#readme
- Issues: https://github.com/eggjs/egg-static/issues
- npm.io page: https://npm.io/package/egg-static

## Dependencies (5)

- [ylru](https://npm.io/package/ylru.md) ^1.3.2
- [koa-range](https://npm.io/package/koa-range.md) ^0.3.0
- [is-type-of](https://npm.io/package/is-type-of.md) ^1.2.1
- [koa-compose](https://npm.io/package/koa-compose.md) ^4.1.0
- [koa-static-cache](https://npm.io/package/koa-static-cache.md) ^5.1.2

## Recent versions

- 2.3.1 (latest) — 2023-02-13
- 1.5.1 (latest-1) — 2018-05-02
- 2.3.0 — 2023-02-12
- 2.2.0 — 2019-02-15
- 2.1.1 — 2018-05-02
- 1.5.0 — 2018-01-10
- 2.1.0 — 2018-01-10
- 2.0.0 — 2017-11-09
- 1.4.1 — 2017-06-04
- 1.4.0 — 2017-06-01
- 1.3.0 — 2017-03-25
- 1.2.0 — 2017-02-21
- 1.1.0 — 2017-01-12
- 1.0.0 — 2016-11-02
- 0.1.0 — 2016-07-18
- … 2 more at https://npm.io/package/egg-static/versions

## README

# egg-static

[![NPM version][npm-image]][npm-url]
[![Test coverage][codecov-image]][codecov-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/egg-static.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-static
[codecov-image]: https://codecov.io/github/eggjs/egg-static/coverage.svg?branch=master
[codecov-url]: https://codecov.io/github/eggjs/egg-static?branch=master
[download-image]: https://img.shields.io/npm/dm/egg-static.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-static

Static server plugin for egg, base on [koa-static-cache](https://github.com/koajs/static-cache).

## Install

`egg-static` is a plugin that has been built-in for egg. It is enabled by default.

## Configuration

egg-static support all configurations in [koa-static-cache](https://github.com/koajs/static-cache). and with default configurations below:

- prefix: `'/public/'`
- dir: `path.join(appInfo.baseDir, 'app/public')`
- dynamic: `true`
- preload: `false`
- maxAge: `31536000` in prod env, `0` in other envs
- buffer: `true` in prod env, `false` in other envs

`egg-static` provides one more option:

- maxFiles: the maximum value of cache items, only effective when dynamic is true, default is `1000`.

**All static files in `$baseDir/app/public` can be visited with prefix `/public`, and all the files are lazy loaded.**

- In non-production environment, assets won't be cached, your modification can take effect immediately.
- In production environment, `egg-static` will cache the assets after visited, you need to restart the process to update the assets.
- Dir default is `$baseDir/app/public` but you can also define **multiple directory** by use `dir: [dir1, dir2, ...]` or `dir: [dir1, { prefix: '/static2', dir: dir2 }]`, static server will use all these directories.

```js
// {app_root}/config/config.default.js
exports.static = {
  // maxAge: 31536000,
};
```

## Questions & Suggestions

Please open an issue [here](https://github.com/eggjs/egg/issues).

## License

[MIT](https://github.com/eggjs/egg-static/blob/master/LICENSE)

<!-- GITCONTRIBUTOR_START -->

## Contributors

|[<img src="https://avatars.githubusercontent.com/u/985607?v=4" width="100px;"/><br/><sub><b>dead-horse</b></sub>](https://github.com/dead-horse)<br/>|[<img src="https://avatars.githubusercontent.com/u/156269?v=4" width="100px;"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|[<img src="https://avatars.githubusercontent.com/u/227713?v=4" width="100px;"/><br/><sub><b>atian25</b></sub>](https://github.com/atian25)<br/>|[<img src="https://avatars.githubusercontent.com/u/360661?v=4" width="100px;"/><br/><sub><b>popomore</b></sub>](https://github.com/popomore)<br/>|[<img src="https://avatars.githubusercontent.com/u/2127199?v=4" width="100px;"/><br/><sub><b>okoala</b></sub>](https://github.com/okoala)<br/>|[<img src="https://avatars.githubusercontent.com/u/559179?v=4" width="100px;"/><br/><sub><b>airyland</b></sub>](https://github.com/airyland)<br/>|
| :---: | :---: | :---: | :---: | :---: | :---: |
[<img src="https://avatars.githubusercontent.com/u/1798364?v=4" width="100px;"/><br/><sub><b>helloyou2012</b></sub>](https://github.com/helloyou2012)<br/>|[<img src="https://avatars.githubusercontent.com/u/8816730?v=4" width="100px;"/><br/><sub><b>maxming2333</b></sub>](https://github.com/maxming2333)<br/>

This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Sun Feb 12 2023 17:38:47 GMT+0800`.

<!-- GITCONTRIBUTOR_END -->

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