forked from ruffle-rs/ruffle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
147 lines (134 loc) · 4.83 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
/* eslint-env node */
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"] || "nightly";
let buildDate = new Date().toISOString().substring(0, 10);
let build_id = process.env["BUILD_ID"];
let firefox_extension_id =
process.env["FIREFOX_EXTENSION_ID"] || "[email protected]";
if (process.env["ENABLE_VERSION_SEAL"] === "true") {
if (fs.existsSync("../../version_seal.json")) {
const version_seal = JSON.parse(
fs.readFileSync("../../version_seal.json", "utf8")
);
packageVersion = version_seal.version_number;
versionChannel = version_seal.version_channel;
buildDate = version_seal.build_date.substring(0, 10);
build_id = version_seal.build_id;
firefox_extension_id = version_seal.firefox_extension_id;
} else {
throw new Error(
"Version seal requested but not found. Please run web/packages/core/tools/set_version.js with ENABLE_VERSION_SEAL to generate it."
);
}
}
// 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,
// so append the build number onto the end of the manifest version.
manifest.version = build_id
? `${packageVersion}.${build_id}`
: packageVersion;
if (env["firefox"]) {
manifest.browser_specific_settings = {
gecko: {
id: firefox_extension_id,
},
};
} else {
manifest.version_name =
versionChannel === "nightly"
? `${packageVersion} nightly ${buildDate}`
: packageVersion;
// Add `wasm-eval` to the `script-src` directive in the Content Security Policy.
// This setting is required by Chrome to allow Wasm in the extension.
// Eventually this may change to `wasm-unsafe-eval`, and we may need this for all browsers.
manifest.content_security_policy =
manifest.content_security_policy.replace(
/(script-src\s+[^;]*)(;|$)/i,
"$1 'wasm-eval'$2"
);
// 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").CallableOption}
*/
export default function (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",
content: "./src/content.ts",
ruffle: "./src/ruffle.ts",
background: "./src/background.ts",
player: "./src/player.ts",
pluginPolyfill: "./src/plugin-polyfill.ts",
},
output: {
path: url.fileURLToPath(new URL("assets/dist/", import.meta.url)),
publicPath: "",
clean: true,
},
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,
},
plugins: [
new CopyPlugin({
patterns: [
{
from: "manifest.json5",
to: "../manifest.json",
transform: (content) =>
transformManifest(
content,
/** @type {Record<string, any>} */ (env)
),
},
{ from: "LICENSE*" },
{ from: "README.md" },
],
}),
],
};
}