forked from zhihu/griffith
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use pure ESM format (zhihu#167)
removed `__WITHOUT_HLSJS__` and `__WITHOUT_MP4__`
- Loading branch information
Showing
19 changed files
with
1,420 additions
and
863 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Demo</title> | ||
</head> | ||
<body> | ||
<div id="player"></div> | ||
<script src="../dist/index.umd.min.js"></script> | ||
<script> | ||
const target = document.getElementById('player') | ||
const sources = { | ||
hd: { | ||
play_url: 'https://zhstatic.zhihu.com/cfe/griffith/zhihu2018_hd.mp4', | ||
}, | ||
sd: { | ||
play_url: 'https://zhstatic.zhihu.com/cfe/griffith/zhihu2018_sd.mp4', | ||
}, | ||
} | ||
// 创建播放器 | ||
const player = Griffith.createPlayer(target) | ||
// 载入视频 | ||
player.render({sources}) | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import path from 'path' | ||
import babel from '@rollup/plugin-babel' | ||
import resolve from '@rollup/plugin-node-resolve' | ||
import replace from '@rollup/plugin-replace' | ||
import commonjs from '@rollup/plugin-commonjs' | ||
import alias from '@rollup/plugin-alias' | ||
import {terser} from 'rollup-plugin-terser' | ||
|
||
const pkg = require(path.resolve(process.cwd(), 'package.json')) | ||
|
||
export default [ | ||
{ | ||
input: pkg.source, | ||
output: [ | ||
{ | ||
file: pkg.main, | ||
format: 'umd', | ||
name: 'Griffith', | ||
sourcemap: false, | ||
}, | ||
], | ||
plugins: [ | ||
babel(require('../../babel.config')), | ||
commonjs({ | ||
// 不是所有的包都是 ESM(如 React 只是 CJS) | ||
include: /node_modules/, | ||
}), | ||
alias({ | ||
entries: { | ||
// 如果需要排除插件 | ||
// 'griffith-hls': 'griffith/null', | ||
// 'griffith-mp4': 'griffith/null', | ||
}, | ||
}), | ||
replace({ | ||
preventAssignment: true, | ||
values: { | ||
'process.env.NODE_ENV': JSON.stringify('production'), | ||
}, | ||
}), | ||
resolve({ | ||
// 有些 npm 包提供了 browser 版本(如 `asap` node 版本使用了 native 模块) | ||
browser: true, | ||
}), | ||
terser(), | ||
], | ||
}, | ||
] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "null", | ||
"version": "1.0.0", | ||
"main": "null.cjs.js", | ||
"module": "null.esm.js", | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
"files": [ | ||
"cjs", | ||
"esm", | ||
"null", | ||
"index.d.ts" | ||
], | ||
"source": "src/index.js", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
import {isHlsNativeSupported, isMSESupported} from 'griffith-utils' | ||
import GriffithHls from 'griffith-hls' | ||
import GriffithMp4 from 'griffith-mp4' | ||
import NormalVideo from './NormalVideo' | ||
/* global __WITHOUT_HLSJS__:false, __WITHOUT_MP4__:false */ | ||
import memoize from 'lodash/memoize' | ||
|
||
export default function selectVideo(format, useMSE) { | ||
if (format === 'm3u8') { | ||
if (typeof __WITHOUT_HLSJS__ === 'undefined' ? false : __WITHOUT_HLSJS__) { | ||
return NormalVideo | ||
} else if (isMSESupported() && !isHlsNativeSupported()) { | ||
return require('griffith-hls').default | ||
} | ||
function selectVideo(format, useMSE) { | ||
if ( | ||
format === 'm3u8' && | ||
GriffithHls?.VideoComponent && | ||
isMSESupported() && | ||
!isHlsNativeSupported() | ||
) { | ||
return GriffithHls | ||
} | ||
if (format === 'mp4') { | ||
if (typeof __WITHOUT_MP4__ === 'undefined' ? false : __WITHOUT_MP4__) { | ||
return NormalVideo | ||
} else if (isMSESupported() && useMSE) { | ||
return require('griffith-mp4').default | ||
} | ||
if ( | ||
format === 'mp4' && | ||
GriffithMp4?.VideoComponent && | ||
isMSESupported() && | ||
useMSE | ||
) { | ||
return GriffithMp4 | ||
} | ||
return NormalVideo | ||
} | ||
|
||
// 内部利用了 DOM 推测,避免 render 过程中多次执行 | ||
export default memoize(selectVideo, (...args) => String(args)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
// gatsby 的 ESLint 与 root 冲突了,会导致 `eslint-config-react-app` 查找不到,禁止它 | ||
extends: [require.resolve('../.eslintrc.js')], | ||
} |
Oops, something went wrong.