silvermine / videojs-quality-selector

MIT License
180 stars 55 forks source link

Does not work with Vite #90

Closed Oleksii14 closed 9 months ago

Oleksii14 commented 1 year ago

Hi!

According to the documentation and examples, the usage of videojs-quality-selector via npm/yarn requires require call which is webpack feature, so it does not work with Vite.

Can you push some updates to the core so the module can be imported and used like that:

import videojs from 'videojs'
import VideojsQualitySelector from '@silvermine/videojs-quality-selector'

VideojsQualitySelector(videojs)

Thanks in advance.

UPD

Workaround

The package script can be loaded via unpkg manually.

import videojs from 'video.js'

const loadQualitySelectorScript = () => {
  window.videojs = videojs
  const SCRIPT_URL = "https://unpkg.com/@silvermine/videojs-quality-selector/dist/js/silvermine-videojs-quality-selector.min.js";
  const s = document.createElement('script');

  s.src = SCRIPT_URL;
  s.type = "text/javascript";
  s.async = false;
  document.getElementsByTagName('head')[0].appendChild(s);
}
loadQualitySelectorScript();
Sube-py commented 1 year ago

@Oleksii14 Hay, boys, vite not supported require, you can modify your vite.config, use optimizeDeps: { include: 'package name' } , but this repo also not support vite, because it dependence class.extend, fortunately, the author is rebuilding and looking forawrd to the new version🙏

yokuze commented 9 months ago

class.extend was removed in v1.3.1 of this plugin, so there should no longer be an error thrown on import. As @Sube-py notes, you also need to include optimizeDeps: { include: [ '@silvermine/videojs-quality-selector' ] } in your Vite config. Thanks!