2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-16 09:46:31 +00:00

Add option for pointing plugin content to a vite host (#10005)

This commit is contained in:
Oliver
2025-07-11 19:57:53 +10:00
committed by GitHub
parent 6d686cc319
commit 786fd846ba
2 changed files with 31 additions and 5 deletions

View File

@@ -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?

View File

@@ -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