Skip to content

Commit

Permalink
Bundle the library with Webpack 2.2
Browse files Browse the repository at this point in the history
- Use webpack to bundle hls.js with the exact same config
- Use webpack-dev-server to run the demo-page
- Use webpack's publicPath in demo/index.html
- Add __VERSION__ as global in .jshintrc
- Replace __VERSION__ at bundling
- Remove useless devDependencies
- Remove private attr
- Move url-toolkit in dependencies
  • Loading branch information
dighan authored and mangui committed Jul 18, 2017
1 parent 6a60fee commit e0cff86
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"fetch" : true,
"Request" : true,
"Headers" : true,
"escape" : true
"escape" : true,
"__VERSION__" : true
}
}
5 changes: 2 additions & 3 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,8 @@ <h4> Stats Display </h4>
<br><br>

<script src="../../streams.js"></script>
<!-- live-reload script -->
<script src="//localhost:35729/livereload.js?snipver=1"></script>
<script src="../dist/hls.js"></script>
<script src="//localhost:8001"></script>
<script src="/assets/hls.js"></script>
<script src="canvas.js"></script>
<script src="metrics.js"></script>
<script src="jsonpack.js"></script>
Expand Down
46 changes: 15 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,55 +25,39 @@
]
},
"scripts": {
"build": "npm run buildlib && rimraf dist/* && npm run builddist && npm run builddistlight",
"buildlib": "rimraf lib/* && babel src --out-dir lib",
"builddistlight": "browserify -t [browserify-conditionalify --definitions [--subtitle 0 --altaudio 0 ] ] -t browserify-versionify -t [babelify] -p browserify-derequire -p bundle-collapser/plugin -s Hls src/index.js --debug | exorcist dist/hls.light.js.map -b . > dist/hls.light.js && npm run minifylight && node scripts/foldersize.js dist",
"builddist": "browserify -t browserify-versionify -t [babelify] -p browserify-derequire -p bundle-collapser/plugin -s Hls src/index.js --debug | exorcist dist/hls.js.map -b . > dist/hls.js && npm run minify && node scripts/foldersize.js dist",
"build": "cross-env NODE_ENV=production webpack --progress --output-filename hls.min.js && node scripts/foldersize.js dist",
"preparerelease": "npm run build && npm run test && git add dist/* && git commit -m 'update dist'",
"prerelease": "mversion prerelease && npm run preparerelease",
"patch": "mversion p && npm run preparerelease",
"minor": "mversion mi && npm run preparerelease",
"major": "mversion ma && npm run preparerelease",
"minify": "uglifyjs dist/hls.js -c sequences=true,dead_code=true,conditionals=true,booleans=true,unused=true,if_return=true,join_vars=true,drop_console=true -m --screw-ie8 > dist/hls.min.js",
"minifylight": "uglifyjs dist/hls.light.js -c sequences=true,dead_code=true,conditionals=true,booleans=true,unused=true,if_return=true,join_vars=true,drop_console=true -m --screw-ie8 > dist/hls.light.min.js",
"watch": "watchify --debug -s Hls src/index.js -t [babelify] -o dist/hls.js",
"pretest": "npm run lint",
"test": "mocha --compilers js:babel-register --recursive tests/unit",
"testfunc": "mocha --compilers js:babel-register tests/functional/auto/hlsjs.js --timeout 80000",
"lint": "jshint src/",
"serve": "http-server -p 8000 .",
"open": "opener http://localhost:8000/demo/",
"live-reload": "livereload dist/",
"dev": "npm run builddist && (npm run open -s & parallelshell 'npm run live-reload -s' 'npm run serve -s' 'npm run watch -s')",
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --output-filename hls.js --devtool source-map",
"coverage": "nyc mocha --compilers js:babel-register --recursive tests/unit"
},
"dependencies": {
"url-toolkit": "^2.0.1"
},
"devDependencies": {
"arraybuffer-equal": "^1.0.4",
"babel-cli": "^6.23.0",
"babel-preset-es2015": "^6.18.0",
"babel-register": "^6.24.0",
"babelify": "^7.2.0",
"browserify": "^14.1.0",
"browserify-conditionalify": "^1.0.0",
"browserify-derequire": "^0.9.4",
"browserify-versionify": "^1.0.6",
"bundle-collapser": "^1.2.1",
"chromedriver": "^2.28.0",
"babel-loader": "^6.2.10",
"babel-register": "^6.18.0",
"chromedriver": "^2.27.1",
"cross-env": "^3.1.4",
"deep-strict-equal": "^0.2.0",
"exorcist": "^0.4.0",
"http-server": "^0.10.0",
"nyc": "^11.0.2",
"http-server": "^0.9.0",
"jshint": "^2.9.4",
"livereload": "^0.6.2",
"mocha": "^3.0.2",
"mversion": "^1.10.1",
"nyc": "^11.0.2",
"opener": "^1.4.0",
"parallelshell": "^3.0.1",
"rimraf": "^2.6.1",
"selenium-webdriver": "^3.1.0",
"uglify-js": "^3.0.23",
"url-toolkit": "^2.0.1",
"watchify": "^3.7.0",
"webworkify": "^1.4.0"
"selenium-webdriver": "^2.52.0",
"webpack": "^2.2.0",
"webpack-dev-server": "^2.2.0",
"webworkify-webpack": "^2.0.0"
}
}
5 changes: 2 additions & 3 deletions src/demux/demuxer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Event from '../events';
import DemuxerInline from '../demux/demuxer-inline';
import DemuxerWorker from '../demux/demuxer-worker';
import {logger} from '../utils/logger';
import {ErrorTypes, ErrorDetails} from '../errors';
import EventEmitter from 'events';
import work from 'webworkify-webpack';

class Demuxer {

Expand Down Expand Up @@ -50,8 +50,7 @@ class Demuxer {
logger.log('demuxing in webworker');
let w;
try {
let work = require('webworkify');
w = this.w = work(DemuxerWorker);
w = this.w = work(require.resolve('../demux/demuxer-worker.js'));
this.onwmsg = this.onWorkerMessage.bind(this);
w.addEventListener('message', this.onwmsg);
w.onerror = function(event) { hls.trigger(Event.ERROR, {type: ErrorTypes.OTHER_ERROR, details: ErrorDetails.INTERNAL_EXCEPTION, fatal: true, event : 'demuxerWorker', err : { message : event.message + ' (' + event.filename + ':' + event.lineno + ')' }});};
Expand Down
3 changes: 1 addition & 2 deletions src/hls.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import {hlsDefaultConfig} from './config';
class Hls {

static get version() {
// replaced with browserify-versionify transform
return '__VERSION__';
return __VERSION__;
}

static isSupported() {
Expand Down
62 changes: 62 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var pkgJson = require('./package.json')
var path = require('path')
var webpack = require('webpack')

var env = process.env.NODE_ENV

var config = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: '/assets/',
library: 'Hls',
libraryTarget: 'umd'
},
devServer: {
compress: true,
contentBase: path.resolve(__dirname, 'demo')
},
module: {
rules: [{
test: /\.js$/,
exclude: [
path.resolve(__dirname, 'node_modules')
],
loader: 'babel-loader',
options: {
presets: ['es2015']
}
}]
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.DefinePlugin({
__VERSION__: JSON.stringify(pkgJson.version)
})
]
}

if (env === 'production') {
config.plugins.push(
new webpack.optimize.UglifyJsPlugin({
compressor: {
sequences: true,
dead_code: true,
conditionals: true,
booleans: true,
unused: true,
if_return: true,
join_vars: true,
drop_console: true
},
mangle: {
screw_ie8: true
},
output: {
screw_ie8: true
}
})
)
}

module.exports = config

0 comments on commit e0cff86

Please sign in to comment.