-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat(admin): Improve DX for deploying admin externally #3418
Conversation
🦋 Changeset detectedLatest commit: 95e3db4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
/snapshot-this |
/snapshot-this |
…dusajs/medusa into feat/improve-admin-build-step
Should the admin build itself, with the simplest config, on the first server start? Sorry if you've mentioned this somewhere; I tried to look for it in the PR description, but couldn't find it (maybe in the last PR?) So doing:
and adding
On first server start, this gives me a Though, if I build the admin using the CLI and restart, everything works as expected. |
Also, because the |
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.
Love this! Added a couple of comments, that I'd like you to address before we merge :)
@olivermrbl It is not meant to build the project with the default options automatically. Users must enable it with |
Works - great one 💪 |
What
medusa-admin build
.deployment
medusa.config.js
. This flag indicates that we are using@medusajs/admin
as a build tool, to build and host our UI with an external host (e.g. Vercel)boolean
--deployment
backend
MEDUSA_BACKEND_URL
)string
-b
,--backend
outDir
build
)string
-o
,--out-dir
include
200.html
file needed for redirects when hosting on Surge.string[]
-i
,--include
includeDir
string
-d
,--include-dist
Simplifies options available in plugin options. Since users should only install the plugin as a direct dependency, and add it to their
medusa.config.js
when serving the UI, all options related to building for deployment has been removed, and can only be passed as command arguments.serve?: boolean = true
,path?: string = "app"
,outDir?: string = "build"
, andautoRebuild?: boolean = false
.Adds a
dev
command that can be used to spin up a developer instance of the UI -medusa-admin dev
.-p, --port <port>
(default 7001) and-b, --backend <backend>
(default"http://localhost:9000"
)Adds a new
eject
command that can be used to eject the source code of the Admin UI -medusa-admin eject -o admin
. This command is useful in two cases:Examples of how to use the plugin
Here are a couple of examples of setups with the plugin.
Deployment to Vercel
When a user wishes to deploy the UI to an external host like Vercel, the plugin should be installed as a
devDependency
, as we don't want to inject any API and startup logic.Install the plugin
Add a build script to
package.json
Add a
vercel.json
file at the root of your server directoryPush your changes to GitHub
Setup Vercel to deploy the admin UI
Note that Vercel (and any other hosting platform) won't be able to auto-detect that we are using Vite, so you need to manually select it as the Framework Preset.
Serving the UI from the server
When serving the UI from the server the plugin should be installed as a direct dependency.
Install the plugin
Add plugin to
plugins
inmedusa.config.js
Using the default options:
Using custom options:
Deciding on how to build the UI
The plugin offers two approaches for how to build the admin UI: manually using the CLI and automatically as part of the server startup.
The latter options will look for changes to your plugin options and check if a build file is missing for the admin UI on each server start. If the options have changed, or the plugin is unable to locate a build output for the admin UI it will automatically build the project before the server is started. This is very practical, as you can set it and forget it and be sure that the admin UI will always be built and ready before your server is started. It does however have one major drawback, as the build step is a memory-intensive process. In order for this to work in a production setup your server will need a min. 2GB-4GB of RAM, otherwise, it will throw a heap out-of-memory error on startup. If you wish to make use of the auto-rebuild feature, you will need to enable it in your plugin options:
If you are working with a less powerful setup, you will need to handle building the admin UI yourself. The most straightforward approach is to simply run
medusa-admin build
from your terminal before you deploy your server. The process can be improved quite a bit using tools such as GitHub actions to automate building the UI with out it taking a toll on the memory resources of your server. Here is an example of how you can setup a GitHub action to build the UI before pushing your server to be hosted on Heroku:In your
package.json
add a new script to build the admin UIAdd a new
.yml
file to your.github/workflows
foldercc: @shahednasser I've added some examples to the description on how to set up the plugin that we can use for the documentation when we get there ✌️