diff --git a/package.json b/package.json index 68220058..b702f138 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Cloudinary Video Player", "author": "Cloudinary", "license": "MIT", - "module": "./lib/videoPlayer.js", + "module": "./lib/cld-video-player.js", "main": "./dist/cld-video-player.min.js", "style": "./dist/cld-video-player.min.css", "types": "./types/cld-video-player.d.ts", @@ -18,7 +18,7 @@ ], "exports": { ".": { - "import": "./lib/videoPlayer.js", + "import": "./lib/cld-video-player.js", "require": "./dist/cld-video-player.js", "types": "./types/cld-video-player.d.ts" }, diff --git a/src/index.all.js b/src/index.all.js index bccb2275..4238211d 100644 --- a/src/index.all.js +++ b/src/index.all.js @@ -1,10 +1,9 @@ -// This file is bundled as `cld-video-player.js` to be imported as a single module that -// includes all plugins. +// This file is bundled as `all.js` to be imported as a single module that includes all plugins. // Usage: -// import { videoPlayer, videoPlayers } from 'cloudinary-video-player'; +// import { videoPlayer, videoPlayers } from 'cloudinary-video-player/all'; // Or: -// import cloudinary from 'cloudinary-video-player'; +// import cloudinary from 'cloudinary-video-player/all'; import cloudinary from './index.js'; diff --git a/src/index.es.js b/src/index.es.js index 507ab3d5..b4ab13b8 100644 --- a/src/index.es.js +++ b/src/index.es.js @@ -1,7 +1,18 @@ -// This file is bundled as `videoPlayer.js` to be imported as a tree-shaken module. +// This file is bundled as `cld-video-player.js` to be imported as a tree-shaken module. +// It is the default export of the Cloudinary Video Player. // Usage: -// import videoPlayer from 'cloudinary-video-player/videoPlayer'; -// import dashjs from "cloudinary-video-player/dash"; +// import cloudinary from 'cloudinary-video-player'; +// Or: +// import { videoPlayer } from "cloudinary-video-player"; -export { videoPlayer as default } from './index.js'; +// Other modules can be imported like that: +// import dash from 'cloudinary-video-player/dash'; + +import cloudinary from './index.js'; + +export const videoPlayer = cloudinary.videoPlayer; +export const videoPlayers = cloudinary.videoPlayers; +export const videoPlayerWithProfile = cloudinary.videoPlayerWithProfile; + +export default cloudinary; diff --git a/src/index.js b/src/index.js index f26e2466..152e9262 100644 --- a/src/index.js +++ b/src/index.js @@ -5,12 +5,6 @@ import { assign } from 'utils/assign'; import { pick, convertKeysToSnakeCase } from './utils/object'; import { CLOUDINARY_CONFIG_PARAM } from './video-player.const'; -if (window.cloudinary && window.cloudinary.Cloudinary) { - console.warn( - 'For version 1.9.0 and above, cloudinary-core is not needed for using the Cloudinary Video Player' - ); -} - const getConfig = (playerOptions = {}, cloudinaryConfig) => { const snakeCaseCloudinaryConfig = pick(convertKeysToSnakeCase(playerOptions), CLOUDINARY_CONFIG_PARAM); @@ -26,26 +20,17 @@ const getVideoPlayer = config => (id, playerOptions, ready) => const getVideoPlayers = config => (selector, playerOptions, ready) => VideoPlayer.all(selector, getConfig(playerOptions, config), ready); -const cloudinaryVideoPlayerConfig = config => ({ - videoPlayer: getVideoPlayer(config), - videoPlayers: getVideoPlayers(config) -}); +const getVideoPlayerWithProfile = config => (id, playerOptions, ready) => createVideoPlayerProfile(id, getConfig(playerOptions, config), ready); export const videoPlayer = getVideoPlayer(); export const videoPlayers = getVideoPlayers(); - -const getVideoPlayerWithProfile = config => (id, playerOptions, ready) => createVideoPlayerProfile(id, getConfig(playerOptions, config), ready); export const videoPlayerWithProfile = getVideoPlayerWithProfile(); const cloudinary = { ...(window.cloudinary || {}), videoPlayer, videoPlayers, - videoPlayerWithProfile, - Cloudinary: { - // Backwards compatibility with SDK v1 - new: cloudinaryVideoPlayerConfig - } + videoPlayerWithProfile }; window.cloudinary = cloudinary; diff --git a/src/index.videoPlayer.js b/src/index.videoPlayer.js new file mode 100644 index 00000000..4fcdc316 --- /dev/null +++ b/src/index.videoPlayer.js @@ -0,0 +1,6 @@ +// This file is bundled as `videoPlayer.js` to be imported as a tree-shaken module. + +// Usage: +// import videoPlayer from 'cloudinary-video-player/videoPlayer'; + +export { videoPlayer as default } from './index.js'; diff --git a/src/index.videoPlayerWithProfile.js b/src/index.videoPlayerWithProfile.js new file mode 100644 index 00000000..e739ba95 --- /dev/null +++ b/src/index.videoPlayerWithProfile.js @@ -0,0 +1,6 @@ +// This file is bundled as `videoPlayerWithProfile.js` to be imported as a tree-shaken module. + +// Usage: +// import videoPlayerWithProfile from 'cloudinary-video-player/videoPlayerWithProfile'; + +export { videoPlayerWithProfile as default } from './index.js'; diff --git a/src/video-player-profile.js b/src/video-player-profile.js index 35bc423a..abb6c5bf 100644 --- a/src/video-player-profile.js +++ b/src/video-player-profile.js @@ -1,8 +1,7 @@ import VideoPlayer from './video-player'; +import { defaultProfiles } from './config/profiles'; export const getProfile = async (cloudName, profile) => { - const { defaultProfiles } = await import(/* webpackChunkName: "defaultProfiles" */ './config/profiles'); - if (Object.keys(defaultProfiles).includes(profile)) { return defaultProfiles[profile]; } diff --git a/src/video-profile-export.es.js b/src/video-profile-export.es.js deleted file mode 100644 index 8c86de90..00000000 --- a/src/video-profile-export.es.js +++ /dev/null @@ -1 +0,0 @@ -export { videoPlayerWithProfile as default } from './index.js'; diff --git a/types/cld-video-player.d.ts b/types/cld-video-player.d.ts index 7adbe341..ca889b22 100644 --- a/types/cld-video-player.d.ts +++ b/types/cld-video-player.d.ts @@ -6,19 +6,11 @@ export const videoPlayer: VideoPlayerFunction; export const videoPlayers: VideoMultiPlayersFunction; export const videoPlayerWithProfile: VideoPlayerWithProfileFunction; -interface CommonCloudinary { - videoPlayer: VideoPlayerFunction; - videoPlayers: VideoMultiPlayersFunction; - videoPlayerWithProfile: VideoPlayerWithProfileFunction; -} -export interface Cloudinary extends CommonCloudinary { +export interface Cloudinary { videoPlayer: VideoPlayerFunction; videoPlayers: VideoMultiPlayersFunction; videoPlayerWithProfile: VideoPlayerWithProfileFunction; - Cloudinary: { - new: (options?: any) => CommonCloudinary; - }; } declare global { diff --git a/webpack/es6.config.js b/webpack/es6.config.js index cb9938e9..f4e37c6f 100644 --- a/webpack/es6.config.js +++ b/webpack/es6.config.js @@ -3,14 +3,16 @@ const webpackCommon = require('./common.config'); const path = require('path'); delete webpackCommon.output; // overwrite +delete webpackCommon.devtool; // disable module.exports = merge(webpackCommon, { mode: 'production', entry: { - 'cld-video-player': './index.all.js', - 'videoPlayer': './index.es.js', - 'videoPlayerWithProfile': './video-profile-export.es.js' + 'cld-video-player': './index.es.js', // default + 'videoPlayer': './index.videoPlayer.js', + 'videoPlayerWithProfile': './index.videoPlayerWithProfile.js', + 'all': './index.all.js' }, output: {