forked from FlightPenguin/flightpenguin-browser-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
137 lines (127 loc) · 4.04 KB
/
webpack.config.ts
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import * as path from "path";
import * as TerserPlugin from "terser-webpack-plugin";
import { Configuration, DefinePlugin, ProgressPlugin } from "webpack";
const CopyPlugin = require("copy-webpack-plugin");
const WebpackExtensionManifestPlugin = require("webpack-extension-manifest-plugin");
const TARGET_VENDOR = process.env.TARGET_VENDOR as "firefox" | "chrome";
// @ts-ignore
const VERSION = require("./package.json").version;
const baseManifestV2 = require("./src/baseManifest.v2.ts");
const defaultEntry = {
background: "./background.js",
"content_scripts/cheapoair": "./content_scripts/collectors/cheapoair/contentScript.ts",
index: "./index.js",
"content_scripts/momondo": "./content_scripts/collectors/momondo/contentScript.ts",
"content_scripts/kiwi": "./content_scripts/collectors/kiwi/contentScript.ts",
"content_scripts/trip": "./content_scripts/collectors/trip/contentScript.ts",
"content_scripts/generic": "./content_scripts/generic/contentScript.ts",
"content_scripts/flightpenguin": "./content_scripts/flightpenguin/contentScript.ts",
};
const getModuleRules = () => [
{
test: /\.(js|jsx|ts|tsx)$/,
loader: "babel-loader",
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
];
const baseResolve = {
extensions: ["*", ".js", ".jsx", ".tsx", ".ts"],
alias: {
components: path.resolve(__dirname, "src/components"),
shared: path.resolve(__dirname, "src/shared"),
sharedTypes: path.resolve(__dirname, "src/shared/types"),
},
};
const getBrowserSpecificManifestData = () => {
const manifestData: { [keyof: string]: any } = {
version: VERSION,
};
switch (TARGET_VENDOR) {
case "chrome":
break;
case "firefox":
break;
default:
throw new Error(`Unknown browser ${TARGET_VENDOR}`);
}
return manifestData;
};
const basePlugins = [
new ProgressPlugin({}),
new DefinePlugin({
"process.env.BUMBAG_ENV": JSON.stringify("not test"),
"process.env.VERSION": JSON.stringify(VERSION),
}),
new CopyPlugin({
patterns: [
{ from: "assets/icons", to: path.resolve(__dirname, "./build", TARGET_VENDOR, "icons") },
{ from: "assets/images", to: path.resolve(__dirname, "./build", TARGET_VENDOR, "images") },
{ from: "background.html", to: path.resolve(__dirname, "./build", TARGET_VENDOR) },
{ from: "index.html", to: path.resolve(__dirname, "./build", TARGET_VENDOR) },
{ from: "css", to: path.resolve(__dirname, "./build", TARGET_VENDOR, "css") },
],
}),
new WebpackExtensionManifestPlugin({
config: { base: baseManifestV2, extend: getBrowserSpecificManifestData() },
}),
];
const baseOutput = {
filename: "[name].js",
path: path.resolve(__dirname, "./build", TARGET_VENDOR),
publicPath: "/",
sourceMapFilename: "[file].map",
};
const baseOptimization = {};
export const development: Configuration = {
mode: "development",
entry: defaultEntry,
output: baseOutput,
plugins: [...basePlugins, new DefinePlugin({ "process.env.EXTENSION_ENV": JSON.stringify("development") })],
resolve: baseResolve,
resolveLoader: {
modules: ["node_modules", path.resolve(__dirname, "loaders")],
},
devtool: "inline-source-map",
module: {
rules: getModuleRules(),
},
optimization: baseOptimization,
target: "web",
context: path.resolve(__dirname, "./src"),
};
export const production: Configuration = {
mode: "production",
entry: defaultEntry,
output: baseOutput,
plugins: [...basePlugins, new DefinePlugin({ "process.env.EXTENSION_ENV": JSON.stringify("production") })],
resolve: baseResolve,
resolveLoader: {
modules: ["node_modules", path.resolve(__dirname, "loaders")],
},
devtool: "source-map",
module: {
rules: getModuleRules(),
},
target: "web",
context: path.resolve(__dirname, "./src"),
optimization: {
minimize: true,
minimizer: [
// @ts-ignore
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true,
},
format: {
comments: false,
},
sourceMap: true,
},
}),
],
},
};