Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add preload script support for component preview
Overview
This PR introduces a new
preloadconfiguration option that allows developers to inject custom JavaScript code into the component preview HTML's<head>section during development. This enables advanced debugging, analytics, polyfills, or any other client-side functionality that needs to execute before component rendering.Changes
Configuration Interface
preload?: stringto thedevelopmentsection ofOpenComponentsConfigParsedConfigtype to include the preload optionFile Processing Logic
options-sanitiser.tsthat distinguishes between file paths and inline JavaScript.jsfiles with proper error handling and fallback behaviorPreview Integration
<head>Usage
The preload option accepts either a file path or inline JavaScript:
{ "development": { "preload": "./scripts/debug.js" } }{ "development": { "preload": "console.log('Component preview loaded'); window.myGlobalVar = true;" } }Technical Details
The implementation uses a heuristic approach to determine whether the preload value is a file path or inline code:
;or{characters, it's treated as a file pathThis approach provides maximum flexibility while maintaining backward compatibility and graceful error handling.