I'm create several Kibana plugins that reuse some components. How can I properly share the components among them?
What I'm doing now is to create a blank plugin (no APIs and UI exports), let say "plugin_commons". In "plugin_common", I export a shared component named "DateRangePicker". And then, from *.jsx files of some other plugins, I import the components using something like: import { DateRangePicker } from '../../../../plugin_commons/components';
Am I doing it right way? Or any better way?
Thank a lot!
It's also providing various components which are used by several other plugins.
To follow the rules in their strictest form, the components should be re-exported by the index.ts/js file in the public folder in your commons plugin - plugins should never reach into the folder structure of another plugin but always use the top level export. This helps with keeping individual plugins separate (because you can re-organize the inner workings of a plugin without touching anything else as long as the public things exported from the top level are staying the same).
Thank you for your suggestion. That way worked like a charm. I just want to summarize it as following:
Commons plugin: export all components in public/index.ts export {DateRangePicker} from './components/DateRangePicker'; export {AnyComponent} from './components/AnyComponent';
from others plugin's .tsx file: use import {DateRangePicker} from 'plugins/plugins_commons';
to import DateRangePicker
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.