Vue Shepherd
Vue Shepherd is a Vue wrapper library for Shepherd.js, a robust JavaScript library designed for guiding users through applications with interactive site tours. The package is currently at its stable version 6.0.0 and offers integration for both Vue's Composition API via `useShepherd` and Options API using `VueShepherdPlugin`. It differentiates itself by providing a native Vue experience for Shepherd.js, simplifying the process of adding step-by-step guides within Vue applications. The release cadence is moderate, often aligning with updates to the underlying Shepherd.js library and broader Vue ecosystem evolutions. A critical aspect for adopters is the licensing; starting from v5.0.1, the library transitioned to the AGPL-3.0 license, which necessitates a commercial license for commercial products and revenue-generating companies.
Common errors
-
Module not found: Error: Can't resolve 'shepherd.js/dist/css/shepherd.css'
cause The necessary CSS stylesheet for Shepherd.js, which `vue-shepherd` depends on for styling, has not been imported.fixAdd `import 'shepherd.js/dist/css/shepherd.css'` to your main application entry file (e.g., `main.js` or `main.ts`) or the component where you initialize the tour. -
TypeError: this.$shepherd is not a function
cause When using the Options API, `VueShepherdPlugin` must be explicitly installed with `app.use()` before `$shepherd` becomes available on the component instance.fixEnsure you have `import VueShepherdPlugin from 'vue-shepherd';` and `createApp(App).use(VueShepherdPlugin).mount('#app');` in your application's entry point. -
Error: Vue Shepherd requires a Vue 3 environment. Detected Vue version is 2.x.
cause Attempting to use `vue-shepherd` version 2.0.0 or higher in a Vue 2 application, which is no longer supported.fixEither upgrade your application to Vue 3.x or downgrade `vue-shepherd` to a version compatible with Vue 2.x (e.g., v1.x or earlier). -
SyntaxError: Named export 'VueShepherdPlugin' not found (module 'vue-shepherd')
cause Attempting to use a named import for `VueShepherdPlugin` when it is exported as a default export for the Options API plugin.fixChange the import statement from `import { VueShepherdPlugin } from 'vue-shepherd'` to `import VueShepherdPlugin from 'vue-shepherd'`.
Warnings
- breaking The license for vue-shepherd and its upstream library Shepherd.js changed from MIT to AGPL-3.0. Commercial projects now require a commercial license.
- breaking Version 2.0.0 introduced breaking changes by dropping support for Vue 2 and exclusively supporting Vue 3.
- breaking Major version bumps in the underlying `shepherd.js` library (e.g., to v8 and v10) have historically introduced breaking changes that propagate to `vue-shepherd`.
- gotcha Native TypeScript declarations were added in v4.1.0. Older versions might have incomplete or incorrect type definitions, leading to poor developer experience or type errors in TypeScript projects.
Install
-
npm install vue-shepherd -
yarn add vue-shepherd -
pnpm add vue-shepherd
Imports
- useShepherd
import { useShepherd } from 'vue-shepherd' - VueShepherdPlugin
import { VueShepherdPlugin } from 'vue-shepherd'import VueShepherdPlugin from 'vue-shepherd'
- CSS Styles
import 'shepherd.js/dist/css/shepherd.css'
- VueShepherd (SSR)
import VueShepherd from 'vue-shepherd/dist/vue-shepherd.ssr.js'
Quickstart
import { createApp, ref, onMounted } from 'vue';
import { useShepherd } from 'vue-shepherd';
import 'shepherd.js/dist/css/shepherd.css';
const App = {
setup() {
const el = ref(null);
const tour = useShepherd({
useModalOverlay: true,
defaultStepOptions: {
cancelIcon: {
enabled: true
}
}
});
onMounted(() => {
tour.addStep({
id: 'intro',
attachTo: { element: el.value, on: 'top' },
text: 'This is your first step! Click next to continue.',
buttons: [
{ action: tour.cancel, text: 'Exit' },
{ action: tour.next, text: 'Next' }
]
});
tour.addStep({
id: 'second',
text: 'This step demonstrates a modal overlay and custom buttons.',
buttons: [
{ action: tour.back, text: 'Back' },
{ action: tour.complete, text: 'Done' }
]
});
tour.start();
});
return { el };
},
template: `
<div id="app">
<h1>Welcome to Vue Shepherd!</h1>
<div ref="el" style="border: 1px solid blue; padding: 20px; margin-top: 50px;">
Content for the tour step.
</div>
</div>
`
};
createApp(App).mount('#app');