diff --git a/src/backend/InvenTree/InvenTree/settings.py b/src/backend/InvenTree/InvenTree/settings.py index 9259e0fa53..d47053ca2f 100644 --- a/src/backend/InvenTree/InvenTree/settings.py +++ b/src/backend/InvenTree/InvenTree/settings.py @@ -209,6 +209,14 @@ PLUGIN_TESTING_EVENTS = False # Flag if events are tested right now PLUGIN_TESTING_EVENTS_ASYNC = False # Flag if events are tested asynchronously PLUGIN_TESTING_RELOAD = False # Flag if plugin reloading is in testing (check_reload) +PLUGIN_DEV_SLUG = ( + get_setting('INVENTREE_PLUGIN_DEV_SLUG', 'plugin_dev.slug') if DEBUG else None +) + +PLUGIN_DEV_HOST = get_setting( + 'INVENTREE_PLUGIN_DEV_HOST', 'plugin_dev.host', 'http://localhost:5174' +) # Host for the plugin development server + PLUGIN_RETRY = get_setting( 'INVENTREE_PLUGIN_RETRY', 'PLUGIN_RETRY', 3, typecast=int ) # How often should plugin loading be tried? diff --git a/src/backend/InvenTree/plugin/plugin.py b/src/backend/InvenTree/plugin/plugin.py index 9edc5a2696..3f12246d50 100644 --- a/src/backend/InvenTree/plugin/plugin.py +++ b/src/backend/InvenTree/plugin/plugin.py @@ -473,16 +473,34 @@ class InvenTreePlugin(VersionMixin, MixinBase, MetaBase): # endregion - def plugin_static_file(self, *args): - """Construct a path to a static file within the plugin directory.""" + def plugin_static_file(self, *args) -> str: + """Construct a path to a static file within the plugin directory. + + - This will return a URL can be used to access the static file + - The path is constructed using the STATIC_URL setting and the plugin slug + - Note: If the plugin is selected for "development" mode, the path will point to a vite server URL + + """ import os from django.conf import settings - url = os.path.join(settings.STATIC_URL, 'plugins', self.SLUG, *args) + if ( + settings.DEBUG + and settings.PLUGIN_DEV_HOST + and settings.PLUGIN_DEV_SLUG + and self.SLUG == settings.PLUGIN_DEV_SLUG + ): + # If the plugin is selected for development mode, use the development host + pathname = '/'.join(list(args)) + url = f'{settings.PLUGIN_DEV_HOST}/src/{pathname}' + url = url.replace('.js', '.tsx') + else: + # Otherwise, construct the URL using the STATIC_URL setting + url = os.path.join(settings.STATIC_URL, 'plugins', self.SLUG, *args) - if not url.startswith('/'): - url = '/' + url + if not url.startswith('/'): + url = '/' + url return url