-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathwebpack.config.js
More file actions
executable file
·283 lines (263 loc) · 7.47 KB
/
webpack.config.js
File metadata and controls
executable file
·283 lines (263 loc) · 7.47 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
const webpack = require("webpack");
const path = require("path");
const fileSystem = require("fs-extra");
const env = require("./utils/env");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const isDev = env.NODE_ENV === "development";
const ASSET_PATH = process.env.ASSET_PATH || "/";
require("dotenv").config();
// Entry points for the different pages
const entryPoints = {
background: path.join(__dirname, "src", "pages", "Background", "index.js"),
contentScript: path.join(__dirname, "src", "pages", "Content", "index.jsx"),
recorder: path.join(__dirname, "src", "pages", "Recorder", "index.jsx"),
cloudrecorder: path.join(
__dirname,
"src",
"pages",
"CloudRecorder",
"index.jsx"
),
recorderoffscreen: path.join(
__dirname,
"src",
"pages",
"RecorderOffscreen",
"index.jsx"
),
audiooffscreen: path.join(
__dirname,
"src",
"pages",
"AudioOffscreen",
"index.js"
),
camera: path.join(__dirname, "src", "pages", "Camera", "index.jsx"),
waveform: path.join(__dirname, "src", "pages", "Waveform", "index.jsx"),
sandbox: path.join(__dirname, "src", "pages", "Sandbox", "index.jsx"),
permissions: path.join(__dirname, "src", "pages", "Permissions", "index.jsx"),
setup: path.join(__dirname, "src", "pages", "Setup", "index.jsx"),
playground: path.join(__dirname, "src", "pages", "Playground", "index.jsx"),
editor: path.join(__dirname, "src", "pages", "Editor", "index.jsx"),
region: path.join(__dirname, "src", "pages", "Region", "index.jsx"),
download: path.join(__dirname, "src", "pages", "Download", "index.jsx"),
editorwebcodecs: path.join(
__dirname,
"src",
"pages",
"EditorWebCodecs",
"index.jsx"
),
editorviewer: path.join(
__dirname,
"src",
"pages",
"EditorViewer",
"index.jsx"
),
backup: path.join(__dirname, "src", "pages", "Backup", "index.jsx"),
};
const htmlPlugins = Object.keys(entryPoints)
.map((entryName) => {
// Skip background script as it doesn't need an HTML file
if (entryName === "background" || entryName === "contentScript") {
return null;
}
// Map entry names to folder names (for multi-word entries)
const folderNameMap = {
cloudrecorder: "CloudRecorder",
recorderoffscreen: "RecorderOffscreen",
audiooffscreen: "AudioOffscreen",
editorwebcodecs: "EditorWebCodecs",
editorviewer: "EditorViewer",
};
const folderName =
folderNameMap[entryName] ||
entryName.charAt(0).toUpperCase() + entryName.slice(1);
const templatePath = path.join(
__dirname,
"src",
"pages",
folderName,
"index.html"
);
const options = {
template: templatePath,
filename: `${entryName}.html`,
chunks: [entryName],
cache: true,
};
// Add favicon only for backup page
if (entryName === "backup") {
options.favicon = path.join(
__dirname,
"src",
"assets",
"backup-favicon.ico"
);
} else {
options.favicon = path.join(__dirname, "src", "assets", "favicon.png");
}
return new HtmlWebpackPlugin(options);
})
.filter(Boolean); // Filter out null values
const fileExtensions = [
"jpg",
"jpeg",
"png",
"gif",
"eot",
"otf",
"svg",
"ttf",
"woff",
"woff2",
];
const secretsPath = path.join(__dirname, `secrets.${env.NODE_ENV}.js`);
const alias = { "react-dom": "@hot-loader/react-dom" };
if (fileSystem.existsSync(secretsPath)) {
alias["secrets"] = secretsPath;
}
const config = {
mode: process.env.NODE_ENV || "production",
performance: { hints: false },
entry: entryPoints,
// Persistent filesystem cache for fast rebuilds
cache: {
type: "filesystem",
buildDependencies: {
config: [__filename],
},
},
output: {
filename: "[name].bundle.js",
path: path.resolve(__dirname, "build"),
clean: !isDev, // Only wipe build dir in production; dev keeps it to avoid re-copying 40MB of assets
publicPath: ASSET_PATH,
},
module: {
rules: [
{
test: /\.(css|scss)$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" },
{
loader: "sass-loader",
options: { sourceMap: true },
},
],
},
{
test: new RegExp(`.(${fileExtensions.join("|")})$`),
type: "asset/resource",
exclude: /node_modules/,
},
{
test: /\.html$/,
loader: "html-loader",
exclude: /node_modules/,
},
{
test: /\.(ts|tsx)$/,
loader: "ts-loader",
exclude: /node_modules/,
options: {
transpileOnly: isDev,
},
},
{
test: /\.(js|jsx)$/,
use: isDev
? [{ loader: "babel-loader" }]
: [{ loader: "source-map-loader" }, { loader: "babel-loader" }],
exclude: /node_modules/,
},
],
},
resolve: {
alias: {
react: path.resolve("./node_modules/react"),
"react-dom": path.resolve("./node_modules/react-dom"),
"react/jsx-runtime": path.resolve("./node_modules/react/jsx-runtime"),
},
// Code extensions first — image/font extensions are only needed for explicit imports with extensions
extensions: [".js", ".jsx", ".ts", ".tsx", ".css"],
},
plugins: [
new webpack.ProgressPlugin(),
new webpack.DefinePlugin({
"process.env.SCREENITY_APP_BASE": JSON.stringify(
process.env.SCREENITY_APP_BASE
),
"process.env.SCREENITY_WEBSITE_BASE": JSON.stringify(
process.env.SCREENITY_WEBSITE_BASE
),
"process.env.SCREENITY_API_BASE_URL": JSON.stringify(
process.env.SCREENITY_API_BASE_URL
),
"process.env.SCREENITY_ENABLE_CLOUD_FEATURES": JSON.stringify(
process.env.SCREENITY_ENABLE_CLOUD_FEATURES
),
"process.env.MAX_RECORDING_DURATION": JSON.stringify(
process.env.MAX_RECORDING_DURATION || 3600 // Default to 1 hour
),
"process.env.RECORDING_WARNING_THRESHOLD": JSON.stringify(
process.env.RECORDING_WARNING_THRESHOLD || 60 // Default to 1 minute
),
"process.env.SCREENITY_DEV_MODE": JSON.stringify(
process.env.SCREENITY_DEV_MODE || ""
),
}),
// Copy manifest and transform with package info
new CopyWebpackPlugin({
patterns: [
{
from: "src/manifest.json",
to: path.join(__dirname, "build"),
force: true,
transform: (content) => {
return Buffer.from(
JSON.stringify({
description: process.env.npm_package_description,
version: process.env.npm_package_version,
...JSON.parse(content.toString()),
})
);
},
},
{
from: "src/schema.json",
to: path.join(__dirname, "build/schema.json"),
force: true,
},
{
from: "src/assets/",
to: path.join(__dirname, "build/assets"),
force: true,
},
{
from: "src/_locales/",
to: path.join(__dirname, "build/_locales"),
force: true,
},
],
}),
...htmlPlugins,
],
};
if (isDev) {
config.devtool = "cheap-module-source-map";
} else {
config.optimization = {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
}),
],
};
}
module.exports = config;