Admin Configuration
In this document, you'll learn about the different ways you can configure the admin dashboard.
Plugin Options
The plugin accepts the following options:
const plugins = [
// ...
{
resolve: "@medusajs/admin",
/** @type {import('@medusajs/admin').PluginOptions} */
options: {
serve: true,
autoRebuild: true,
backend: "https://example.com",
path: "/app",
outDir: "build",
develop: {
open: true,
port: 7001,
host: "example.com",
logLevel: "error",
stats: "normal",
allowedHosts: "auto",
webSocketURL: undefined,
},
},
},
]
serve
booleanfalse
, you can serve the admin dashboard using the dev command.Default: true
autoRebuild
booleanDefault: false
backend
stringserve
option is set to false
.path
string/
, but it can't end with a /
, which throws an error. It also can't be one of the reserved paths: "admin" and "store".Default: /app
outDir
stringbuild
directory in the root of the Medusa backend directory.develop
objectOptions for the admin development server.
develop
objectAdmin CLI
Build Command Options
The build
command in the admin CLI allows you to manually build the admin dashboard. If you intend to use it, you should typically add it to the package.json
of the Medusa backend:
You can add the following option to the medusa-admin build
command:
--deployment
: a boolean value indicating that the build should be ready for deployment. When this option is added, options are not loaded frommedusa-config.js
anymore, and it means the admin will be built to be hosted on an external host. This also means that the backend URL is loaded from theMEDUSA_ADMIN_BACKEND_URL
environment variable. For example,medusa-admin build --deployment
.
Develop Command Options
The develop
command in the admin CLI allows you to run the admin dashboard in development separately from the Medusa backend. If you intend to use it, you should typically add it to the package.json
of the Medusa backend:
You can add the following options to the medusa-admin develop
command:
--backend
or-b
: a string specifying the URL of the Medusa backend. By default, it's the value of the environment variableMEDUSA_ADMIN_BACKEND_URL
. For example,medusa-admin develop --backend example.com
.--port
or-p
: the port to run the admin on. By default, it's7001
. For example,medusa-admin develop --port 8000
.
Change Backend URL
In Development - Disabled Serve
To change the backend's URL that the admin sends request to in development when the serve
option is disabled, set the backend
option to the URL of your Medusa backend.
For example:
In Development - Enabled Serve
To change the backend's URL when the serve
option is enabled, set the host
and port
properties of the develop
option to those of the Medusa backend. This is useful when running Medusa remotely in development, such as using GitHub Codespace.
For example:
In Production
This assumes that you've deployed the admin separately and you're passing the --deployment
option to the build command.
To change the backend's URL that the admin sends request to in production, set the environment variable MEDUSA_ADMIN_BACKEND_URL
to the backend's URL.
For example:
Custom Environment Variables
If you want to set environment variables that you want to access in your admin dashboard's customizations (such as in widgets or UI routes), your environment variables must be prefixed with MEDUSA_ADMIN_
. Otherwise, it won't be loaded within the admin.
For example:
Custom Webpack Configurations
Plugins cannot include webpack customizations.
The admin dashboard uses Webpack to define the necessary configurations for both the core admin plugin and your extensions. So, for example, everything works out of the box with Tailwind CSS, the admin dependencies, and more.
However, you may have some advanced case where you need to tweak the webpack configurations. For example, you want to support styling your extensions with CSS Modules.
For such use cases, you can extend the default webpack configurations defined in the admin plugin to add your custom configurations.
To do that, create the file src/admin/webpack.config.js
that uses the withCustomWebpackConfig
method imported from @medusajs/admin
to export the extended configurations. The method accepts a callback function that must return an object of webpack configuration. The callback function accepts two parameters:
config
: the first parameter is an object that holds the default webpack configuration. You should add your configurations to this object, then return it. Not returning the default configurations will lead to the application breaking.webpack
: the second parameter is the webpack instance.
This is an advanced feature and requires knowledge of configuring webpack. If configured wrongly, it may lead to the admin application breaking.
For example:
const withCustomWebpackConfig = require(
"@medusajs/admin"
).withCustomWebpackConfig
module.exports = withCustomWebpackConfig((config, webpack) => {
config.plugins.push(
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production"),
API_URL:
JSON.stringify("https://api.medusa-commerce.com"),
},
})
)
return config
})