-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.babel.js
132 lines (129 loc) · 3.19 KB
/
webpack.config.babel.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
123
124
125
126
127
128
129
130
131
132
import HtmlWebpackPlugin from "html-webpack-plugin";
import TerserPlugin from "terser-webpack-plugin";
import CopyPlugin from "copy-webpack-plugin";
import { resolve as _resolve } from "path";
const bundleFrontendScripts = (env, argv) => {
const isDev = argv.mode === "development";
return {
name: "frontend",
stats: "errors-warnings",
devtool: isDev ? "eval-source-map" : "source-map",
entry: {
popup: "./src/popup/index.js",
options: "./src/options/index.js",
},
output: {
filename: "bundle.[name].js",
path: _resolve(__dirname, isDev ? "dev" : "dist"),
publicPath: "/",
},
plugins: [
new HtmlWebpackPlugin({
filename: "popup.html",
template: "./src/popup/index.html",
chunks: ["popup"],
}),
new HtmlWebpackPlugin({
filename: "options.html",
template: "./src/options/index.html",
chunks: ["options"],
}),
],
resolve: {
modules: [__dirname, "src", "node_modules"],
extensions: ["*", ".js", ".jsx", ".tsx", ".ts"],
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: require.resolve("babel-loader"),
},
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
{
test: /\.(png|svg|jpg|gif)$/,
loader: "file-loader",
options: {
outputPath: "assets/",
publicPath: "assets/",
name: "[name].[ext]",
},
},
],
},
devServer: {
hot: false,
client: {
overlay: true,
},
allowedHosts: "all",
devMiddleware: {
stats: "minimal",
writeToDisk: true,
},
port: 8000,
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
format: {
comments: false,
},
},
extractComments: false,
}),
],
},
};
};
const bundleBackgroundScripts = (env, argv) => {
const isDev = argv.mode === "development";
return {
name: "background",
cache: false,
stats: "errors-warnings",
devtool: isDev ? "eval-source-map" : "source-map",
entry: { background: "./src/background/background.js" },
resolve: {
modules: [__dirname, "src", "node_modules"],
extensions: ["*", ".js", ".jsx", ".tsx", ".ts"],
},
output: {
filename: "bundle.[name].js",
path: _resolve(__dirname, isDev ? "dev" : "dist"),
publicPath: "/",
},
plugins: [
new CopyPlugin({
patterns: [
{ context: _resolve(__dirname, "src"), from: "assets", to: "assets" },
],
}),
new CopyPlugin({
patterns: [
{ context: _resolve(__dirname, "src"), from: "manifest.json" },
],
}),
],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
format: {
comments: false,
},
},
extractComments: false,
}),
],
},
};
};
module.exports = [bundleFrontendScripts, bundleBackgroundScripts];