New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use polka instead of express to serve the viewer #212
Conversation
4d9604d
to
c7c647a
Compare
src/viewer.js
Outdated
|
||
ejs.renderFile('views.ejs', data, ejsOptions, (err, str) => { | ||
if (err) { | ||
throw err; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't err
be passed to the next
route handler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a middleware but a handler for GET
and thus doesn't have a next
handler. I could output an error to the browser but I figured this be enough for the use case of bundle analyzer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With Polka@next, all route handlers follow (req, res, err) signature, so you're no longer limited here.
Here's an alternative approach using the current polka@0.5
version
package.json
Outdated
"filesize": "^3.6.1", | ||
"gzip-size": "^5.0.0", | ||
"lodash": "^4.17.10", | ||
"mkdirp": "^0.5.1", | ||
"opener": "^1.5.1", | ||
"polka": "^0.5.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does it reduce the total size of dependencies? I would like to see the numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair question on the size. Using bundle phobia: webpack-bundle-analyzer is currently at 6.05MB, express is 1.56 MB so a quarter of that. polka is just 53kB and serve-static is 318kB. So this PR would shave off a bit more than 1MB of the install size. |
For me Thanks for the PR! I'll leave it opened as a reminder. |
@th0r I don't think polka will receive a 1.0 anytime soon. It's more likely one of those projects that (annoyingly) stays < 1.0 forever. Since polka has a very small API and bundle analyzer makes only 3 calls to it, I think migrating to a new API would be easy. We could pin to a fixed version if that helps. What do you think? |
Hi! FWIW |
package.json
Outdated
"filesize": "^3.6.1", | ||
"gzip-size": "^5.0.0", | ||
"lodash": "^4.17.15", | ||
"mkdirp": "^0.5.1", | ||
"opener": "^1.5.1", | ||
"polka": "^0.5.2", | ||
"serve-static": "^1.14.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comparison of
Half the packages and 28% less bytes :) |
Alternative to long-standing webpack-contrib#212 Express in this project does not add much value. Middleware api is not necessary for 1.5 middlwares. We can try to use node server directly. Serving static is left for express middleware. Can be replaced with something smaller in another PR.
Updated this in light of #397 being merged. New comparison of
Still ~half the packages and 20% less bytes. (I have no idea why the size went up compared to the last time I ran the stats) |
Alternative to long-standing webpack-contrib#212 Express in this project does not add much value. Middleware api is not necessary for 1.5 middlwares. We can try to use node server directly. Serving static is left for express middleware. Can be replaced with something smaller in another PR.
Alternative to long-standing webpack-contrib#212 Express in this project does not add much value. Middleware api is not necessary for 1.5 middlwares. We can try to use node server directly. Serving static is left for express middleware. Can be replaced with something smaller in another PR.
Thank you for the contributions! In the end, we went with #398 |
All good. Thank you :) |
While the code is less elegant, this is a pretty big size reduction for anyone not using express as you can see in the number of dependencies that become dev dependencies. On the other hand, it's a relatively small size increase for those projects that do use polka.
Express is still the most popular web framework but I wouldn't assume that everyone is using it since there are so many great alternatives. Since bundle analyser has simple needs, something tiny like polka should do.