-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.mjs
78 lines (72 loc) · 1.75 KB
/
webpack.config.mjs
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
import path from "path";
import webpack from "webpack";
import CopyPlugin from "copy-webpack-plugin";
const target = process.env.NODE_ENV;
const isFirefoxExtension = target === "firefox";
const isChromiumExtension = target === "chromium";
const copyPluginPatterns = [
{
from: "src/_locales",
to: target + "/_locales",
},
{
from: "src/" + target,
to: target,
globOptions: {
ignore: ["**/*.js"],
},
},
{
from: "src/shared",
to: target + "/shared",
globOptions: {
ignore: ["**/*.js"],
},
}
];
// only copy the api.js file for firefox
if (isFirefoxExtension) {
copyPluginPatterns.push({
from: "src/firefox/api.js",
to: target,
});
}
const alias = {
"Shared": path.resolve("src/shared"),
};
if (target === "firefox") {
alias["Interfaces"] = path.resolve("src/firefox/interfaces");
} else {
alias["Interfaces"] = path.resolve("src/chromium/interfaces");
}
console.log("Building for " + target + "...\n");
export default {
entry: {
background: "./src/shared/backgroundScripts/background.js",
welcomePage: "./src/shared/pages/welcomePage/script.js",
},
output: {
path: path.resolve("build"),
filename: ({ chunk }) => {
if (chunk.name === "background") {
return target + "/background.bundle.js";
} else if (chunk.name === "welcomePage") {
return target + "/shared/pages/welcomePage/script.bundle.js";
}
},
},
resolve: {
alias: alias,
},
mode: "development",
devtool: "inline-source-map",
plugins: [
new webpack.DefinePlugin({
IS_FIREFOX_EXTENSION: JSON.stringify(isFirefoxExtension),
IS_CHROMIUM_EXTENSION: JSON.stringify(isChromiumExtension)
}),
new CopyPlugin({
patterns: copyPluginPatterns,
}),
],
};