forked from video-dev/hls.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
145 lines (135 loc) · 3.74 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const pkgJson = require('./package.json');
const path = require('path');
const webpack = require('webpack');
const buildConstants = {
__VERSION__: JSON.stringify(pkgJson.version),
__BUILD_VERSION__: process.env.BUILD_VERSION || 'full'
};
const uglifyJsOptions = {
screwIE8: true,
stats: true,
compress: {
warnings: false
},
mangle: {
toplevel: true,
eval: true
}
};
const commonConfig = {
entry: './src/hls.js',
module: {
rules: [
{
test: /\.js$/,
exclude: [
path.resolve(__dirname, 'node_modules')
],
use: {
loader: 'babel-loader'
}
}
]
}
};
const commonPlugins = [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.DefinePlugin(buildConstants)
];
const distPlugins = commonPlugins.concat([
new webpack.optimize.UglifyJsPlugin(uglifyJsOptions),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
})
]);
const multiConfig = [
{
name: 'debug',
output: {
filename: 'hls.js',
chunkFilename: '[name].js',
sourceMapFilename: 'hls.js.map',
path: path.resolve(__dirname, 'dist'),
publicPath: '/hls.js/dist/',
library: 'Hls',
libraryTarget: 'umd'
},
plugins: commonPlugins,
devtool: 'source-map',
},
{
name: 'dist',
output: {
filename: 'hls.min.js',
chunkFilename: '[name].js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/hls.js/dist/',
library: 'Hls',
libraryTarget: 'umd'
},
plugins: distPlugins
},
{
name: 'light',
output: {
filename: 'hls.light.js',
chunkFilename: '[name].js',
sourceMapFilename: 'hls.light.js.map',
path: path.resolve(__dirname, 'dist'),
publicPath: '/hls.js/dist/',
library: 'Hls',
libraryTarget: 'umd'
},
resolve: {
alias: {
'./controller/audio-track-controller': './empty.js',
'./controller/audio-stream-controller': './empty.js',
'./utils/cues': './empty.js',
'./controller/timeline-controller': './empty.js',
'./controller/subtitle-track-controller': './empty.js',
'./controller/subtitle-stream-controller': './empty.js'
}
},
plugins: commonPlugins,
devtool: 'source-map'
},
{
name: 'light-dist',
output: {
filename: 'hls.light.min.js',
chunkFilename: '[name].js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/hls.js/dist/',
library: 'Hls',
libraryTarget: 'umd'
},
resolve: {
alias: {
'./controller/audio-track-controller': './empty.js',
'./controller/audio-stream-controller': './empty.js',
'./utils/cues': './empty.js',
'./controller/timeline-controller': './empty.js',
'./controller/subtitle-track-controller': './empty.js',
'./controller/subtitle-stream-controller': './empty.js'
}
},
plugins: distPlugins
}
].map(fragment => Object.assign({}, commonConfig, fragment));
// webpack matches the --env arguments to a string; for example, --env.debug.min translates to { debug: true, min: true }
module.exports = (envArgs) => {
if (!envArgs) {
// If no arguments are specified, return every configuration
return multiConfig;
}
// 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);
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;
};