-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
webpack.config.js
97 lines (90 loc) · 3.29 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
const glob = require("glob");
const path = require("path");
const webpack = require("webpack");
const Overrides = require("./firefox-ios/Client/Assets/CC_Script/Overrides.ios.js");
const AllFramesAtDocumentStart = glob.sync(
"./firefox-ios/Client/Frontend/UserContent/UserScripts/AllFrames/AtDocumentStart/*.{js,mjs}"
);
const AllFramesAtDocumentEnd = glob.sync(
"./firefox-ios/Client/Frontend/UserContent/UserScripts/AllFrames/AtDocumentEnd/*.{js,mjs}"
);
const MainFrameAtDocumentStart = glob.sync(
"./firefox-ios/Client/Frontend/UserContent/UserScripts/MainFrame/AtDocumentStart/*.{js,mjs}"
);
const MainFrameAtDocumentEnd = glob.sync(
"./firefox-ios/Client/Frontend/UserContent/UserScripts/MainFrame/AtDocumentEnd/*.{js,mjs}"
);
const WebcompatAllFramesAtDocumentStart = glob.sync(
"./firefox-ios/Client/Frontend/UserContent/UserScripts/AllFrames/WebcompatAtDocumentStart/*.{js,mjs}"
);
const AutofillAllFramesAtDocumentStart = glob.sync(
"./firefox-ios/Client/Frontend/UserContent/UserScripts/AllFrames/AutofillAtDocumentStart/*.{js,mjs}"
);
const AddressFormManager = glob.sync(
"./firefox-ios/Client/Frontend/UserContent/UserScripts/AddressFormManager/*.{js,mjs}"
);
// Ensure the first script loaded at document start is __firefox__.js
// since it defines the `window.__firefox__` global.
const needsFirefoxFile = {
AllFramesAtDocumentStart,
// PDF content does not execute user scripts designated to
// run at document start for some reason. So, we also need
// to include __firefox__.js for the document end scripts.
// ¯\_(ツ)_/¯
AllFramesAtDocumentEnd,
};
for (let [name, files] of Object.entries(needsFirefoxFile)) {
if (path.basename(files[0]) !== "__firefox__.js") {
throw `ERROR: __firefox__.js is expected to be the first script in ${name}.js`;
}
}
// Custom plugin used to replace imports used in Desktop code that use uris:
// resource://... with Assets/...
// This is needed because aliases are not supported for URI imports.
// See: https://github.com/webpack/webpack/issues/12792
const CustomResourceURIWebpackPlugin =
new webpack.NormalModuleReplacementPlugin(/resource:(.*)/, function (
resource
) {
const issuer = path.basename(resource.contextInfo.issuer);
const moduleName = path.basename(resource.request);
const override = Overrides.ModuleOverrides[moduleName];
if (override && issuer !== override) {
resource.request = resource.request.replace(moduleName, override);
}
resource.request = resource.request.replace(/.*\//, "Assets/CC_Script/");
});
module.exports = {
mode: "production",
entry: {
AllFramesAtDocumentStart,
AllFramesAtDocumentEnd,
MainFrameAtDocumentStart,
MainFrameAtDocumentEnd,
WebcompatAllFramesAtDocumentStart,
AutofillAllFramesAtDocumentStart,
AddressFormManager,
},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "firefox-ios/Client/Assets"),
},
module: {
rules: [
{
test: /\.mjs$/,
include: [path.resolve(__dirname, "firefox-ios/Client/Assets/CC_Script/")],
type: "javascript/auto",
},
],
},
plugins: [CustomResourceURIWebpackPlugin],
resolve: {
fallback: {
url: require.resolve("page-metadata-parser"),
},
alias: {
Assets: path.resolve(__dirname, "firefox-ios/Client/Assets"),
},
},
};