-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: CldVideoPlayer support for Next.js 13 App Router (#265)
# Description With the App Router, we no longer have access to the <Head component. CldVideoPlayer was utilizing this component in order to load a stylesheet, preventing the need to include it from the project, but without <Head, the player breaks. Given this is no longer an option, this includes the CSS and associated files on build so that they're able to be imported from within the App Router project, allowing the stylesheet to be imported for a working player. This is currently downloading the assets from unpkg, where the player is officially hosted, though future iterations may include these files from the cloudinary-video-player node_module, though thats currently on hold for performance reasons. See #181 This also deprecates the `version` prop as we're no longer able to reliably grab assets based on the configured version (or at all for that matter). In future versions using the node module, the assets will be synced based on the installed dependency via next-cloudinary without configuration available. ## Issue Ticket Number Fixes #248 <!-- Specify above which issue this fixes by referencing the issue number (`#<ISSUE_NUMBER>`) or issue URL. --> <!-- Example: Fixes https://github.com/colbyfayock/next-cloudinary/issues/<ISSUE_NUMBER> --> ## Type of change <!-- Please select all options that are applicable. --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] Fix or improve the documentation - [ ] This change requires a documentation update # Checklist <!-- These must all be followed and checked. --> - [ ] I have followed the contributing guidelines of this project as mentioned in [CONTRIBUTING.md](/CONTRIBUTING.md) - [ ] I have created an [issue](https://github.com/colbyfayock/next-cloudinary/issues) ticket for this PR - [ ] I have checked to ensure there aren't other open [Pull Requests](https://github.com/colbyfayock/next-cloudinary/pulls) for the same update/change? - [ ] I have performed a self-review of my own code - [ ] I have run tests locally to ensure they all pass - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes needed to the documentation
- Loading branch information
1 parent
52bad18
commit 8674b95
Showing
8 changed files
with
99 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Plugin } from 'esbuild' | ||
import path from 'path'; | ||
import { createWriteStream } from 'fs'; | ||
import { mkdirp } from 'mkdirp'; | ||
import https from 'https'; | ||
|
||
const version = '1.9.14'; | ||
|
||
const assets = [ | ||
`https://unpkg.com/cloudinary-video-player@${version}/dist/cld-video-player.css`, | ||
{ | ||
directory: 'fonts', | ||
assets: [ | ||
`https://unpkg.com/cloudinary-video-player@${version}/dist/fonts/cloudinary_icon_for_black_bg.svg`, | ||
`https://unpkg.com/cloudinary-video-player@${version}/dist/fonts/cloudinary_icon_for_white_bg.svg`, | ||
] | ||
} | ||
]; | ||
|
||
let hasWrittenAssets = false; | ||
|
||
export const plugin: Plugin = { | ||
name: 'copy-assets', | ||
setup: async () => { | ||
const rootPath = path.join(__dirname, '../'); | ||
const distPath = path.join(rootPath, 'dist'); | ||
|
||
if ( hasWrittenAssets ) return; | ||
|
||
await mkdirp(distPath); | ||
|
||
for ( const asset of assets ) { | ||
|
||
if ( typeof asset === 'string' ) { | ||
const writePath = path.join(distPath, path.basename(asset)); | ||
await downloadFile(asset, writePath); | ||
console.log(`Wrote ${asset} to ${writePath}`); | ||
} else if ( typeof asset.directory === 'string' ) { | ||
await mkdirp(path.join(distPath, asset.directory)); | ||
|
||
for ( const dirAsset of asset.assets ) { | ||
const writePath = path.join(distPath, asset.directory, path.basename(dirAsset)); | ||
await downloadFile(dirAsset, writePath); | ||
console.log(`Wrote ${dirAsset} to ${writePath}`); | ||
} | ||
} | ||
} | ||
|
||
hasWrittenAssets = true; | ||
} | ||
} | ||
|
||
/** | ||
* downloadFile | ||
*/ | ||
|
||
function downloadFile(assetUrl: string, writePath: string) { | ||
return new Promise<void>((resolve) => { | ||
const file = createWriteStream(writePath); | ||
https.get(assetUrl, function(response) { | ||
response.pipe(file); | ||
file.on('finish', () => { | ||
file.close(); | ||
resolve(); | ||
}); | ||
}); | ||
}) | ||
} |
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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { defineConfig } from 'tsup' | ||
import { plugin as CopyAssetsPlugin } from './plugins/copy-assets'; | ||
|
||
export default defineConfig({ | ||
minify: true, | ||
target: 'es2018', | ||
external: ['react'], | ||
sourcemap: true, | ||
dts: true, | ||
format: ['esm', 'cjs'] | ||
format: ['esm', 'cjs'], | ||
esbuildPlugins: [CopyAssetsPlugin] | ||
}) |
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
8674b95
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
next-cloudinary – ./
next-cloudinary-cloudinarydevx.vercel.app
next-cloudinary.spacejelly.dev
next.cloudinary.dev
next-cloudinary-git-main-cloudinarydevx.vercel.app
next-cloudinary.vercel.app