-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.base.config.js
116 lines (113 loc) · 2.79 KB
/
webpack.base.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
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
const MiniCSSExtractPlugin = require("mini-css-extract-plugin");
const pages = require("./.eb/pages.js");
const fs = require("fs");
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const { DefinePlugin } = require("webpack");
const contentScripts = require("./config/content_scripts.json");
const popupScript = path.resolve(
"./src/popup",
fs.readdirSync("./src/popup/").find(function (file) {
return /index\.[tj]sx?$/.test(file);
})
);
const backgroundScript = path.resolve(
"./src/background",
fs.readdirSync("./src/background/").find(function (file) {
return /index\.[tj]s$/.test(file);
})
);
const contentScriptEntries = Object.fromEntries(
Object.entries(contentScripts).map(function (entry) {
return [entry[0], path.resolve("./src/content", entry[1])];
})
);
module.exports = function (env) {
return {
name: "base",
entry: {
popup: popupScript,
background: backgroundScript,
...contentScriptEntries,
...pages.entries
},
output: {
asyncChunks: true,
filename: "[name].js",
path: path.resolve(__dirname, "dist"),
environment: {
arrowFunction: false
},
assetModuleFilename: "assets/[name].[ext]"
},
resolve: {
extensions: [".js", ".ts", ".jsx", ".tsx", ".css", ".scss"]
},
module: {
rules: [
{
test: /\.s[ca]ss$/i,
use: [MiniCSSExtractPlugin.loader, "css-loader", "sass-loader"]
},
{
test: /\.css$/i,
use: [MiniCSSExtractPlugin.loader, "css-loader"]
},
{
test: /\.(png|jpg|jpeg|svg|ttf)$/i,
type: "asset/resource"
},
{
test: /\.tsx?$/i,
use: [
{
loader: "ts-loader",
options: {
transpileOnly: true
}
},
{
loader: "ifdef-loader",
options: env
}
],
type: "javascript/auto"
},
{
test: /\.jsx?$/i,
use: [
{
loader: "babel-loader",
options: {
presets: ["@babel/preset-env"]
}
},
{
loader: "ifdef-loader",
options: env
}
],
type: "javascript/auto"
}
]
},
plugins: [
new DefinePlugin({
"process.browser": "true"
}),
...pages.plugins,
new HtmlWebpackPlugin({
template: "./src/popup/index.html",
filename: `popup.html`,
chunks: ["popup"],
cache: true,
inject: false,
meta: {
charset: "utf-8",
page: "popup"
}
}),
new MiniCSSExtractPlugin()
]
};
};