mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-17 18:26:32 +00:00
Add option for pointing plugin content to a vite host (#10005)
This commit is contained in:
@@ -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_EVENTS_ASYNC = False # Flag if events are tested asynchronously
|
||||||
PLUGIN_TESTING_RELOAD = False # Flag if plugin reloading is in testing (check_reload)
|
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(
|
PLUGIN_RETRY = get_setting(
|
||||||
'INVENTREE_PLUGIN_RETRY', 'PLUGIN_RETRY', 3, typecast=int
|
'INVENTREE_PLUGIN_RETRY', 'PLUGIN_RETRY', 3, typecast=int
|
||||||
) # How often should plugin loading be tried?
|
) # How often should plugin loading be tried?
|
||||||
|
@@ -473,16 +473,34 @@ class InvenTreePlugin(VersionMixin, MixinBase, MetaBase):
|
|||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
def plugin_static_file(self, *args):
|
def plugin_static_file(self, *args) -> str:
|
||||||
"""Construct a path to a static file within the plugin directory."""
|
"""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
|
import os
|
||||||
|
|
||||||
from django.conf import settings
|
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('/'):
|
if not url.startswith('/'):
|
||||||
url = '/' + url
|
url = '/' + url
|
||||||
|
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user