index.mdx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. ---
  2. title: "DashboardPlugin"
  3. generated: true
  4. ---
  5. <GenerationInfo sourceFile="packages/dashboard/plugin/dashboard.plugin.ts" sourceLine="119" packageName="@vendure/dashboard" />
  6. This plugin serves the static files of the Vendure Dashboard and provides the
  7. GraphQL extensions needed for the order metrics on the dashboard index page.
  8. ## Installation
  9. `npm install @vendure/dashboard`
  10. ## Usage
  11. First you need to set up compilation of the Dashboard, using the Vite configuration
  12. described in the [Dashboard Getting Started Guide](/guides/extending-the-dashboard/getting-started/)
  13. ## Development vs Production
  14. When developing, you can run `npx vite` (or `npm run dev`) to start the Vite development server.
  15. The plugin will automatically detect if Vite is running on the default port (5173) and proxy
  16. requests to it instead of serving static files. This enables hot module replacement and faster
  17. development iterations.
  18. For production, run `npx vite build` to build the dashboard app. The built app files will be
  19. output to the location specified by `build.outDir` in your Vite config file. This should then
  20. be passed to the `appDir` init option, as in the example below:
  21. *Example*
  22. ```ts
  23. import { DashboardPlugin } from '@vendure/dashboard/plugin';
  24. const config: VendureConfig = {
  25. // Add an instance of the plugin to the plugins array
  26. plugins: [
  27. DashboardPlugin.init({
  28. route: 'dashboard',
  29. appDir: './dist/dashboard',
  30. // Optional: customize Vite dev server port (defaults to 5173)
  31. viteDevServerPort: 3000,
  32. }),
  33. ],
  34. };
  35. ```
  36. ## Metrics
  37. This plugin defines a `metricSummary` query which is used by the Dashboard UI to
  38. display the order metrics on the dashboard.
  39. If you are building a stand-alone version of the Dashboard UI app, and therefore
  40. don't need this plugin to serve the Dashboard UI, you can still use the
  41. `metricSummary` query by adding the `DashboardPlugin` to the `plugins` array,
  42. but without calling the `init()` method:
  43. *Example*
  44. ```ts
  45. import { DashboardPlugin } from '@vendure/dashboard-plugin';
  46. const config: VendureConfig = {
  47. plugins: [
  48. DashboardPlugin, // <-- no call to .init()
  49. ],
  50. // ...
  51. };
  52. ```
  53. ```ts title="Signature"
  54. class DashboardPlugin implements NestModule {
  55. constructor(processContext: ProcessContext)
  56. init(options: DashboardPluginOptions) => Type<DashboardPlugin>;
  57. configure(consumer: MiddlewareConsumer) => ;
  58. }
  59. ```
  60. * Implements: NestModule
  61. <div className="members-wrapper">
  62. ### constructor
  63. <MemberInfo kind="method" type={`(processContext: <a href='/reference/typescript-api/common/process-context#processcontext'>ProcessContext</a>) => DashboardPlugin`} />
  64. ### init
  65. <MemberInfo kind="method" type={`(options: <a href='/reference/core-plugins/dashboard-plugin/dashboard-plugin-options#dashboardpluginoptions'>DashboardPluginOptions</a>) => Type<<a href='/reference/core-plugins/dashboard-plugin/#dashboardplugin'>DashboardPlugin</a>>`} />
  66. Set the plugin options
  67. ### configure
  68. <MemberInfo kind="method" type={`(consumer: MiddlewareConsumer) => `} />
  69. </div>