npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

egg-serlina

v2.0.0

Published

Serlina for Egg

Readme

egg-serlina

NPM version CircleCI npm download

egg-serlina is a Serlina binding for Egg. It brings the best SSR solution to Egg application.

Install

$ npm i serlina egg-serlina react react-dom --save

Usage

Enable the plugin:

// {app_root}/config/plugin.js
exports.serlina = {
  enable: true,
  package: 'egg-serlina',
};

Add a client folder and create the first page:

- app_root
  - app
+ - client
+   - pages
+     - page1.js
// {app_root}/client/pages/page1.js

export default () => {
  return <div>Hello Serlina</div>
}
// {app_root}/config/config.default.js

exports.serlina = {
  map: {
    '/page1': 'page1'
  }
}

Then visit http://{your_host}/page1 and you will see the React page.

Please note that the egg ctx had been injected to your page:

// {app_root}/client/pages/page1.js

export default class Page1 extends React.Component {

  static async getInitialProps({ ctx }) {
    // ctx is egg `ctx`
    return {
      data: await ctx.service.getDate()
    }
  }

  render () {
    return (
      <div>{this.props.data}</div>
    )
  }
}

You can also render your page manually in controller:

// app/controller/page1.js

module.exports = async ctx => {
  const rendered = await ctx.app.serlina.render('/page1', { ctx })
}

Remember to inject your ctx if you need it in getInitialProps.

Configuration

options

dev

boolean dev mode.

default: appInfo.env === 'local'

baseDir

string Serlina baseDir.

default: path.resolve(appInfo.baseDir, './client')

outputPath

string Serlina output files path.

publicPath

string Webpack's publicPath. Only work in prod mode. Usually use it when you upload the Serlina output files to CDN.

default: /public/

map

object Using Serlina only in specific path:

exports.serlina = {
  map: {
    '/p/page1': 'page1' // render SSR page `page1` only when the `ctx.path` is `/p/page1`
  }
}

see config/config.default.js for more detail.

Production deployment

self serve static files

Before deploy to production, please run serlina build first (usually do it on CI):

// ${app_root}/package.json

{
  "script": {
    "build": "serlina build ./client --publicPath /public/"
  }
}

Then you need to serve the output path:

// {app_root}/config/config.default.js
exports.static = {
  dir: [
    path.join(appInfo.baseDir, 'app/public'),
    path.join(appInfo.baseDir, 'client/.serlina')
  ]
};

server static files on CDN

// ${app_root}/package.json

{
  "script": {
    "build": "serlina build ./client --publicPath ${YOUR_CDN_ENDPOINT}"
  }
}
// {app_root}/config/config.default.js
exports.serlina = {
  publicPath: '${YOUR_CND_ENDPOINT}'
};

Limitation

While Egg will restart a new worker after file changing, Serlina will restart building. Maybe it will be frustrating when the client code getting bigger. PR is welcome if you know how to deal with this problem.

License

MIT