-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
69 lines (65 loc) · 1.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
const CopyPlugin = require("copy-webpack-plugin");
const path = require("path");
const fs = require("fs").promises;
const mergeJson = (fileName) => async (content, _absoluteFrom) => {
const data = await fs.readFile(path.resolve(__dirname, fileName));
const base = JSON.parse(data);
const extension = JSON.parse(content.toString());
return JSON.stringify({ ...base, ...extension });
};
module.exports = {
mode: "production",
entry: {
// popup script
"chromium/index": "./src/popup/index.tsx",
"firefox/index": "./src/popup/index.tsx",
// background script
"chromium/background": "./src/background/index.ts",
"firefox/background": "./src/background/index.ts",
},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "dist"),
},
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [".tsx", ".ts"],
alias: {
"react/jsx-runtime": "preact-jsx-runtime/jsx-runtime",
react: "preact/compat",
"react-dom/test-utils": "preact/test-utils",
"react-dom": "preact/compat",
// Must be below test-utils
},
},
plugins: [
new CopyPlugin({
patterns: [
// once for chromium
{ from: "assets", to: "chromium/assets" },
{ from: "src/popup/index.html", to: "chromium" },
{
from: "manifest/chromium.json",
to: "chromium/manifest.json",
transform: mergeJson("manifest/base.json"),
},
// once for firefox
{ from: "assets", to: "firefox/assets" },
{ from: "src/popup/index.html", to: "firefox" },
{
from: "manifest/firefox.json",
to: "firefox/manifest.json",
transform: mergeJson("manifest/base.json"),
},
],
}),
],
};