This repo holds the bundler used in courses.joshwcomeau.com, by the Sandpack library.
It's deployed separately, on Vercel. I haven't purchased a domain, I use the vercel.app URL.
Here's why I self-host:
- Not dependent on CodeSandbox maintaining this library, no issues if their servers crash
- I can include my own static assets, to be referenced within supplied code. I currently have lots of images, as well as the Wotfard + Source Code Pro fonts.
In order to self-host, we have to follow a procedure to generate the bundle from the codesandbox-client codebase.
Link to steps: https://sandpack.codesandbox.io/docs/advanced-usage/client#hosting-the-bundler
Here are the steps to perform:
cd
into/work/forks/codesandbox-client
. Do agit pull origin master
to make sure I have the latest files- Switch to Node v10 with NVM (or whichever version is requested by
engines
in package.json) - Reinstall dependencies with
yarn install
. yarn build:deps
to build some of the packages lerna needs for internal links.yarn build:sandpack
to create the built files
Now, the tricky thing: I already have a deployed and compiled bundler! We need to merge them.
- Inside
/work/sandpack-bundler
, move my assets out. Move thefonts
,img
, andvideos
directories to a safe place. - Copy the
/work/forks/codesandbox-client/www
over, overwriting/work/sandpack-bundler/www
. - Push to github to deploy!