The `vue-inbrowser-compiler` package allows for the compilation of Vue Single File Components (SFCs), pseudo-JSX, and plain Vue app definitions directly within the browser environment. It is primarily designed for applications requiring dynamic, user-editable Vue components, such as live code editors, interactive documentation (e.g., Vue Styleguidist), or component playgrounds, eliminating the need for server-side compilation. The current stable version is 4.72.4. Based on its frequent patch and minor updates within the `vue-styleguidist` monorepo, it maintains an active development and release cadence. Its key differentiator is the ability to perform full Vue component compilation dynamically on the client-side, integrating with tools like Buble for JavaScript transpilation, providing a flexible and immediate feedback loop for component development.
npm install vue-inbrowser-compilerVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to compile a Vue Single File Component (SFC) string dynamically in the browser, inject its styles, and mount it using Vue 3's `createApp`.
Refer to the Buble documentation for supported features and configuration options when compiling JavaScript within Vue components. Avoid using advanced experimental Babel features.
Upgrade to `vue-inbrowser-compiler@4.72.4` or newer to ensure full compatibility with Vue 3.3.2 and its associated features. Always keep `vue` and `vue-inbrowser-compiler` versions aligned.
Configure Buble with `{ jsx: '__pragma__(h)' }` and then call the compiled function with `func(adaptCreateElement)` to correctly handle JSX rendering, as shown in the package's documentation.For SFCs, the `compiled.style` output should contain the correctly scoped CSS. If injecting additional styles or working with non-SFC CSS, explicitly call `addScopedStyle(cssString, uniqueSuffix)` to ensure proper encapsulation and application.
Ensure that your `compile` call's Buble configuration includes `{ jsx: '__pragma__(h)' }` and that the `new Function()` call for the compiled script is invoked with `func(adaptCreateElement)`.Manually move variables intended for reactive use within the component's template into the `data` property of the returned component object. For more complex scenarios, consider using the `new Vue({...})` or full Single File Component syntax.Always pass your raw Vue component code through the `compile(code, config)` function first. The `compile` function will return an object containing `script` and `style` strings, where `script` is the valid JavaScript string ready for `new Function()`.