forked from webrecorder/archiveweb.page
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
223 lines (195 loc) · 5.63 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
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
/*eslint-env node */
const path = require("path");
const webpack = require("webpack");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const GenerateJsonPlugin = require("generate-json-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const APP_FILE_SERVE_PREFIX = "http://files.archiveweb.page/";
const PACKAGE = require("./package.json");
const WARCIO_PACKAGE = require("./node_modules/warcio/package.json");
const IPFS_CORE_URL = "/ipfs-core.min.js";
const BANNER = "[name].js is part of the Webrecorder Extension (https://replayweb.page) Copyright (C) 2020-2021, Webrecorder Software. Licensed under the Affero General Public License v3.";
const manifest = require("./src/ext/manifest.json");
const defaultDefines = {
__AWP_VERSION__: JSON.stringify(PACKAGE.version),
__VERSION__: JSON.stringify(PACKAGE.version),
__WARCIO_VERSION__: JSON.stringify(WARCIO_PACKAGE.version),
__SW_NAME__: JSON.stringify("sw.js"),
__IPFS_CORE_URL__: JSON.stringify(""),
__IPFS_HTTP_CLIENT_URL__: JSON.stringify(""),
__APP_FILE_SERVE_PREFIX__ : JSON.stringify(APP_FILE_SERVE_PREFIX),
};
const moduleSettings = {
rules: [
{
test: /\.svg$/,
use: "svg-inline-loader"
},
{
test: /\.s(a|c)ss$/,
use: ["css-loader", "sass-loader"]
},
{
test: /(dist\/wombat.js|src\/wombatWorkers.js|behaviors.js|extractPDF.js|ruffle.js)$/i,
use: "raw-loader",
}
]
};
const fallback = {
"stream": require.resolve("stream-browserify"),
"querystring": require.resolve("querystring-es3"),
"url": require.resolve("url/")
};
const optimization = {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
}),
],
};
const electronMainConfig = (/*env, argv*/) => {
return {
target: "electron-main",
mode: "production",
entry: {
"electron": "./src/electron/electron-rec-main.js",
},
optimization,
resolve: {
alias: {
"abort-controller": "abort-controller/dist/abort-controller.js",
"dlv": "dlv/dist/dlv.js",
"bignumber.js": "bignumber.js/bignumber.js",
//"multiformats/hashes/sha2": "multiformats/cjs/src/hashes/sha2.js"
}
},
output: {
path: path.join(__dirname, "dist"),
filename: "[name].js"
},
node: {
__dirname: false,
__filename: false,
},
plugins: [
new webpack.DefinePlugin(defaultDefines),
new webpack.BannerPlugin(BANNER),
new CopyPlugin({
patterns: [
{ from: "wr-ext/replay/", to: "replay/" },
{ from: "wr-ext/ruffle/", to: "ruffle/" },
{ from: "wr-ext/pdf/", to: "pdf/" },
{ from: "node_modules/leveldown/prebuilds/", to: "prebuilds" },
{ from: "build/extra_prebuilds/", to: "prebuilds" },
],
}),
],
externals: {
"bufferutil": "bufferutil",
"utf-8-validate": "utf-8-validate",
},
module: moduleSettings,
};
};
const electronPreloadConfig = (/*env, argv*/) => {
return {
target: "electron-preload",
mode: "production",
entry: {
"preload": "./src/electron/electron-rec-preload.js",
},
optimization,
output: {
path: path.join(__dirname, "dist"),
filename: "[name].js"
},
plugins: [
new webpack.DefinePlugin(defaultDefines),
]
};
};
const electronRendererConfig = (/*env, argv*/) => {
return {
mode: "production",
target: "web",
entry: {
"rec-window": "./src/electron/rec-window.js",
},
optimization,
resolve: {fallback},
output: {
path: path.join(__dirname, "dist"),
filename: "[name].js",
libraryTarget: "global",
globalObject: "self"
},
plugins: [
new webpack.ProvidePlugin({
process: "process/browser.js",
Buffer: ["buffer", "Buffer"],
}),
new MiniCssExtractPlugin(),
new CopyPlugin({
patterns: [
{ from: "src/electron/rec-preload.js", to: "" },
{ from: "src/electron/rec-window.html", to: "" },
]
}),
new webpack.DefinePlugin(defaultDefines),
],
module: moduleSettings,
};
};
const extensionConfig = (env, argv) => {
const icon = (argv.mode === "production") ? "icon.png" : "icon-dev.png";
const generateManifest = (name, value) => {
switch (value) {
case "$VERSION":
return PACKAGE.version;
case "$ICON":
return icon;
}
return value;
};
return {
mode: "production",
target: "web",
entry: {
"bg": "./src/ext/bg.js",
"ui": "./src/ui/app.js",
"popup": "./src/popup.js",
"sw": "./src/sw/main.js"
},
optimization,
resolve: {fallback},
output: {
path: path.join(__dirname, "wr-ext"),
filename: (chunkData) => {
return !["sw", "ui"].includes(chunkData.chunk.name) ? "[name].js": "./replay/[name].js";
},
libraryTarget: "global",
globalObject: "self"
},
plugins: [
new webpack.ProvidePlugin({
process: "process/browser.js",
Buffer: ["buffer", "Buffer"],
}),
new MiniCssExtractPlugin(),
new webpack.BannerPlugin(BANNER),
new GenerateJsonPlugin("manifest.json", manifest, generateManifest, 2),
new webpack.DefinePlugin({...defaultDefines,
__IPFS_CORE_URL__: JSON.stringify(IPFS_CORE_URL),
}),
new CopyPlugin({
patterns: [
{ from: "node_modules/ipfs-core/dist/index.min.js", to: "ipfs-core.min.js" },
]
})
],
module: moduleSettings,
};
};
module.exports = [ extensionConfig, electronRendererConfig, electronMainConfig, electronPreloadConfig ];