forked from ruffle-rs/ruffle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
153 lines (141 loc) · 5.12 KB
/
webpack.config.js
File metadata and controls
153 lines (141 loc) · 5.12 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
import fs from "fs";
import url from "url";
import json5 from "json5";
import CopyPlugin from "copy-webpack-plugin";
/**
* @param {Buffer} content
* @param {Record<string, any>} env
* @returns {string}
*/
function transformManifest(content, env) {
const manifest = json5.parse(content.toString());
let packageVersion = process.env["npm_package_version"];
let versionChannel = process.env["CFG_RELEASE_CHANNEL"] || "local";
let version4 = process.env["VERSION4"];
let firefoxExtensionId =
process.env["FIREFOX_EXTENSION_ID"] || "ruffle@ruffle.rs";
if (process.env["ENABLE_VERSION_SEAL"] === "true") {
if (fs.existsSync("../../version_seal.json")) {
const versionSeal = JSON.parse(
fs.readFileSync("../../version_seal.json", "utf8"),
);
packageVersion = versionSeal.version_number;
versionChannel = versionSeal.version_channel;
version4 = versionSeal.version4;
firefoxExtensionId = versionSeal.firefox_extension_id;
} else {
throw new Error(
"Version seal requested but not found. To generate it, please run web/packages/core/tools/set_version.js using node in the web directory, with the ENABLE_VERSION_SEAL environment variable set to true.",
);
}
}
// At this point all code below needs to be deterministic. If you want other
// information to be included here you must store it in the version seal
// when it gets generated in web/packages/core/tools/set_version.js and then
// load it in the code above.
// The extension marketplaces require the version to monotonically increase
// and to be in the format of A.B.C.D.
manifest.version = version4 ? version4 : packageVersion;
if (env["firefox"]) {
manifest.browser_specific_settings = {
gecko: {
id: firefoxExtensionId,
data_collection_permissions: {
required: ["none"],
},
},
};
manifest.background = {
scripts: ["dist/background.js"],
};
} else {
if (
versionChannel === "stable" ||
packageVersion?.includes(versionChannel)
) {
manifest.version_name = packageVersion;
} else {
manifest.version_name = `${versionChannel} ${packageVersion}`;
}
manifest.background = {
service_worker: "dist/background.js",
};
// Chrome runs the extension in a single shared process by default,
// which prevents extension pages from loading in Incognito tabs
manifest.incognito = "split";
}
return JSON.stringify(manifest);
}
/**
* @type {import("webpack-cli").CallableWebpackConfiguration}
*/
export default function (/** @type {Record<string, any>} */ env, _argv) {
const mode =
/** @type {import("webpack").Configuration["mode"]} */ (
process.env["NODE_ENV"]
) || "production";
console.log(`Building ${mode}...`);
return {
mode,
entry: {
popup: "./src/popup.ts",
options: "./src/options.ts",
onboard: "./src/onboard.ts",
content: "./src/content.ts",
ruffle: "./src/ruffle.ts",
background: "./src/background.ts",
player: "./src/player.ts",
pluginPolyfill: "./src/plugin-polyfill.ts",
siteContentScript4399: "./src/4399-content-script.ts",
},
output: {
path: url.fileURLToPath(new URL("assets/dist/", import.meta.url)),
// publicPath: "auto" throws for content scripts, which lack a script src
// This is changed at runtime to the full URL of the extension's /dist/ folder
publicPath: "/dist/",
clean: true,
assetModuleFilename: "assets/[name][ext][query]",
},
module: {
rules: [
{
test: /\.ts$/i,
use: "ts-loader",
},
],
},
resolve: {
extensions: [".ts", "..."],
},
performance: {
/**
* @param {string} assetFilename
* @returns {boolean}
*/
assetFilter: (assetFilename) =>
!/\.(map|wasm)$/i.test(assetFilename),
},
optimization: {
minimize: false,
},
devtool: mode === "development" ? "source-map" : false,
plugins: [
new CopyPlugin({
patterns: [
{
from: "manifest.json5",
to: "../manifest.json",
transform: (content) =>
transformManifest(
content,
/** @type {Record<string, any>} */ (env),
),
},
{ from: "LICENSE*" },
{ from: "README.md" },
{ from: "4399_rules.json" },
],
}),
],
};
}