Add helpers for Vue and Vite extensions #43
Merged
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.


I create this PR to add some more functionality in the Connect UI Toolkit to make our lives easier when working with Connect extensions.
This PR adds two new features:
Toolkit Vue plugin
It is a very straight forward Vue plugin that allows us to have access to the toolkit app instance inside Vue components.
Besides exposing the raw toolkit app instance, it has a reactive property,
sharedContext, that is updated when the shared context from the Connect SPA to the Extension changes (this is the state we provide with thevalue/v-modeltoc-slotin the SPA).It can be used in several ways:
Options API:
Composition API:
To use it in an extension:
Vite config generator
The
defineExtensionConfigfunction is used to generate a default Vite config that works for Connect extensions.It does the following:
~) that points to the extension's source directory (provided by the user){{srcDir}}/pages/{{pageName}}/index.htmlas an entry point that will be output in the extension's static directory (provided by the user). I'll show this in more detail in a PR for the Connect BI Reporter extension later.The function has two parameters:
config: Object, required.config.srcDir: String, required. The absolute path for the source directory.config.srcUrl: URL, required. URL for the src folder, used for aliasing '~'.config.outputDir: String, required. The absolute path for the output directory.config.vuePlugin: Object, required. An instance of the Vue plugin for Vite.viteConfig: Object, optional. Any other Vite config options you need.I attempted to use a configuration file (something like
connect.config.js) and guess most of these properties, but it gets really complex really quickly when you are doing things from a package outside the extensions context, like the toolkit is. So this is the easiest way, and I think that it is not very cumbersome to use. Let me know if you have any thoughts on this.To use it in the extensions, create a
vite.config.jsfile and paste the following: