-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
80 lines (75 loc) · 1.79 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
const { resolve } = require("path");
const { argv } = require("process");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const ZipPlugin = require("zip-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const isProduction = argv[3] === "production";
const fileExtensions = [
"jpg",
"jpeg",
"png",
"gif",
"eot",
"otf",
"svg",
"ttf",
"woff",
"woff2",
];
const plugins = [
new CleanWebpackPlugin(),
new CopyPlugin({
patterns: [
{ from: "src/frontend/manifest.json", to: "manifest.json" },
{ from: "src/frontend/assets/img/logo.png", to: "img/logo.png" },
{ from: "src/frontend/assets/css/style.css", to: "style.css" },
],
}),
];
if (isProduction) {
plugins.push(
new ZipPlugin({
path: resolve(__dirname),
filename: "bundle.zip",
})
);
}
module.exports = {
mode: isProduction ? "production" : "development",
devtool: isProduction ? "source-map" : "cheap-module-source-map",
entry: {
content: resolve(__dirname, "src/frontend/content/content.js"),
background: resolve(__dirname, "src/frontend/background/background.js")
},
output: {
path: resolve(__dirname, "dist"),
filename: "[name].bundle.js",
},
module: {
rules: [
{
test: /\.(js|ts)x?$/,
loader: "babel-loader",
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ["style-loader", "css-loader", "postcss-loader"],
},
{
test: new RegExp(`.(${fileExtensions.join("|")})$`),
loader: "file-loader",
options: {
name: "[name].[ext]",
},
},
],
},
plugins: plugins,
resolve: {
alias: {
"@": resolve(__dirname, "src/frontend"),
},
extensions: [".js", ".jsx", ".ts", ".tsx", ".json"],
},
};