Introducing serwist
#118
Closed
DuCanhGH
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In v9.0.0, all of Serwist's service worker modules will be merged into one module named
serwist
. This module is now available on npm, and you can now install it and uninstall all the legacy modules:npm uninstall @serwist/core @serwist/background-sync @serwist/broadcast-update @serwist/cacheable-response @serwist/core @serwist/expiration @serwist/google-analytics @serwist/navigation-preload @serwist/precaching @serwist/range-requests @serwist/routing @serwist/strategies @serwist/sw && npm install serwist
.The legacy modules will be marked as deprecated on npm.
With this change, you no longer have to install so many modules to use Serwist. From now on, simply import core functions and classes from
serwist
, plugins fromserwist/plugins
, and strategies fromserwist/strategies
.Alongside this change, I have replaced
installSerwist
,PrecacheController
, andRouter
withSerwist
.installSerwist
,PrecacheController
, andRouter
have been moved toserwist/legacy
. Their functionalities have been merged into theSerwist
class.The new
Serwist
class does NOT have a singleton instance. As such,serwist/plugins.initializeGoogleAnalytics()
and@serwist/recipes
's functions now require you to pass in your ownSerwist
instance.This was done because separating Serwist's functionalities into three separate classes, namely
PrecacheController
,Router
, andSerwist
, was not only unnecessary, but it also required the code to be rather... boilerplatey. In the past, to set up, you needed to install all the necessary packages (workbox-routing
,workbox-precaching
,workbox-strategies
), import all the necessary classes (PrecacheController
,Router
,...), and know all the APIs needed (PrecacheController.precache
,Router.registerRoute
,new PrecacheRoute()
, runtime caching strategies,...) to get yourself started. To simplify that whole process, the Workbox team provided GenerateSW, which allowed you to create a service worker without having to write one. However, this design was not my cup of tea, one of the reasons of which was that you needed to migrate from GenerateSW to InjectManifest if you needed to do anything remotely complex, so I replaced it withinstallSerwist
. Still, I was not satisfied by the result. I wanted an API where things are simple enough that you don't need to have multiple ways of doing one same thing, some more straightforward than others. This change where we merge the three classes is an effort to simplify and unify the API.To migrate, either:
Serwist
class:PrecacheController
andRouter
fromserwist/legacy
:Having done this, I now expect to release Serwist v9 right next weekend (the one after this week's one, I mean). At this moment, I only plan to introduce rudimentary support for Next.js + Turbopack and finish the docs. See you there!
P/s: With my compute minutes on GitLab running out much more quickly than I had anticipated, I guess I'll be back on GitHub, heh... Can't do much about being a broke bloke... Sorry for the inconvenience.
To be honest, after a few weeks of trying out GitLab, I'd say that GitHub is still way better in many ways. Managing secrets was, frankly, quite a big problem. I obviously didn't want someone to be able to extract my secret stuff through CI/CD, so I had to restrict my secrets to protected branches, meaning that other branches just had to live without Turborepo's remote caching, resulting in many wasted compute minutes. I also couldn't enforce approvals on merge requests without going Premium, so that was quite a pain. Also, Changesets doesn't officially support GitLab, so I had to fork
changesets-gitlab
(to be honest, I could just use the project, but it looked like it was in its infancy, with it still using@actions/core
everywhere), which was quite a maintain burden (still couldn't get Releases working, heh). GitHub also doesn't support an official and publicly available way of mirroring repos, so I just had to make GitLab push to GitHub every time I pushed. So, considering everything, I guess being back on GitHub doesn't seem that bad after all. Hopefully, its bots don't suddenly decide I am worth their time again.P/s 2: Seems that Workbox has also found Google's Aurora team as its new owner :) Great to know that it will no longer be a semi-abandoned ghost project! Hopefully the new team can cook up some good stuff.
Edit: I just went through the Next.js 14.2 blog and noticed that Turbopack still doesn't support
next build
and plugins (not loaders!) in Release Candidate 💀 I guess some support for it can wait then.Beta Was this translation helpful? Give feedback.
All reactions