-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbase.webpack.config.mjs
More file actions
115 lines (105 loc) · 3.86 KB
/
base.webpack.config.mjs
File metadata and controls
115 lines (105 loc) · 3.86 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/************************************************************************
* Copyright (C) 2025 Code Forge Temple *
* This file is part of scribe-pal project *
* Licensed under the GNU General Public License v3.0. *
* See the LICENSE file in the project root for more information. *
************************************************************************/
import path from "path";
import CopyWebpackPlugin from "copy-webpack-plugin";
import fs from "fs/promises";
function convertToTitleCase (str) {
return str
.split("-")
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join("");
}
function convertToDotNotation (str) {
return str.toLowerCase().trim().split(/\s+/).join(".");
}
const BUILD_FOLDER = "./dist";
const baseConfig = (browser, manifestFile) => ({
mode: "development",
devtool: "source-map",
entry: {
popup: "./src/popup/popup.ts",
serviceWorker: "./src/tab/serviceWorker.ts",
injectedScript: "./src/tab/injectedScript.ts",
},
output: {
path: path.resolve(process.cwd(), `${BUILD_FOLDER}/${browser}`),
filename: "[name].js",
clean: true,
},
optimization: {
runtimeChunk: false,
},
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
},
module: {
rules: [
{
test: /\.(ts|tsx|js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript",
],
},
},
},
{
test: /\.scss$/,
oneOf: [
{
resourceQuery: /inline/,
use: ["raw-loader", "sass-loader"],
},
{
use: ["style-loader", "css-loader", "sass-loader"],
},
],
},
{
test: /\.svg$/i,
use: ["@svgr/webpack"],
exclude: /node_modules/,
},
],
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{from: path.resolve("src/popup/popup.html"), to: "."},
{from: path.resolve("src/popup/assets"), to: "assets"},
{
from: path.resolve(manifestFile),
to: "./manifest.json",
transform: async (content) => {
try {
const pkgPath = path.resolve("package.json");
const pkgData = await fs.readFile(pkgPath, "utf8");
const pkg = JSON.parse(pkgData);
const manifest = JSON.parse(content.toString());
manifest.name = convertToTitleCase(pkg.name);
manifest.version = pkg.version;
manifest.description = pkg.description;
if(manifest.browser_specific_settings) {
manifest.browser_specific_settings.gecko.id = `${pkg.name}@${convertToDotNotation(pkg.author)}`;
}
return JSON.stringify(manifest, null, 4);
} catch (error) {
console.error("Error updating manifest.json:", error);
return content;
}
},
},
],
}),
],
});
export default baseConfig;