vendure-ecommerce / vendure

The commerce platform with customization in its DNA.
https://www.vendure.io
Other
5.78k stars 1.03k forks source link

Plugin static assets not found #2928

Open yazfield opened 4 months ago

yazfield commented 4 months ago

Describe the bug Hello, I have a custom plugin where I use setBranding to change images / favicon following the docs here

@VendurePlugin({
  imports: [PluginCommonModule],
  providers: [
    { provide: IZAR_PLUGIN_OPTIONS, useFactory: () => IzarPlugin.options },
  ],
  configuration: (config) => {
    return config;
  },
  compatibility: "^2.0.0",
})
export class IzarPlugin {
  static options: PluginInitOptions;

  static init(options: PluginInitOptions): Type<IzarPlugin> {
    this.options = options;
    return IzarPlugin;
  }

  static ui: AdminUiExtension = {
    id: "izar-ui",
    extensionPath: path.join(__dirname, "ui"),
    routes: [{ route: "izar", filePath: "routes.ts" }],
    providers: ["providers.ts"],
    staticAssets: setBranding({
      smallLogoPath: path.join(__dirname, "images/izar-logo.png"),
      largeLogoPath: path.join(__dirname, "images/izar-logo.png"),
      faviconPath: path.join(__dirname, "images/favicon.ico"),
    }).staticAssets,
  };
}

I use the plugin as follows:

AdminUiPlugin.init({
    route: "admin",
    port: 3002,
    adminUiConfig: {
      apiPort: 3000,
      brand: "Izar",
      hideVendureBranding: false,
      hideVersion: true,
    },
    app: compileUiExtensions({
      outputPath: path.join(__dirname, "../admin-ui"),
      extensions: [
        IzarPlugin.ui,
      ],
    }),
  }),

After building npm run build and running npm run start:server I get this error:

Error: ENOENT: no such file or directory, lstat '.../dist/plugins/izar/images/izar-logo.png'

I can see that the images were copied to admin-ui folder under admin-ui/static-assets however the plugin in the dist folder expects the assets to be on the same folder because of path.join(__dirname, "images/izar-logo.png") I guess.

I'm not sure if this is a bug and the plugin system should be updating the image path or I should change the image path?

I'd appreciate if someone could point me to a workaround.

Thanks for the support ❤️

Expected behavior Plugin assets are copied and paths are updated on build.

Environment (please complete the following information):

mohitxskull commented 4 months ago

Getting same issue

@yazfield can you please share how you fixed it?

Error: ENOENT: no such file or directory, lstat '/usr/src/app/dist/plugins/services/ui'

the path should be this /usr/src/app/admin-ui/src/extensions/services

yazfield commented 3 months ago

i have not managed to fix this

@mohitxskull i used a workaround updating package.json build command

{
"build": "tsc && copyfiles -u 1 src/plugins/**/images/* dist",
}