I have a root instance that has several CustomVideo-components in it (amongst a bunch of other components). The CustomVideo-component implements VideoJS, but it's not on all pages that there is a CustomVideo-component, so I don't want to import VideoJS globally. Here is an example of components on a page:
App.js
|
|-- CustomVideo
|-- FooComponent
|-- CustomVideo
|-- BarComponent
|-- CustomVideo
In the top of CustomVideo, I import VideoJS, like so:
import videojs from 'video.js';
import abLoopPlugin from 'videojs-abloop'
export default {
name: "FeaturedVideoPlayer",
props: {
videoUrl: String
}
mounted() {
let videoOptions = {
sources: [
{
src: this.videoUrl,
type: "video/mp4"
}
],
plugins: {
abLoopPlugin: {
'enabled': true
}
}
};
this.player = videojs(this.$refs.featuredVideoPlayer, videoOptions, function onPlayerReady() {});
}
But if there are more than one CustomVideo, then I get a console warning:
VIDEOJS: WARN: A plugin named "abLoopPlugin" already exists. You may want to avoid re-registering plugins!
I tried looking into conditional imports, but it doesn't seem like it's the way to do it.
Even if I try and import it in app.js, even though I would rather import it CustomVideo, then I get another console error:
Attempt
import abLoopPlugin from 'videojs-abloop'
Vue.use( abLoopPlugin );
Then I get the error:
Uncaught TypeError: Cannot read property 'registerPlugin' of undefined
How do I ensure that a plugin is registered only once?
app.js. Example:import videojs from 'video.js' import abLoopPlugin from 'videojs-abloop' abLoopPlugin(window,videojs)Refer to Github: Videojs-abloop