forked from canalplus/rx-player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
166 lines (144 loc) · 5.35 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
/* eslint-env node */
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const TerserPlugin = require("terser-webpack-plugin");
const webpack = require("webpack");
const RXP_ENV = process.env.RXP_ENV || "production";
const shouldMinify = !!process.env.RXP_MINIFY;
const shouldReportSize = process.env.RXP_SIZE_REPORT === "true";
const isBarebone = process.env.RXP_BAREBONE === "true";
if (["development", "production"].indexOf(RXP_ENV) < 0) {
throw new Error("unknown RXP_ENV " + RXP_ENV);
}
const isDevMode = RXP_ENV === "development";
const plugins = [
new webpack.DefinePlugin({
"__FEATURES__": {
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",
},
// Path relative to src/features where optional features are implemented
__RELATIVE_PATH__: {
EME_MANAGER: JSON.stringify("../core/eme/index.ts"),
IMAGE_BUFFER: JSON.stringify("../custom_source_buffers/image/index.ts"),
BIF_PARSER: JSON.stringify("../parsers/images/bif.ts"),
SMOOTH: JSON.stringify("../transports/smooth/index.ts"),
DASH: JSON.stringify("../transports/dash/index.ts"),
LOCAL_MANIFEST: JSON.stringify("../transports/local/index.ts"),
METAPLAYLIST: JSON.stringify("../transports/metaplaylist/index.ts"),
NATIVE_TEXT_BUFFER: JSON.stringify("../custom_source_buffers/text/native/index.ts"),
NATIVE_VTT: JSON.stringify("../parsers/texttracks/webvtt/native/index.ts"),
NATIVE_SRT: JSON.stringify("../parsers/texttracks/srt/native.ts"),
NATIVE_TTML: JSON.stringify("../parsers/texttracks/ttml/native/index.ts"),
NATIVE_SAMI: JSON.stringify("../parsers/texttracks/sami/native.ts"),
HTML_TEXT_BUFFER: JSON.stringify("../custom_source_buffers/text/html/index.ts"),
HTML_VTT: JSON.stringify("../parsers/texttracks/webvtt/html/index.ts"),
HTML_SRT: JSON.stringify("../parsers/texttracks/srt/html.ts"),
HTML_TTML: JSON.stringify("../parsers/texttracks/ttml/html/index.ts"),
HTML_SAMI: JSON.stringify("../parsers/texttracks/sami/html.ts"),
DIRECTFILE: JSON.stringify("../core/init/initialize_directfile.ts"),
MEDIA_ELEMENT_TRACK_CHOICE_MANAGER: JSON.stringify("../core/api/media_element_track_choice_manager.ts"),
},
__DEV__: isDevMode,
__LOGGER_LEVEL__: isDevMode ? "\"INFO\"" : "\"DEBUG\"",
"process.env": {
NODE_ENV: JSON.stringify(isDevMode ? "development" : "production"),
},
}),
];
if (shouldReportSize) {
plugins.push(new BundleAnalyzerPlugin());
}
module.exports = {
mode: isDevMode ? "development" : "production",
entry: "./src/index.ts",
output: {
library: "RxPlayer",
libraryTarget: "umd",
libraryExport: "default",
filename: shouldMinify ? "rx-player.min.js" : "rx-player.js",
},
optimization: {
minimize: shouldMinify,
minimizer: shouldMinify ? [new TerserPlugin()] : [],
},
performance: {
maxEntrypointSize: shouldMinify ? 450000 : 2000000,
maxAssetSize: shouldMinify ? 450000 : 2000000,
},
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,
node: {
console: false,
global: true,
process: false,
Buffer: false,
__filename: false,
__dirname: false,
setImmediate: false,
},
watchOptions: {
ignored: /node_modules/,
},
};