Skip to content
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

Include vtt.js using require/browserify #3794

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 47 additions & 25 deletions build/grunt.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {gruntCustomizer, gruntOptionsMaker} from './options-customizer.js';
import chg from 'chg';
import npmRun from 'npm-run';
import envify from 'envify/custom';

module.exports = function(grunt) {
require('time-grunt')(grunt);
Expand All @@ -27,6 +28,16 @@ module.exports = function(grunt) {
]
};

const browserifyTransform = function(options) {
var transform = [
[envify({VTT: options.VTT})],
['unreachable-branch-transform'],
['browserify-shim']
];

return transform;
};

const githubReleaseDefaults = {
options: {
release: {
Expand Down Expand Up @@ -127,10 +138,6 @@ module.exports = function(grunt) {
},
dist: {},
watch: {
novtt: {
files: ['build/temp/video.js'],
tasks: ['concat:novtt']
},
minify: {
files: ['build/temp/video.js'],
tasks: ['uglify']
Expand Down Expand Up @@ -320,25 +327,30 @@ module.exports = function(grunt) {
}
},
browserify: {
options: browserifyGruntOptions(),
build: {
options: browserifyGruntOptions({transform: browserifyTransform({VTT: true})}),
files: {
'build/temp/video.js': ['es5/video.js']
}
},
buildnovtt: {
options: browserifyGruntOptions({transform: browserifyTransform({VTT: false})}),
files: {
'build/temp/alt/video.novtt.js': ['es5/video.js']
}
},
dist: {
options: browserifyGruntOptions({
transform: [
['browserify-versionify', {
placeholder: '../node_modules/videojs-vtt.js/dist/vtt.js',
version: 'https://cdn.rawgit.com/gkatsev/vtt.js/vjs-v0.12.1/dist/vtt.min.js'
}],
]
}),
options: browserifyGruntOptions({transform: browserifyTransform({VTT: true})}),
files: {
'build/temp/video.js': ['es5/video.js']
}
},
distnovtt: {
options: browserifyGruntOptions({transform: browserifyTransform({VTT: false})}),
files: {
'build/temp/alt/video.novtt.js': ['es5/video.js']
}
},
watch: {
options: {
watch: true,
Expand All @@ -348,6 +360,16 @@ module.exports = function(grunt) {
'build/temp/video.js': ['es5/video.js']
}
},
watchnovtt: {
options: {
watch: true,
keepAlive: true
},
files: {
'build/temp/alt/video.novtt.js': ['es5/video.js']
}
},

tests: {
options: {
browserifyOptions: {
Expand Down Expand Up @@ -384,14 +406,6 @@ module.exports = function(grunt) {
options: {
separator: '\n'
},
novtt: {
src: ['build/temp/video.js'],
dest: 'build/temp/alt/video.novtt.js'
},
vtt: {
src: ['build/temp/video.js', 'node_modules/videojs-vtt.js/dist/vtt.js'],
dest: 'build/temp/video.js'
},
ie8_addition: {
src: ['build/temp/video-js.css', 'src/css/ie8.css'],
dest: 'build/temp/video-js.css'
Expand All @@ -410,12 +424,14 @@ module.exports = function(grunt) {
watchAll: [
'watch',
'browserify:watch',
'browserify:watchnovtt',
'browserify:tests',
'karma:watch'
],
watchSandbox: [
'watch',
'browserify:watch'
'browserify:watch',
'browserify:watchnovtt',
]
},
usebanner: {
Expand Down Expand Up @@ -495,8 +511,7 @@ module.exports = function(grunt) {

'babel:es5',
'browserify:build',
'concat:novtt',
'concat:vtt',
'browserify:buildnovtt',
'usebanner:novtt',
'usebanner:vtt',
'uglify',
Expand All @@ -515,7 +530,14 @@ module.exports = function(grunt) {

grunt.registerTask(
'build:dist',
buildDependents.map(task => task === 'browserify:build' ? 'browserify:dist' : task)
buildDependents.map(task => {
if (task === 'browserify:build') {
return 'browserify:dist';
} else if (task === 'browserify:buildnovtt') {
return 'browserify:distnovtt';
}
return task;
})
);

grunt.registerTask('dist', [
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"type": "git",
"url": "https://github.com/videojs/video.js.git"
},
"browserify-shim": {
"videojs-vtt.js": "node_modules/videojs-vtt.js/dist/vtt.js"
},
"dependencies": {
"babel-runtime": "^6.9.2",
"global": "4.3.0",
Expand All @@ -56,11 +59,13 @@
"blanket": "^1.1.6",
"browserify-derequire": "^0.9.4",
"browserify-istanbul": "^2.0.0",
"browserify-shim": "^3.8.12",
"browserify-versionify": "^1.0.4",
"bundle-collapser": "^1.2.1",
"chg": "^0.3.2",
"conventional-changelog-cli": "^1.2.0",
"conventional-changelog-videojs": "^3.0.0",
"envify": "^3.4.1",
"es5-shim": "^4.1.3",
"es6-shim": "^0.35.1",
"ghooks": "^1.3.2",
Expand Down Expand Up @@ -114,6 +119,7 @@
"sinon": "^1.16.1",
"time-grunt": "^1.1.1",
"uglify-js": "~2.7.3",
"unreachable-branch-transform": "^0.5.1",
"videojs-doc-generator": "0.0.1",
"videojs-standard": "^6.0.1",
"webpack": "^1.13.2"
Expand Down
7 changes: 6 additions & 1 deletion src/js/tech/tech.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,12 @@ class Tech extends Component {
if (!window.WebVTT && this.el().parentNode !== null && this.el().parentNode !== undefined) {
const script = document.createElement('script');

script.src = this.options_['vtt.js'] || '../node_modules/videojs-vtt.js/dist/vtt.js';
if (process.env.VTT === false) {
script.src = this.options_['vtt.js'] || 'https://cdn.rawgit.com/gkatsev/vtt.js/vjs-v0.12.1/dist/vtt.js';
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be changed to true === false or false === false depending on envify configuration. From there unreachable-branch-transform will remove one of these if statements.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dig it. Proper pre-processing! 👍

if (process.env.VTT === true) {
script.src = this.options_['vtt.js'] || require('videojs-vtt.js');
}
script.onload = () => {
/**
* Fired when vtt.js is loaded.
Expand Down