如何将video.js与create-next-app nextjs一起使用?

时间:2018-06-06 06:47:25

标签: css webpack video.js nextjs

我正在尝试将Video.js与create-next-app一起使用,但我无法加载video.js.css。这就是我的组件的样子。

import videojs from 'video.js'

import videoStyles from '../node_modules/video.js/dist/video-js.min.css'

export default class VideoPlayer extends React.Component {
  componentDidMount() {
    // instantiate Video.js
    this.player = videojs(this.videoNode, this.props, function onPlayerReady() {
      console.log('onPlayerReady', this)
    });
  }

  // destroy player on unmount
  componentWillUnmount() {
    if (this.player) {
      this.player.dispose()
    }
  }

  // wrap the player in a div with a `data-vjs-player` attribute
  // so videojs won't create additional wrapper in the DOM
  // see https://github.com/videojs/video.js/pull/3856
  render() {
    return (
      <div>    
        <div data-vjs-player>
          <video ref={ node => this.videoNode = node } className="video-js"></video>
        </div>
        <style jsx>{videoStyles}</style>
      </div>
    )
  }
}

我使用styled-jsx/css loader加载外部css文件。

1 个答案:

答案 0 :(得分:0)

查看next.js github example。应该足以让您入门。