-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpackExtension.config.js
More file actions
99 lines (97 loc) · 3.61 KB
/
webpackExtension.config.js
File metadata and controls
99 lines (97 loc) · 3.61 KB
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
const path = require("path");
const fs = require("fs");
const webpack = require("webpack");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const { version } = require('./package.json');
module.exports = (_env, argv) => {
const isDevelopment = argv.mode === "development";
// const browsers = ["chrome", "edge", "firefox"];
const browsers = ["chrome", "firefox"];
return browsers.map((browser) => ({
mode: isDevelopment ? "development" : "production",
// devtool: isDevelopment ? "source-map" : false,
// Inline-source-map is only for testing, revert this change later
devtool: "inline-source-map",
entry: {
action: "./src/action.ts",
background: "./src/background.ts",
settings: "./src/settings.ts", // Needed to access IndexedDB's UI in devtools
"scripts/worldMain": "./src/scripts/worldMain.ts",
"scripts/worldIsolated": "./src/scripts/worldIsolated.ts",
...(isDevelopment
? {
"playwright/harness/testBrowserContexts": "./playwright/harness/testBrowserContexts.ts",
"playwright/harness/testWorkbench": "./playwright/harness/testWorkbench.ts",
}
: {}),
},
output: {
path: path.resolve(__dirname, "webext", browser),
filename: "[name].js",
},
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
// {
// test: /\.css$/i,
// type: "asset/source",
// },
// {
// test: /\.html$/i,
// type: "asset/source",
// },
],
},
resolve: {
extensions: [".ts", ".js"],
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{ from: "src/_locales", to: "_locales" },
{ from: "src/icons", to: "icons" },
// { from: "src/images", to: "images" },
{
from: `src/manifests/manifest.${browser}.json`,
to: "manifest.json",
transform: {
transformer(content) {
// Replace placeholders with the version string
return content.toString().replace(/{{VERSION}}/g, version);
},
},
},
{ from: "src/*.html", to: "[name][ext]" },
{ from: "src/*.css", to: "[name][ext]" },
],
}),
new webpack.ProvidePlugin({
log: ["/src/logging", "Logger", "log"],
LogLevels: ["/src/logging", "Logger"],
}),
],
optimization: {
minimize: !isDevelopment,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
mangle: false,
},
extractComments: false,
}),
],
},
cache: {
type: "filesystem", // Enables caching in 'memory' or 'filesystem'
},
}));
};