Skip to content

Commit

Permalink
allow building demo asset seperately
Browse files Browse the repository at this point in the history
  • Loading branch information
tchakabam committed Dec 23, 2017
1 parent 0d4513c commit f4b10d7
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ const webpack = require('webpack');

const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;

const clone = (...args) => Object.assign({}, ...args);

// Allow to customise light dists through env-vars.
const env = process.env;
const addSubtitleSupport = (typeof env.SUBTITLE !== 'undefined' && env.SUBTITLE);
const addAltAudioSupport = (typeof env.ALT_AUDIO !== 'undefined' && env.ALT_AUDIO);

const uglifyJsOptions = {
screwIE8: true,
stats: true,
Expand All @@ -16,7 +23,7 @@ const uglifyJsOptions = {
}
};

const commonConfig = {
const baseConfig = {
entry: './src/hls.js',
module: {
rules: [
Expand All @@ -33,10 +40,22 @@ const commonConfig = {
}
};

// Allow to customise light dists through env-vars.
const env = process.env;
const addSubtitleSupport = (typeof env.SUBTITLE !== 'undefined' && env.SUBTITLE);
const addAltAudioSupport = (typeof env.ALT_AUDIO !== 'undefined' && env.ALT_AUDIO);
const demoConfig = clone(baseConfig, {
name: 'demo',
entry: './demo/index',
output: {
filename: 'hls-demo.js',
chunkFilename: '[name].js',
sourceMapFilename: 'hls-demo.js.map',
path: path.resolve(__dirname, 'dist'),
publicPath: '/dist/',
library: 'HlsDemo',
libraryTarget: 'umd',
libraryExport: 'default'
},
plugins: [],
devtool: 'source-map'
});

function getPluginsForConfig(type, minify = false) {
// common plugins.
Expand Down Expand Up @@ -82,7 +101,7 @@ function getAliasesForLightDist() {
let aliases = {};

if (!addSubtitleSupport) {
aliases = Object.assign({}, aliases, {
aliases = clone(aliases, {
'./utils/cues': './empty.js',
'./controller/timeline-controller': './empty.js',
'./controller/subtitle-track-controller': './empty.js',
Expand All @@ -91,7 +110,7 @@ function getAliasesForLightDist() {
}

if (!addAltAudioSupport) {
aliases = Object.assign({}, aliases, {
aliases = clone(aliases, {
'./controller/audio-track-controller': './empty.js',
'./controller/audio-stream-controller': './empty.js'
});
Expand Down Expand Up @@ -163,7 +182,9 @@ const multiConfig = [
},
plugins: getPluginsForConfig('light', true)
}
].map(fragment => Object.assign({}, commonConfig, fragment));
].map(config => clone(baseConfig, config));

multiConfig.push(demoConfig);

// webpack matches the --env arguments to a string; for example, --env.debug.min translates to { debug: true, min: true }
module.exports = (envArgs) => {
Expand All @@ -174,12 +195,12 @@ module.exports = (envArgs) => {

// Find the first enabled config within the arguments array
const enabledConfigName = Object.keys(envArgs).find(envName => envArgs[envName]);
let enabledConfig = multiConfig.find(config => config.name === enabledConfigName);

// Filter out config with name
const enabledConfig = multiConfig.find(config => config.name === enabledConfigName);
if (!enabledConfig) {
console.error(`Couldn't find a valid config with the name "${enabledConfigName}". Known configs are: ${multiConfig.map(config => config.name).join(', ')}`);
return;
}

return enabledConfig;
return [enabledConfig, demoConfig];
};

0 comments on commit f4b10d7

Please sign in to comment.