-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
122 lines (120 loc) · 2.95 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
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
const path = require("path");
const HTMLPlugin = require("html-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const ExtReloader = require("webpack-ext-reloader");
const webpack = require("webpack");
const port = process.env.PORT || 3000;
module.exports = {
entry: {
popup: "./src/Page/index.js",
background: "./src/Script/Background/index.js",
content: "./src/Script/Content/index.js",
},
mode: "development", // this is overriden by the --mode flag in the npm build script
devtool: "source-map", // this is required to run the extension in dev mode, if removed it uses eval() which is not allowed by the chrome extension manifest
devServer: {
port,
open: true,
client: {
overlay: {
errors: true,
warnings: false,
runtimeErrors: true,
},
},
},
module: {
rules: [
{
test: /\.(css|scss)$/,
use: [
'style-loader',
'css-loader',
'sass-loader'
]
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader", // Replace 'babel-loader' with the appropriate loader
options: {
presets: ["@babel/preset-env", "@babel/preset-react"],
},
},
},
{
test: /\.(png|svg|jpg|jpeg|gif|ico)$/,
exclude: /node_modules/,
use: ["file-loader?name=[name].[ext]"], // ?name=[name].[ext] is only necessary to preserve the original file name
},
],
},
plugins: [
new CopyPlugin({
patterns: [
{ from: "manifest.json", to: path.join(__dirname, "dist") },
{
from: "public",
to: path.join(__dirname, "dist"),
globOptions: {
ignore: ["**/popup.html"],
},
},
],
options: {
concurrency: 100,
},
}),
...["popup"].map(name => {
return new HTMLPlugin({
title: `${name} page`,
filename: `${name}.html`,
chunks: [name],
template: `public/${name}.html`,
minify: true,
templateParameters: {
PUBLIC_URL: process.env.PUBLIC_URL || "",
},
});
}),
new webpack.ProvidePlugin({
React: "react",
}),
new ExtReloader({
port,
entries: {
contentScript: "content",
background: "background",
extensionPage: ["popup"],
},
}),
],
resolve: {
extensions: [".tsx", ".ts", ".js"],
alias: {
"@": path.resolve(__dirname, "src/"),
"@Page": path.resolve(__dirname, "src/Page/"),
"@BackgroundScript": path.resolve(
__dirname,
"src/Script/Background/"
),
"@ContentScript": path.resolve(__dirname, "src/Script/Content/"),
"@Component": path.resolve(__dirname, "src/Component/"),
"@Hook": path.resolve(__dirname, "src/Hook/"),
"@Util": path.resolve(__dirname, "src/Util/"),
"@Context": path.resolve(__dirname, "src/Context/"),
},
},
output: {
path: path.join(__dirname, "dist"),
// include full folder path
filename: pathData => {
if (["background", "content"].includes(pathData.chunk.name)) {
return `bundle/script/${pathData.chunk.name}.js`;
} else {
return `bundle/page/${pathData.chunk.name}.js`;
}
},
},
};