forked from EMPRI-DEVOPS/empri-browser-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebextension-toolbox-config.js
55 lines (48 loc) · 1.76 KB
/
webextension-toolbox-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
// This file is not going through babel transformation.
// So, we write it in vanilla JS
// (But you could use ES2015 features supported by your Node.js version)
const webpack = require("webpack");
module.exports = {
webpack: (config, { dev, vendor }) => {
// Perform customizations to webpack config
// TODO(FAP): can be removed once https://github.com/webextension-toolbox/webextension-toolbox/pull/347 is merged
// Add webextension polyfill
if (["edge"].includes(vendor)) {
config.plugins.push(
new webpack.ProvidePlugin({
browser: require.resolve("webextension-polyfill"),
})
);
// The webextension-polyill doesn't work well with webpacks ProvidePlugin.
// So we need to monkey patch it on the fly
// More info: https://github.com/mozilla/webextension-polyfill/pull/86
config.module.rules.push({
test: /webextension-polyfill[\\/]+dist[\\/]+browser-polyfill\.js$/,
loader: require.resolve("string-replace-loader"),
query: {
search: 'typeof browser === "undefined"',
replace:
'typeof window.browser === "undefined" || Object.getPrototypeOf(window.browser) !== Object.prototype',
},
});
}
config.plugins.push(
new webpack.EnvironmentPlugin({
BROWSER_USER: "browser",
BROWSER_PASSWORD: "secrets",
})
);
if (process.env.NODE_ENV === "production") {
var apiUrl = "https://empri-devops.vogella.com:5555";
} else if (process.env.NODE_ENV === "development") {
var apiUrl = "http://localhost:5555";
}
config.plugins.push(
new webpack.DefinePlugin({
API_URL: JSON.stringify(apiUrl),
})
);
// Important: return the modified config
return config;
},
};