zero-to-one-static
v1.0.0
Published
[![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![Test coverage][codecov-image]][codecov-url] [![David deps][david-image]][david-url] [![Known Vulnerabilities][snyk-image]][snyk-url] [![npm download][download-image]][down
Downloads
3
Readme
egg-static
Static server plugin for egg, base on koa-static-cache.
Install
$ npm i egg-static --save
Usage
egg-static
is a plugin that has been built-in for egg. But it is disabled by default.
// {app_root}/config/plugin.js
exports.static = true;
Configuration
egg-static support all configurations in koa-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 usedir: [dir1, dir2, ...]
and static server will use all these directories.
// {app_root}/config/config.default.js
exports.static = {
// maxAge: 31536000,
};
Questions & Suggestions
Please open an issue here.