Skip to main content

VendureDashboardPlugin

vendureDashboardPlugin

This is the Vite plugin which powers the Vendure Dashboard, including:

  • Configuring routing, styling and React support
  • Analyzing your VendureConfig file and introspecting your schema
  • Loading your custom Dashboard extensions
Signature
function vendureDashboardPlugin(options: VitePluginVendureDashboardOptions): PluginOption[]

Parameters

options

VitePluginVendureDashboardOptions

Options for the vendureDashboardPlugin Vite plugin.

Signature
type VitePluginVendureDashboardOptions = {
/**
* @description
* The path to the Vendure server configuration file.
*/
vendureConfigPath: string | URL;
/**
* @description
* The {@link PathAdapter} allows you to customize the resolution of paths
* in the compiled Vendure source code which is used as part of the
* introspection step of building the dashboard.
*
* It enables support for more complex repository structures, such as
* monorepos, where the Vendure server configuration file may not
* be located in the root directory of the project.
*
* If you get compilation errors like "Error loading Vendure config: Cannot find module",
* you probably need to provide a custom `pathAdapter` to resolve the paths correctly.
*
* @example
* ```ts
* vendureDashboardPlugin({
* tempCompilationDir: join(__dirname, './__vendure-dashboard-temp'),
* pathAdapter: {
* getCompiledConfigPath: ({ inputRootDir, outputPath, configFileName }) => {
* const projectName = inputRootDir.split('/libs/')[1].split('/')[0];
* const pathAfterProject = inputRootDir.split(`/libs/${projectName}`)[1];
* const compiledConfigFilePath = `${outputPath}/${projectName}${pathAfterProject}`;
* return path.join(compiledConfigFilePath, configFileName);
* },
* transformTsConfigPathMappings: ({ phase, patterns }) => {
* // "loading" phase is when the compiled Vendure code is being loaded by
* // the plugin, in order to introspect the configuration of your app.
* if (phase === 'loading') {
* return patterns.map((p) =>
* p.replace('libs/', '').replace(/.ts$/, '.js'),
* );
* }
* return patterns;
* },
* },
* // ...
* }),
* ```
*/
pathAdapter?: PathAdapter;
/**
* @description
* The name of the exported variable from the Vendure server configuration file, e.g. `config`.
* This is only required if the plugin is unable to auto-detect the name of the exported variable.
*/
vendureConfigExport?: string;
/**
* @description
* The path to the directory where the generated GraphQL Tada files will be output.
*/
gqlOutputPath?: string;
tempCompilationDir?: string;
/**
* @description
* Allows you to customize the location of node_modules & glob patterns used to scan for potential
* Vendure plugins installed as npm packages. If not provided, the compiler will attempt to guess
* the location based on the location of the `@vendure/core` package.
*/
pluginPackageScanner?: PackageScannerConfig;
/**
* @description
* Allows you to selectively disable individual plugins.
* @example
* ```ts
* vendureDashboardPlugin({
* vendureConfigPath: './config.ts',
* disablePlugins: {
* react: true,
* lingui: true,
* }
* })
* ```
*/
disablePlugins?: {
tanstackRouter?: boolean;
react?: boolean;
lingui?: boolean;
themeVariables?: boolean;
tailwindSource?: boolean;
tailwindcss?: boolean;
configLoader?: boolean;
viteConfig?: boolean;
adminApiSchema?: boolean;
dashboardMetadata?: boolean;
uiConfig?: boolean;
gqlTada?: boolean;
transformIndexHtml?: boolean;
translations?: boolean;
hmr?: boolean;
};
} & UiConfigPluginOptions &
ThemeVariablesPluginOptions

PathAdapter

The PathAdapter interface allows customization of how paths are handled when compiling the Vendure config and its imports.

It enables support for more complex repository structures, such as monorepos, where the Vendure server configuration file may not be located in the root directory of the project.

If you get compilation errors like "Error loading Vendure config: Cannot find module", you probably need to provide a custom pathAdapter to resolve the paths correctly.

This can take some trial-and-error. Try logging values from the functions to figure out the exact settings that you need for your repo setup.

Example

vendureDashboardPlugin({
pathAdapter: {
getCompiledConfigPath: ({ inputRootDir, outputPath, configFileName }) => {
const projectName = inputRootDir.split('/libs/')[1].split('/')[0];
const pathAfterProject = inputRootDir.split(`/libs/${projectName}`)[1];
const compiledConfigFilePath = `${outputPath}/${projectName}${pathAfterProject}`;
return path.join(compiledConfigFilePath, configFileName);
},
transformTsConfigPathMappings: ({ phase, patterns }) => {
// "loading" phase is when the compiled Vendure code is being loaded by
// the plugin, in order to introspect the configuration of your app.
if (phase === 'loading') {
return patterns.map((p) =>
p.replace('libs/', '').replace(/.ts$/, '.js'),
);
}
return patterns;
},
},
// ...
}),
Signature
interface PathAdapter {
getCompiledConfigPath?: GetCompiledConfigPathFn;
transformTsConfigPathMappings?: TransformTsConfigPathMappingsFn;
}

getCompiledConfigPath

property
GetCompiledConfigPathFn

A function to determine the path to the compiled Vendure config file.

transformTsConfigPathMappings

property
TransformTsConfigPathMappingsFn

ApiConfig

Options used by the vendureDashboardPlugin to configure how the Dashboard connects to the Vendure Admin API

Signature
interface ApiConfig {
host?: string | 'auto';
port?: number | 'auto';
adminApiPath?: string;
tokenMethod?: 'cookie' | 'bearer';
authTokenHeaderKey?: string;
channelTokenKey?: string;
}

host

property
string | 'auto'
default:
'auto'

The hostname of the Vendure server which the admin UI will be making API calls to. If set to "auto", the Admin UI app will determine the hostname from the current location (i.e. window.location.hostname).

port

property
number | 'auto'
default:
'auto'

The port of the Vendure server which the admin UI will be making API calls to. If set to "auto", the Admin UI app will determine the port from the current location (i.e. window.location.port).

adminApiPath

property
string
default:
'admin-api'

The path to the GraphQL Admin API.

tokenMethod

property
'cookie' | 'bearer'
default:
'cookie'

Whether to use cookies or bearer tokens to track sessions. Should match the setting of in the server's tokenMethod config option.

authTokenHeaderKey

property
string
default:
'vendure-auth-token'

The header used when using the 'bearer' auth method. Should match the setting of the server's authOptions.authTokenHeaderKey config option.

channelTokenKey

property
string
default:
'vendure-token'

The name of the header which contains the channel token. Should match the setting of the server's apiOptions.channelTokenKey config option.

I18nConfig

Options used by the vendureDashboardPlugin to configure aspects of the Dashboard UI behaviour.

Signature
interface I18nConfig {
defaultLanguage?: LanguageCode;
defaultLocale?: string;
availableLanguages?: LanguageCode[];
availableLocales?: string[];
}

defaultLanguage

property
default:
LanguageCode.en

The default language for the Admin UI. Must be one of the items specified in the availableLanguages property.

defaultLocale

property
v2.2.0
string

The default locale for the Admin UI. The locale affects the formatting of currencies & dates. Must be one of the items specified in the availableLocales property.

If not set, the browser default locale will be used.

availableLanguages

property

An array of languages for which translations exist for the Admin UI.

availableLocales

property
v2.2.0
string[]

An array of locales to be used on Admin UI.

UiConfigPluginOptions

Options used by the vendureDashboardPlugin to configure aspects of the Dashboard UI behaviour.

Signature
interface UiConfigPluginOptions {
api?: ApiConfig;
i18n?: I18nConfig;
}

api

property

Configuration for API connection settings

i18n

property

Configuration for internationalization settings