-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic Imports for Video Player #181
Open
colbyfayock
wants to merge
9
commits into
main
Choose a base branch
from
feat/180-dynamic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f51575e
importing the npm module dynamically on client
colbyfayock ff4a7b1
dynamic stylesheet version, exclude stylesheet prop
colbyfayock ced633f
Merge branch 'main' into feat/180-dynamic
colbyfayock 7011af6
reverting accidental prop removal
colbyfayock 4ed7990
Merge branch 'main' into feat/180-dynamic
colbyfayock 57dfb82
copying cld video player assets from node module to export
colbyfayock 2cf1418
removing dep
colbyfayock 64fdf0c
removing dep
colbyfayock 02f0dbe
player version
colbyfayock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { Plugin } from 'esbuild' | ||
import path from 'path'; | ||
import { readdir, copyFile, readFile, lstat } from 'fs/promises'; | ||
import { mkdirp } from 'mkdirp'; | ||
|
||
let hasWrittenAssets = false; | ||
|
||
const assets = [ | ||
'cloudinary-video-player/dist/cld-video-player.min.css', | ||
'cloudinary-video-player/dist/fonts' | ||
]; | ||
|
||
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 ) { | ||
const assetPath = await resolveAssetPath(asset); | ||
|
||
if ( typeof assetPath === 'string' ) { | ||
const info = await lstat(assetPath); | ||
const isDirectory = info.isDirectory(); | ||
let files; | ||
|
||
if ( isDirectory ) { | ||
const dirFiles = await readdir(assetPath); | ||
const dirName = path.basename(assetPath); | ||
|
||
files = dirFiles.map(dirFile => { | ||
return { | ||
path: path.join(assetPath, dirFile), | ||
name: path.join(dirName, dirFile) | ||
} | ||
}); | ||
|
||
await mkdirp(path.join(distPath, dirName)); | ||
} else { | ||
files = [{ | ||
path: assetPath, | ||
name: path.basename(assetPath) | ||
}]; | ||
} | ||
|
||
for ( const file of files ) { | ||
await copyFile(file.path, path.join(distPath, file.name)); | ||
} | ||
} | ||
} | ||
|
||
hasWrittenAssets = true; | ||
} | ||
} | ||
|
||
async function resolveAssetPath(assetPath: string) { | ||
let filePath; | ||
let dirPath; | ||
|
||
// Check if it's a file in the active project root node_modules | ||
|
||
try { | ||
filePath = path.join('node_modules', assetPath); | ||
await readFile(filePath); | ||
} catch(e) { | ||
filePath = undefined; | ||
} | ||
|
||
// Check if it's a file in the workspace node_modules | ||
|
||
try { | ||
filePath = path.join('../node_modules', assetPath) | ||
await readFile(filePath); | ||
} catch(e) { | ||
filePath = undefined; | ||
} | ||
|
||
// If we've determined its a file, return early | ||
|
||
if ( filePath ) return filePath; | ||
|
||
// If it's not a file, maybe its a directory | ||
// First check in active project root | ||
|
||
try { | ||
dirPath = path.join('node_modules', assetPath) | ||
await readdir(dirPath); | ||
} catch(e) { | ||
dirPath = undefined; | ||
} | ||
|
||
// Then again in the workspace root | ||
|
||
try { | ||
dirPath = path.join('../node_modules', assetPath) | ||
await readdir(dirPath); | ||
} catch(e) { | ||
dirPath = undefined; | ||
} | ||
|
||
return dirPath; | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
i dont love this solution but couldn't figure out a way to resolve the node_modules reliably with being in a yarn workspace