-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
86 lines (73 loc) · 2.45 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
const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
module.exports = function (env, argv) {
const applyTransformation = (content, transformation) => {
const parsedContent = JSON.parse(content);
const transformedContent = transformation(parsedContent, argv.mode);
return JSON.stringify(transformedContent, null, 2);
};
return {
mode: argv.mode,
entry: {
"dist/popup": "./src/popup.tsx",
"dist/manage-data": "./src/manage-data.tsx",
"dist/background": "./src/background.ts",
},
output: {
path: path.resolve(__dirname, "build"),
filename: "[name].js",
},
devtool: argv.mode === "development" ? "inline-source-map" : false,
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
modules: ["node_modules"],
alias: {
"@root": path.resolve(__dirname, "src"),
"@actions": path.resolve(__dirname, "src/actions"),
"@components": path.resolve(__dirname, "src/components"),
"@hooks": path.resolve(__dirname, "src/hooks"),
"@icons": path.resolve(__dirname, "src/icons"),
"@messaging": path.resolve(__dirname, "src/messaging"),
"@models": path.resolve(__dirname, "src/models"),
"@services": path.resolve(__dirname, "src/services"),
},
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /(node_modules)/,
loader: "ts-loader",
},
],
},
plugins: [
new CleanWebpackPlugin(),
new CopyPlugin({
patterns: [
{
from: "node_modules/webextension-polyfill/dist/browser-polyfill.min.js",
to: "vendor/webextension-polyfill.min.js",
},
{
from: "platform/manifest.common.json",
to: "platform/chrome/manifest.json",
transform: (content, path) => {
const transform = require("./platform/chrome/manifest.transform");
return applyTransformation(content, transform);
},
},
{
from: "platform/manifest.common.json",
to: "platform/firefox/manifest.json",
transform: (content, path) => {
const transform = require("./platform/firefox/manifest.transform");
return applyTransformation(content, transform);
},
},
],
}),
],
};
};