Skip to content

eggjs/static

Folders and files

NameName
Last commit message
Last commit date

Latest commit

8ab94aa · Jan 12, 2025

History

39 Commits
Jan 12, 2025
Jan 12, 2025
Jan 12, 2025
Jul 15, 2016
Jan 12, 2025
Jan 12, 2025
Jan 12, 2025
May 2, 2018
Jan 12, 2025
Jan 12, 2025
Jan 12, 2025

Repository files navigation

@eggjs/static

NPM version Node.js CI Test coverage Known Vulnerabilities npm download Node.js Version PRs Welcome

Static server plugin for egg, base on @eggjs/koa-static-cache.

Install

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

Configuration

@eggjs/static support all configurations in @eggjs/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

@eggjs/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, @eggjs/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.
// {app_root}/config/config.default.ts
export default {
  static: {
    // maxAge: 31536000,
  },
};

Questions & Suggestions

Please open an issue here.

License

MIT

Contributors

Contributors

Made with contributors-img.