-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathwebpack.config.js
More file actions
198 lines (184 loc) · 7.85 KB
/
webpack.config.js
File metadata and controls
198 lines (184 loc) · 7.85 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
const path = require('path');
const glob = require('glob');
const CopyPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CompressionPlugin = require("compression-webpack-plugin");
const webpack = require('webpack');
const resolve = require('path').resolve;
const CHROME_KEY =
'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmf6qYyrFypvvB0klM/hHhIdGO0bAnUT6ZK4fLqGl8/l5OWze2leeQkC/Nf0HOTQ50d2sdgXFuQDfHsMF+HQ5pUVIUT/25MzEXZWGwqi+JAxEX9Q/yGFFN53nI4m7mGNzCQ0TDUS3IrJsFfQBMEdv/fAwnhEitF/Ko9qn8/KYDzZqIjujwXKKeqlx+UXIvkgblI44RT9evwiqp+/WjZZ/YQzLa9tFhdz0Ct3Qvhn/03YrLAXa+yxXKpLAjQJ9DpYJoa++bJwluffinxKQUX0tm5dzFRSRKFCG92hKHnQHcQFUnBlDKF4LS0KQhgelyiTxN4GmKX7I1xQS/B1TByLL2wIDAQAB';
function getPathEntries(path) {
return glob.sync(path).reduce((acc, e) => {
if (!e.includes('node_modules')) {
// Remove extension
acc[e.replace(/\.[^/.]+$/, '')] = './' + e;
}
return acc;
}, {});
}
function convertToFirefoxManifest(manifest) {
const cp = Object.assign({}, manifest);
cp.action = {
default_popup: "src/popup.html"
}
cp.background = {
page: 'src/background_ff.html',
};
cp.browser_specific_settings = {
gecko: {
id: '{194d0dc6-7ada-41c6-88b8-95d7636fe43c}',
strict_min_version: '127.0',
},
};
// Allow getting the extension version from CSFloat page in Firefox
cp.content_scripts.push({
matches: ['*://*.csfloat.com/*'],
js: ['src/lib/page_scripts/csfloat.js'],
});
cp.host_permissions.push('*://*.csfloat.com/*');
// Force optional host permissions to be required
cp.host_permissions = cp.host_permissions.concat(cp.optional_host_permissions);
// Not supported in Firefox
cp.permissions = cp.permissions.filter(e => e !== 'offscreen');
return cp;
}
module.exports = (env) => {
const mode = env.mode || 'development';
return {
mode: 'none',
entry: Object.assign(
getPathEntries('./src/lib/page_scripts/*.ts'),
getPathEntries('./src/lib/types/*.d.ts'),
getPathEntries('./src/background.ts'),
getPathEntries('./src/popup/popup.ts'),
getPathEntries('./src/offscreen/offscreen.ts'),
getPathEntries('./src/**/*.js')
),
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js',
},
resolve: {
extensions: ['.ts', '.js', '.html'],
},
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader',
exclude: /node_modules|\.d\.ts$/,
},
{
test: /\.d\.ts$/,
loader: 'ignore-loader',
},
{
test: new RegExp(`.(css)$`),
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
exclude: /node_modules/,
},
{
test: /environment\.ts$/,
loader: 'file-replace-loader',
options: {
condition: mode === 'development',
replacement: resolve('./src/environment.dev.ts'),
},
},
{
test: /tlsn_wasm_bg\.wasm$/,
type: 'asset/resource',
generator: {
filename: 'tlsn_wasm_bg.wasm',
},
},
],
},
plugins: [
new MiniCssExtractPlugin(),
new webpack.SourceMapDevToolPlugin({}),
new CopyPlugin({
patterns: [
{from: 'icons', to: 'icons', context: '.'},
{from: 'data', to: 'data', context: '.', globOptions: { ignore: ['bluegem.json'] } },
{from: 'src/global.css', to: 'src/', context: '.'},
{from: 'src/background_ff.html', to: 'src/', context: '.'},
{from: 'src/steamcommunity_ruleset.json', to: 'src/', context: '.'},
{from: 'src', to: 'raw/', context: '.'},
{from: 'README.md', to: '', context: '.'},
{from: 'src/popup/popup.html', to: 'src/', context: '.'},
{from: 'src/offscreen/offscreen.html', to: 'src/', context: '.'},
{from: 'node_modules/@csfloat/tlsn-wasm/*.js', to: '[name][ext]'},
{from: 'node_modules/@csfloat/tlsn-wasm/snippets', to: 'snippets/', context: '.'},
{
from: 'manifest.json',
to: 'manifest.json',
transform(raw) {
let processed = JSON.parse(raw.toString());
if (mode === 'development' && env.browser === 'chrome') {
processed.key = CHROME_KEY;
}
if (mode === 'development') {
// Add permissions only used for connecting to localhost dev env
processed.host_permissions.push('http://localhost:8080/*');
processed.host_permissions.push('http://localhost:4200/*');
// If you're running phoenix locally
processed.content_scripts.push({
matches: ['*://*.localhost/*'],
js: ['src/lib/page_scripts/csfloat.js'],
});
const versionResource = processed.web_accessible_resources.find((e) =>
e.resources[0].includes('version.txt')
);
versionResource.matches.push('http://localhost:4200/*');
processed.externally_connectable.matches.push('http://localhost/*');
processed.externally_connectable.matches.push('http://localhost:4200/*');
}
if (env.browser === 'firefox') {
processed = convertToFirefoxManifest(processed);
}
return JSON.stringify(processed, null, 2);
},
},
{
from: 'manifest.json',
to: 'src/version.txt',
transform(raw) {
let processed = JSON.parse(raw.toString());
return processed.version;
},
},
],
}),
// Add Gzip compression for bluegem.json
new CompressionPlugin({
filename: "[path][base].gz", // Change extension to .gz
algorithm: "gzip",
test: /bluegem\.json$/,
deleteOriginalAssets: true,
}),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
],
stats: {
errorDetails: true,
},
optimization: {
usedExports: true,
},
// Required by wasm-bindgen-rayon, in order to use SharedArrayBuffer on the Web
// Ref:
// - https://github.com/GoogleChromeLabs/wasm-bindgen-rayon#setting-up
// - https://web.dev/articles/coop-coep
devServer: {
headers: {
'Cross-Origin-Embedder-Policy': 'require-corp',
'Cross-Origin-Opener-Policy': 'same-origin',
}
},
};
};