-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.js
85 lines (82 loc) · 2.22 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
const path = require("path");
const CopyPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { merge } = require("webpack-merge");
const ZipPlugin = require("zip-webpack-plugin");
const { DefinePlugin } = require("webpack");
module.exports = (env) => {
if (!env?.browser) {
env = { browser: "chrome" };
}
const isSafari = env.browser === "safari";
let manifest
let outputPath;
switch (env.browser) {
case "firefox":
manifest = "manifest.firefox.json";
outputPath = path.resolve(__dirname, "dist-firefox");
break;
case "chrome":
manifest = "manifest.chrome.json";
outputPath = path.resolve(__dirname, "dist-chrome");
break;
case "safari":
manifest = "manifest.safari.json";
outputPath = path.resolve(__dirname, "dist-safari");
break;
default:
throw new Error(`Unknown browser: ${env.browser}\nSupported targets are: firefox, chrome, safari`);
}
const baseConfig = {
entry: {
contentScript: "./src/contentScript.tsx",
popup: "./src/popup/index.tsx",
background: "./src/background/index.ts",
},
output: {
filename: "[name].js",
path: outputPath,
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: "ts-loader",
},
{
test: /\.css$/,
include: path.resolve(__dirname, "styles"),
use: ["style-loader", "css-loader", "postcss-loader"],
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
plugins: [
new HtmlWebpackPlugin({
template: "./public/popup.html",
filename: "popup.html",
chunks: ["popup"],
}),
new CopyPlugin({
patterns: [
{ from: ".", to: ".", context: "public/static" },
{
from: manifest,
to: "manifest.json",
},
],
}),
new DefinePlugin({
BROWSER: JSON.stringify(env.browser),
VERSION: JSON.stringify(require("./package.json").version),
}),
...(!isSafari ? [new ZipPlugin({
filename: "prompster.zip",
})] : []),
],
};
return baseConfig;
};