Some notes on eggjs

eggjs is a “enterprise-level” nodejs framework for building node applications. It was created and opensourced by Alibaba.

Had some experiences with it while I was there. It’s sort of complete and battle-tested. So I thought it would be a good idea to use it outside. But as it turned out, as always, your open sourced project will be running in different envs for different use cases. There are always gaps.

Adding to the situation is the fact that inside Alibaba a wrapped version of eggjs - beggjs is used, and that inside Alibaba egg plugins used are the scoped ones prefixed @ali, @alidata, @ant etc. This worsens the scenario as internal devs don’t feel the pain - or they feel different pains and fix entirely different bugs on different packages.

Enough background, here’s a list of issues found while using eggjs and my solutions:

easywebpack optimized functions away - sometimes

easywebpack is the choice of webpack flavor in most eggjs fullstack boilerplates. For prouction build it replaces your function if it contains only console.[log_level] statements. However, if that function has arguments and any of it is used, then it stops doing so in the fear that your function might have unknown side effects (e.g. getter)

That’s unreasonable. Nobody does that in JS - I can easily re-assign console.log, so that this optimization becomes void. But the key is not that whether logging is showing or not, but the fact that it gives logging sometimes. That’s the worst. Gosh if I see some of my log messages are shown while else missing, I no doubt think that those missing log messages must mean that those execution paths are not traversed. How catastrophic!

I end up replacing console.[log_level] with my own wrappers to disable this behavior

egg-cookies doing things not same as its underlying library

cookie - along with some other plugins mentioned below - are common components of a web server. You would expect it to behave the same as mainstream libraries doing the same thing.

egg-cookies is based on the npm pkg cookies, but it conveniently changed a default opt such that signature became a required param (as opposed to being optional in cookies). If it’s not provided, it fails silently.

This is unacceptable. But why no one mentions this? Because in Alibaba cookie always comes with a signature! Again, they don’t feel the same pain.

no proxy plugin

Some basic components are misbahaving - like the one above. Some are missing. Hard to say which one better (worse)

So you can wrap koa-proxy into an eggjs plugin following its conventions. See this issue

egg-vue-ssr

This plugin implements vue server-side rendering. It’s a wrapper around vue-server-renderer and makes egg to use it as view engine.

It generally works, except that it doesn’t allow some of the params that vue-server-renderer permits, such as head and styles.

The solution was to fork the plugin and make the changes (and submit a PR hoping that it will be merged one day). Again, the devs themselves do not use these params. They also failed to do a pass-all-to-down-stream.

Written on October 20, 2018