
Installation
Install dependencies:
npm install
This will install:
esbuild- Fast TypeScript / JavaScript bundlertypescript- Strict type-checking and.d.tsemissionclean-css- CSS minifiervitest+@playwright/test- Unit / e2e test runners
Build Commands
Build Everything
Build TypeScript bundles, type declarations and CSS:
npm run build
npm run build now cleans dist/ first to avoid stale files (e.g. old chunk names) when rebuilding.
This creates:
dist/dev/vidply.esm.js- ES Module (development)dist/prod/vidply.esm.min.js- ES Module (production, minified)dist/legacy/vidply.js- IIFE bundle (development)dist/legacy/vidply.min.js- IIFE bundle (production, minified)dist/types/index.d.ts- TypeScript declarations (entry)dist/types/**/*.d.ts- Per-module declarationsdist/vidply.css- Unminified stylesdist/vidply.min.css- Minified styles
Build JavaScript Only
Bundle TypeScript with esbuild:
npm run build:js
Build TypeScript Declarations Only
Emit .d.ts files via tsc --emitDeclarationOnly:
npm run build:types
Type-check (no emit)
npm run typecheck
Build CSS Only
npm run build:css
Clean Build Directory
npm run clean
Watch Mode (Development)
Auto-rebuild on file changes:
npm run watch
Then in another terminal:
npm run dev
This starts a local server at http://localhost:3000
Build Output
JavaScript Bundles
ESM Format (dist/vidply.esm.js and .min.js)
- Modern ES6 module format
- Use with
importstatements - Tree-shakeable
- Recommended for modern projects
import Player from './dist/prod/vidply.esm.min.js';
IIFE Format (dist/vidply.js and .min.js)
- Immediately Invoked Function Expression
- Works with
<script>tags - Creates global
VidPlyvariable - For traditional web pages
<script src="dist/legacy/vidply.min.js"></script>
<script>
const player = new VidPly.Player('#video');
</script>
CSS Files
dist/vidply.css
- Unminified, readable styles
- Includes comments
- Good for development and customization
dist/vidply.min.css
- Minified and optimized
- ~60% smaller than unminified
- Use in production
Using Built Files
Option 1: ES Module (Recommended)
<link rel="stylesheet" href="dist/vidply.min.css">
<video data-vidply src="video.mp4"></video>
<script type="module">
import Player from './dist/prod/vidply.esm.min.js';
// Player auto-initializes with data-vidply
</script>
Option 2: IIFE (Traditional)
<link rel="stylesheet" href="dist/vidply.min.css">
<script src="dist/legacy/vidply.min.js"></script>
<video id="my-video" src="video.mp4"></video>
<script>
const player = new VidPly.Player('#my-video', {
controls: true,
autoplay: false
});
</script>
File Sizes
Approximate sizes (minified + gzip):
| File | Uncompressed | Gzipped |
|---|---|---|
| vidply.esm.min.js | ~50 KB | ~15 KB |
| vidply.min.js | ~52 KB | ~16 KB |
| vidply.min.css | ~12 KB | ~3 KB |
| Total | ~62 KB | ~18 KB |
Note: Actual file sizes may vary depending on the version and features included. These are approximate values for the production builds.
Build Scripts Explained
build/build.js
Main TypeScript bundling script (esbuild):
- Bundles all
src/**/*.tssource files - Creates ES Module and IIFE formats
- Generates both dev and production versions
- Adds license banner
- Creates source maps for debugging
tsc (build:types)
Runs the TypeScript compiler in declaration-only mode using tsconfig.build.json:
- Emits
.d.tsfiles todist/types/ - Used by IDEs,
tscconsumers and bundlers (vite, webpack, rollup) for type information - Referenced from
package.json#types
build/build-css.js
CSS build script:
- Copies unminified CSS to dist
- Minifies CSS for production
- Reports compression statistics
- Optimizes for performance
build/watch.js
Development watch script:
- Monitors src/ for changes
- Auto-rebuilds on save
- Creates development builds with source maps
- Faster than full production build
build/clean.js
Cleanup script:
- Removes dist/ directory
- Prepares for fresh build
Customizing the Build
Change Target Browsers
Edit build/build.js:
target: ['es2020', 'chrome90', 'firefox88', 'safari14']
Add Source Maps to Production
Edit build/build.js:
{
name: 'ESM Bundle (Minified)',
sourcemap: true, // Enable source maps
minify: true
}
Change Global Name
Edit build/build.js:
{
format: 'iife',
globalName: 'MyPlayer', // Change from VidPly
}
CI/CD Integration
GitHub Actions Example
name: Build
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/
Troubleshooting
Build Fails
Symptom: Build command fails with errors
Solutions:
# 1. Clear node_modules and reinstall
rm -rf node_modules package-lock.json
npm install
npm run build
# 2. Check Node.js version (requires 18+)
node --version
# 3. Try using npx directly
npx esbuild src/index.ts --bundle --outfile=dist/vidply.js
Type-check failures:
If npm run typecheck reports errors, run:
npx tsc --noEmit --pretty
to see full TypeScript diagnostics with source context.
Source Maps Not Working
Symptom: Unable to debug minified code in browser dev tools
Solutions:
- Ensure source maps are enabled in build config (
build/build.js) - Check browser dev tools are configured to load source maps
- Verify
.mapfiles exist indist/folder - Clear browser cache and reload
Large Bundle Size
Symptom: Bundle size is larger than expected
Explanation: The player includes:
- Complete UI controls with all buttons and menus (incl. download, buffering spinner)
- Multiple renderers (HTML5, YouTube, Vimeo, SoundCloud, HLS, DASH)
- i18n system with 5 built-in languages
- Full accessibility features (ARIA, keyboard navigation)
- Transcript, playlist, and sign language features
Solutions:
- The minified + gzipped size (~18 KB) is already optimized for production
- Modern browsers will cache the files after first load
- Consider using a CDN for better caching across sites
- For custom builds excluding unused features, modify
src/index.tsbefore building
Permission Denied on Build Scripts
Symptom: EACCES or permission errors
Solutions:
# On Linux/macOS, ensure scripts have execute permission
chmod +x build/*.js
# Or run with node explicitly
node build/build.js
Watch Mode Not Detecting Changes
Symptom: Files change but build doesn't trigger
Solutions:
- Restart watch mode
- Check if editor saves files properly (some editors use atomic writes)
- Increase file watch timeout in
build/watch.jsif needed
ESM Import Errors in Browser
Symptom: Browser console shows module import errors
Solutions:
- Ensure you're using a local server (not
file://protocol) - Check file paths are correct and relative to HTML file
- Verify
<script type="module">is set correctly - Check browser supports ES6 modules (Chrome 61+, Firefox 60+, Safari 11+)
Development Workflow
- Make changes to src/ files
- Run watch mode:
npm run watch - Test in browser:
npm run dev - View demo: http://localhost:3000/demo/
- Build production:
npm run build