publicDir does not honour server.basePath

Hello, I generated a sample plugin from the Kibana scripts, and added the "publicDir" option in order to serve static files like images from within my plugin:

// From my plugin's index.js

export default function (kibana) {

  return new kibana.Plugin({
    require: ['kibana'],
    publicDir: resolve(__dirname, 'public'), // <-- I added this to serve static files

    uiExports: {

I added a static asset called rhino.png in the "public" subfolder in my plugin directory:

/me/kibana_plugin/kibana/plugins/my_plugin $ find . | grep png

I generated a zip file for my plugin, so I can install it in a kibana distribution:

$ yarn build
$ ls build/

I installed the plugin zip in a freshly downloaded Kibana distribution.

/me/tmp/kibana-7.3.0-darwin-x86_64 $ bin/kibana-plugin install file:///me/kibana_plugin/kibana/plugins/my_plugin/build/
Attempting to transfer from file:///me/kibana_plugin/kibana/plugins/my_plugin/build/
Transferring 106382 bytes....................
Transfer complete
Retrieving metadata from plugin archive
Extracting plugin archive
Extraction complete
Plugin installation complete

Now I configured a server.basePath in kibana.yml

/me/tmp/kibana-7.3.0-darwin-x86_64 $ grep basePath config/kibana.yml
# Use the `server.rewriteBasePath` setting to tell Kibana if it should remove the basePath
server.basePath: "/xxx"

With Kibana server running, now I expect the following URL to serve the image respecting server.basePath, but it goes 404:

http://localhost:5601/xxx/plugins/my_plugin/rhino.png  <-- 404

However, when I remove the basePath from the url, it still works:

http://localhost:5601/plugins/my_plugin/rhino.png  <-- still returns the picture

Is there a way to make this work? Is it a bug?


Hm. It seems to be working for me locally with a raw (unzipped) plugin, so there's something else going on. I can't remember ever using png files. I think there's a special "assets" directory which you should add to your plugin, and drop it in there. I'm not sure that they get bundled up in the build process otherwise.

Alternatively, you can import images using import myimage from './path/to.png', and then use the image like that. It's bulkier (I think it inlines it during the build process as a base-64 encoded string).

Are you testing with the Kibana development environment? Because the issue is with the actual zipped Kibana distribution people download and install.

Wow that would be very inefficient, right? Would it make the optimization phase slower I guess?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.