forked from canalplus/rx-player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
168 lines (147 loc) · 5.18 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* eslint-env node */
/**
* This file exports a configuration used to generate our "legacy" builds in
* dist/rx-player.js and dist/rx-player.min (depending on if the minify option
* is set) by using Webpack.
*
* Note that we do not rely at all on this configuration when the usually
* preferred "Minimal" version of the player is imported.
*/
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const TerserPlugin = require("terser-webpack-plugin");
const webpack = require("webpack");
/**
* Generate the Webpack config used to generate the RxPlayer's legacy builds.
* @param {Object} env - Arguments. When Webpack is called through the CLI,
* those are created implicitely based on flags.
* @param {boolean} [options.minify] - If `true`, the output will be minified.
* @param {boolean} [options.production] - If `true`, the code will be compiled
* in "production" mode, which contains between other things less runtime
* assertions.
* @param {boolean} [options.shouldReportSize] - If `true`, a bunle size report
* will be generated after the build.
* @returns {Object} - The Webpack configuration
*/
module.exports = (env) => {
const isDevMode = !env.production;
const shouldMinify = !!env.minify;
const shouldReportSize = !!env.reportSize;
const isBarebone = process.env.RXP_BAREBONE === "true";
const plugins = [
new webpack.DefinePlugin({
"__FEATURES__": {
IS_DISABLED: +(false), // === 0 (wrote this way to be explicit)
IS_ENABLED: +(true), // === 1 (wrote this way to be explicit)
// Each following feature is compared to IS_ENABLED or IS_DISABLED in
// code to check whether the feature is enabled or not.
SMOOTH: +(isBarebone ?
process.env.RXP_SMOOTH === "true" :
process.env.RXP_SMOOTH !== "false"),
DASH: +(isBarebone ?
process.env.RXP_DASH === "true" :
process.env.RXP_DASH !== "false"),
LOCAL_MANIFEST: +(process.env.RXP_LOCAL_MANIFEST === "true"),
METAPLAYLIST: +(process.env.RXP_METAPLAYLIST === "true"),
DIRECTFILE: +(isBarebone ?
process.env.RXP_DIRECTFILE === "true" :
process.env.RXP_DIRECTFILE !== "false"),
NATIVE_TTML: +(isBarebone ?
process.env.RXP_NATIVE_TTML === "true" :
process.env.RXP_NATIVE_TTML !== "false"),
NATIVE_SAMI: +(isBarebone ?
process.env.RXP_NATIVE_SAMI === "true" :
process.env.RXP_NATIVE_SAMI !== "false"),
NATIVE_VTT: +(isBarebone ?
process.env.RXP_NATIVE_VTT === "true" :
process.env.RXP_NATIVE_VTT !== "false"),
NATIVE_SRT: +(isBarebone ?
process.env.RXP_NATIVE_SRT === "true" :
process.env.RXP_NATIVE_SRT !== "false"),
HTML_TTML: +(isBarebone ?
process.env.RXP_HTML_TTML === "true" :
process.env.RXP_HTML_TTML !== "false"),
HTML_SAMI: +(isBarebone ?
process.env.RXP_HTML_SAMI === "true" :
process.env.RXP_HTML_SAMI !== "false"),
HTML_VTT: +(isBarebone ?
process.env.RXP_HTML_VTT === "true" :
process.env.RXP_HTML_VTT !== "false"),
HTML_SRT: +(isBarebone ?
process.env.RXP_HTML_SRT === "true" :
process.env.RXP_HTML_SRT !== "false"),
EME: +(isBarebone ?
process.env.RXP_EME === "true" :
process.env.RXP_EME !== "false"),
BIF_PARSER: +(isBarebone ?
process.env.RXP_BIF_PARSER === "true" :
process.env.RXP_BIF_PARSER !== "false"),
},
__ENVIRONMENT__: {
PRODUCTION: 0,
DEV: 1,
CURRENT_ENV: isDevMode ? 1 : 0,
},
__LOGGER_LEVEL__: {
CURRENT_LEVEL: isDevMode ? "\"INFO\"" : "\"ERROR\"",
},
}),
];
if (shouldReportSize) {
plugins.push(new BundleAnalyzerPlugin());
}
return {
mode: isDevMode ? "development" : "production",
entry: "./src/index.ts",
output: {
library: "RxPlayer",
libraryTarget: "umd",
libraryExport: "default",
filename: shouldMinify ? "rx-player.min.js" : "rx-player.js",
environment: {
arrowFunction: false,
bigIntLiteral: false,
const: false,
destructuring: false,
dynamicImport: false,
forOf: false,
module: false,
},
},
optimization: {
minimize: shouldMinify,
minimizer: shouldMinify ? [new TerserPlugin()] : [],
},
performance: {
maxEntrypointSize: shouldMinify ? 540000 : 2500000,
maxAssetSize: shouldMinify ? 540000 : 2500000,
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx", ".json"],
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
options: {
cacheDirectory: true,
presets: [
[ "@babel/env", { loose: true, modules: false } ],
],
plugins: [[ "@babel/plugin-transform-runtime" ]],
},
},
{ loader: "ts-loader" },
],
},
],
},
plugins,
watchOptions: {
ignored: /node_modules/,
},
};
};