Skip to content

Commit

Permalink
chore: define globals via webpack DefinePlugin (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrenMe authored and Dan Ziv committed Sep 17, 2017
1 parent c7a2995 commit c2eb85f
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 55 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
},
"globals": {
"should": true,
"sinon": true
"sinon": true,
"__VERSION__": true,
"__NAME__": true,
"__PACKAGE_URL__": true
},
"rules": {
"mocha-no-only/mocha-no-only": "off",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"standard-version": "^4.2.0",
"style-loader": "^0.18.2",
"uglifyjs-webpack-plugin": "^0.4.3",
"webpack": "latest",
"webpack": "^3.6.0",
"webpack-dev-server": "latest"
},
"repository": {
Expand Down
17 changes: 7 additions & 10 deletions src/playkit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@flow
import Player from './player'
import LoggerFactory from './utils/logger'
import * as packageData from '../package.json'
import BaseMediaSourceAdapter from './engines/html5/media-source/base-media-source-adapter'
import {registerMediaSourceAdapter} from './engines/html5/media-source/media-source-provider'
import {registerPlugin} from './plugin/plugin-manager'
Expand All @@ -15,14 +14,12 @@ import TextTrack from './track/text-track'
import Env from './utils/env'
import * as Utils from './utils/util'

// Playkit version
const VERSION = packageData.version;
declare var __VERSION__:string;
declare var __NAME__:string;
declare var __PACKAGE_URL__:string;

// Playkit name
const PLAYER_NAME = 'kaltura-playkit-js';

LoggerFactory.getLogger().log("%c Playkit " + VERSION, "color: #3399ff; font-size: large");
LoggerFactory.getLogger().log("%c For more details see https://github.com/kaltura/playkit-js", "color: #3399ff;");
LoggerFactory.getLogger().log(`%c ${__NAME__} ${__VERSION__}`, "color: #98ff98; font-size: large");
LoggerFactory.getLogger().log(`%c For more details see ${__PACKAGE_URL__}`, "color: #98ff98;");

/**
* @param {string} targetId - The target div id to append the player.
Expand All @@ -46,10 +43,10 @@ export {Track, VideoTrack, AudioTrack, TextTrack};
export {Utils};

// Export version
export {VERSION};
export {__VERSION__ as VERSION};

// Export player name
export {PLAYER_NAME};
export {__NAME__ as PLAYER_NAME};

// Export environment data
export {Env};
Expand Down
15 changes: 14 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
const webpack = require("webpack");
const path = require("path");
const PROD = (process.env.NODE_ENV === 'production');
const packageData = require("./package.json");

let plugins = [
new webpack.DefinePlugin({
__VERSION__: JSON.stringify(packageData.version),
__NAME__: JSON.stringify(packageData.name),
__PACKAGE_URL__: JSON.stringify(packageData.repository.url)
})
];

if (PROD){
plugins.push(new webpack.optimize.UglifyJsPlugin({sourceMap: true}));
}

module.exports = {
context: __dirname + "/src",
Expand All @@ -16,7 +29,7 @@ module.exports = {
devtoolModuleFilenameTemplate: "webpack:///core/[resource-path]",
},
devtool: 'source-map',
plugins: PROD ? [new webpack.optimize.UglifyJsPlugin({sourceMap: true})] : [],
plugins: plugins,
module: {
rules: [{
test: /\.js$/,
Expand Down
146 changes: 104 additions & 42 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ acorn@^3.0.4:
version "3.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a"

acorn@^4.0.3, acorn@^4.0.4:
acorn@^4.0.3:
version "4.0.11"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.11.tgz#edcda3bd937e7556410d42ed5860f67399c794c0"

acorn@^5.0.0:
version "5.1.2"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.1.2.tgz#911cb53e036807cf0fa778dc5d370fbd864246d7"

acorn@^5.0.1:
version "5.0.3"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.0.3.tgz#c460df08491463f028ccb82eab3730bf01087b3d"
Expand All @@ -48,10 +52,14 @@ [email protected]:
version "0.8.2"
resolved "https://registry.yarnpkg.com/after/-/after-0.8.2.tgz#fedb394f9f0e02aa9768e702bda23b505fae7e1f"

ajv-keywords@^1.0.0, ajv-keywords@^1.1.1:
ajv-keywords@^1.0.0:
version "1.5.1"
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-1.5.1.tgz#314dd0a4b3368fad3dfcdc54ede6171b886daf3c"

ajv-keywords@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-2.1.0.tgz#a296e17f7bfae7c1ce4f7e0de53d29cb32162df0"

ajv@^4.7.0, ajv@^4.9.1:
version "4.11.6"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-4.11.6.tgz#947e93049790942b2a2d60a8289b28924d39f987"
Expand All @@ -68,6 +76,15 @@ ajv@^5.0.0:
json-schema-traverse "^0.3.0"
json-stable-stringify "^1.0.1"

ajv@^5.1.5:
version "5.2.2"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.2.2.tgz#47c68d69e86f5d953103b0074a9430dc63da5e39"
dependencies:
co "^4.6.0"
fast-deep-equal "^1.0.0"
json-schema-traverse "^0.3.0"
json-stable-stringify "^1.0.1"

align-text@^0.1.1, align-text@^0.1.3:
version "0.1.4"
resolved "https://registry.yarnpkg.com/align-text/-/align-text-0.1.4.tgz#0cd90a561093f35d0a99256c22b7069433fad117"
Expand Down Expand Up @@ -1001,7 +1018,7 @@ chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3:
strip-ansi "^3.0.0"
supports-color "^2.0.0"

chokidar@^1.4.1, chokidar@^1.4.3, chokidar@^1.6.0, chokidar@^1.6.1:
chokidar@^1.4.1, chokidar@^1.6.0, chokidar@^1.6.1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.6.1.tgz#2f4447ab5e96e50fb3d789fd90d4c72e0e4c70c2"
dependencies:
Expand All @@ -1016,6 +1033,21 @@ chokidar@^1.4.1, chokidar@^1.4.3, chokidar@^1.6.0, chokidar@^1.6.1:
optionalDependencies:
fsevents "^1.0.0"

chokidar@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468"
dependencies:
anymatch "^1.3.0"
async-each "^1.0.0"
glob-parent "^2.0.0"
inherits "^2.0.1"
is-binary-path "^1.0.0"
is-glob "^2.0.0"
path-is-absolute "^1.0.0"
readdirp "^2.0.0"
optionalDependencies:
fsevents "^1.0.0"

cipher-base@^1.0.0, cipher-base@^1.0.1:
version "1.0.3"
resolved "https://registry.yarnpkg.com/cipher-base/-/cipher-base-1.0.3.tgz#eeabf194419ce900da3018c207d212f2a6df0a07"
Expand Down Expand Up @@ -1783,14 +1815,14 @@ [email protected]:
engine.io-parser "1.3.2"
ws "1.1.2"

enhanced-resolve@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.1.0.tgz#9f4b626f577245edcf4b2ad83d86e17f4f421dec"
enhanced-resolve@^3.4.0:
version "3.4.1"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.4.1.tgz#0421e339fd71419b3da13d129b3979040230476e"
dependencies:
graceful-fs "^4.1.2"
memory-fs "^0.4.0"
object-assign "^4.0.1"
tapable "^0.2.5"
tapable "^0.2.7"

ent@~2.2.0:
version "2.2.0"
Expand Down Expand Up @@ -2150,6 +2182,10 @@ fast-deep-equal@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-0.1.0.tgz#5c6f4599aba6b333ee3342e2ed978672f1001f8d"

fast-deep-equal@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz#96256a3bc975595eb36d82e9929d060d893439ff"

fast-levenshtein@~2.0.4:
version "2.0.6"
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"
Expand Down Expand Up @@ -3046,7 +3082,7 @@ [email protected], json3@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/json3/-/json3-3.3.2.tgz#3c0434743df93e2f5c42aee7b19bcb483575f4e1"

json5@^0.5.0:
json5@^0.5.0, json5@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"

Expand Down Expand Up @@ -3228,7 +3264,7 @@ loader-utils@^0.2.16, loader-utils@^0.2.5:
json5 "^0.5.0"
object-assign "^4.0.1"

loader-utils@^1.0.2:
loader-utils@^1.0.2, loader-utils@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.1.0.tgz#c98aef488bcceda2ffb5e2de646d6a754429f5cd"
dependencies:
Expand Down Expand Up @@ -4199,12 +4235,6 @@ postcss@^6.0.1:
source-map "^0.5.6"
supports-color "^4.0.0"

pre-push@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/pre-push/-/pre-push-0.1.1.tgz#2a2a79827d243a76c91089897ac707f45e716aac"
dependencies:
shelljs "0.3.x"

prelude-ls@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
Expand Down Expand Up @@ -4691,10 +4721,6 @@ shebang-regex@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"

[email protected]:
version "0.3.0"
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.3.0.tgz#3596e6307a781544f591f37da618360f31db57b1"

shelljs@^0.7.5:
version "0.7.7"
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.7.tgz#b2f5c77ef97148f4b4f6e22682e10bba8667cff1"
Expand Down Expand Up @@ -4814,6 +4840,10 @@ source-list-map@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-1.1.1.tgz#1a33ac210ca144d1e561f906ebccab5669ff4cb4"

source-list-map@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.0.tgz#aaa47403f7b245a92fbc97ea08f250d6087ed085"

source-map-support@^0.4.2:
version "0.4.14"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.14.tgz#9d4463772598b86271b4f523f6c1f4e02a7d6aef"
Expand Down Expand Up @@ -5032,6 +5062,12 @@ supports-color@^4.0.0:
dependencies:
has-flag "^2.0.0"

supports-color@^4.2.1:
version "4.4.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.4.0.tgz#883f7ddabc165142b2a61427f3352ded195d1a3e"
dependencies:
has-flag "^2.0.0"

svgo@^0.7.0:
version "0.7.2"
resolved "https://registry.yarnpkg.com/svgo/-/svgo-0.7.2.tgz#9f5772413952135c6fefbf40afe6a4faa88b4bb5"
Expand All @@ -5055,9 +5091,9 @@ table@^3.7.8:
slice-ansi "0.0.4"
string-width "^2.0.0"

tapable@^0.2.5, tapable@~0.2.5:
version "0.2.6"
resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.6.tgz#206be8e188860b514425375e6f1ae89bfb01fd8d"
tapable@^0.2.7:
version "0.2.8"
resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.8.tgz#99372a5c999bf2df160afc0d74bed4f47948cd22"

tar-pack@^3.4.0:
version "3.4.0"
Expand Down Expand Up @@ -5206,7 +5242,7 @@ ua-parser-js@^0.7.13:
version "0.7.13"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.13.tgz#cd9dd2f86493b3f44dbeeef3780fda74c5ee14be"

uglify-js@^2.6, uglify-js@^2.8.5:
uglify-js@^2.6:
version "2.8.22"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.22.tgz#d54934778a8da14903fa29a326fb24c0ab51a1a0"
dependencies:
Expand All @@ -5215,6 +5251,15 @@ uglify-js@^2.6, uglify-js@^2.8.5:
optionalDependencies:
uglify-to-browserify "~1.0.0"

uglify-js@^2.8.29:
version "2.8.29"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.29.tgz#29c5733148057bb4e1f75df35b7a9cb72e6a59dd"
dependencies:
source-map "~0.5.1"
yargs "~3.10.0"
optionalDependencies:
uglify-to-browserify "~1.0.0"

uglify-to-browserify@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz#6e0924d6bda6b5afe349e39a6d632850a0f882b7"
Expand All @@ -5226,6 +5271,14 @@ uglifyjs-webpack-plugin@^0.4.3:
source-map "^0.5.6"
webpack-sources "^0.2.3"

uglifyjs-webpack-plugin@^0.4.6:
version "0.4.6"
resolved "https://registry.yarnpkg.com/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-0.4.6.tgz#b951f4abb6bd617e66f63eb891498e391763e309"
dependencies:
source-map "^0.5.6"
uglify-js "^2.8.29"
webpack-sources "^1.0.1"

uid-number@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/uid-number/-/uid-number-0.0.6.tgz#0ea10e8035e8eb5b8e4449f06da1c730663baa81"
Expand Down Expand Up @@ -5349,12 +5402,12 @@ void-elements@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-2.0.1.tgz#c066afb582bb1cb4128d60ea92392e94d5e9dbec"

watchpack@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.3.1.tgz#7d8693907b28ce6013e7f3610aa2a1acf07dad87"
watchpack@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.4.0.tgz#4a1472bcbb952bd0a9bb4036801f954dfb39faac"
dependencies:
async "^2.1.2"
chokidar "^1.4.3"
chokidar "^1.7.0"
graceful-fs "^4.1.2"

wbuf@^1.1.0, wbuf@^1.4.0:
Expand Down Expand Up @@ -5401,30 +5454,39 @@ webpack-sources@^0.2.3:
source-list-map "^1.1.1"
source-map "~0.5.3"

webpack@latest:
version "2.3.3"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-2.3.3.tgz#eecc083c18fb7bf958ea4f40b57a6640c5a0cc78"
webpack-sources@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.0.1.tgz#c7356436a4d13123be2e2426a05d1dad9cbe65cf"
dependencies:
acorn "^4.0.4"
source-list-map "^2.0.0"
source-map "~0.5.3"

webpack@^3.6.0:
version "3.6.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-3.6.0.tgz#a89a929fbee205d35a4fa2cc487be9cbec8898bc"
dependencies:
acorn "^5.0.0"
acorn-dynamic-import "^2.0.0"
ajv "^4.7.0"
ajv-keywords "^1.1.1"
ajv "^5.1.5"
ajv-keywords "^2.0.0"
async "^2.1.2"
enhanced-resolve "^3.0.0"
enhanced-resolve "^3.4.0"
escope "^3.6.0"
interpret "^1.0.0"
json-loader "^0.5.4"
json5 "^0.5.1"
loader-runner "^2.3.0"
loader-utils "^0.2.16"
loader-utils "^1.1.0"
memory-fs "~0.4.1"
mkdirp "~0.5.0"
node-libs-browser "^2.0.0"
source-map "^0.5.3"
supports-color "^3.1.0"
tapable "~0.2.5"
uglify-js "^2.8.5"
watchpack "^1.3.1"
webpack-sources "^0.2.3"
yargs "^6.0.0"
supports-color "^4.2.1"
tapable "^0.2.7"
uglifyjs-webpack-plugin "^0.4.6"
watchpack "^1.4.0"
webpack-sources "^1.0.1"
yargs "^8.0.2"

websocket-driver@>=0.5.1:
version "0.6.5"
Expand Down Expand Up @@ -5550,7 +5612,7 @@ yargs@^6.0.0:
y18n "^3.2.1"
yargs-parser "^4.2.0"

yargs@^8.0.1:
yargs@^8.0.1, yargs@^8.0.2:
version "8.0.2"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-8.0.2.tgz#6299a9055b1cefc969ff7e79c1d918dceb22c360"
dependencies:
Expand Down

0 comments on commit c2eb85f

Please sign in to comment.