-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.prod.js
174 lines (166 loc) · 5.07 KB
/
webpack.config.prod.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const webpack = require("webpack");
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const CopyPlugin = require("copy-webpack-plugin");
const DotenvPlugin = require("dotenv-webpack");
const TerserPlugin = require("terser-webpack-plugin");
const path = require("path");
module.exports = ({ heapId }, { mode }) => {
const isDevelopment = mode === "development";
return {
entry: {
popup: {
import: "./src/pages/popup/index.tsx",
filename: "pages/[name].js"
},
app: {
import: "./src/pages/app/index.tsx",
filename: "pages/[name].js"
},
content: path.join(__dirname, "src/content.tsx"),
background: path.join(__dirname, "src/background.ts"),
},
output: { path: path.join(__dirname, "dist"), filename: "[name].js", publicPath: '/', clean: true },
module: {
rules: [
{
test: /\.[jt]sx?$/,
exclude: /node_modules/,
use: [
{
loader: require.resolve("babel-loader"),
options: {
plugins: [
isDevelopment && require.resolve("react-refresh/babel"),
].filter(Boolean),
},
},
],
},
{
test: /\.s[ac]ss|css$/i,
use: ["style-loader", "css-loader", "resolve-url-loader", "sass-loader"],
},
{
test: /\.(png|jpg|gif|svg)$/i,
type: "asset/resource",
generator: {
filename: 'static/[hash][ext][query]'
},
exclude: [
path.join(__dirname, "src/images/ui/fa"),
path.join(__dirname, "src/images/ui/fa/brands"),
path.join(__dirname, "src/images/ui/flags")
]
},
{
test: /\.svg$/,
use: ["@svgr/webpack"],
generator: {
filename: 'static/[hash][ext][query]'
},
include: [
path.join(__dirname, "src/images/ui/flags"),
path.join(__dirname, "src/images/ui/fa"),
]
},
{
test: /\.less$/,
use: [{
loader: "style-loader",
}, {
loader: "css-loader",
}, {
loader: "less-loader",
options: {
lessOptions: {
modifyVars: {
"primary-color": "#12b886",
"border-radius-base": "5px",
"btn-border-radius-base": "6px",
"font-family": "'Source Sans Pro', 'Noto Sans JP', BlinkMacSystemFont, -apple-system, 'Segoe UI', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol','Noto Color Emoji'",
},
javascriptEnabled: true,
},
},
}],
}
],
},
resolve: {
extensions: [".js", ".jsx", ".tsx", ".ts"],
alias: {
"@": path.join(__dirname, "src"),
"@img": path.join(__dirname, "src/images"),
"@hooks": path.join(__dirname, "src/common/hooks"),
"@consts": path.join(__dirname, "src/common/consts"),
"@facades": path.join(__dirname, "src/common/facades"),
"@bg": path.join(__dirname, "src/background"),
},
fallback: {
"stream": require.resolve("stream-browserify"),
"buffer": require.resolve("buffer"),
"crypto": require.resolve("crypto-browserify"),
"assert": false
},
},
devServer: {
contentBase: "./dist",
hot: true,
},
plugins: [
new DotenvPlugin({
path: ((mode) => {
switch (mode) {
case "development":
return "./.env"
case "production":
return "./prod.env"
default:
return "./.env"
}
})(mode)
}),
new CopyPlugin({
patterns: [{
from: "public",
to: ".",
filter: async (resourcePath) => {
if (resourcePath.match(`pages\/heap\-${heapId}\.js`)) return true
else if (resourcePath.match(/pages\/heap\-\d+\.js/)) return false
return true
},
transform(content, absoluteFrom) {
if (absoluteFrom.endsWith("heap.js") || absoluteFrom.endsWith("manifest.json")) return content.toString().replace("$HEAP_IO_ID", heapId)
return content
},
}],
}),
new webpack.HotModuleReplacementPlugin(),
new ReactRefreshWebpackPlugin(),
//new BundleAnalyzerPlugin(),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
new webpack.ProvidePlugin({
process: 'process/browser',
}),
],
optimization: {
minimize: true,
minimizer: [new TerserPlugin({
extractComments: false,
parallel: true,
terserOptions: {
ecma: 6,
output: {
ascii_only: true
},
compress: {
drop_console: true,
},
},
})],
},
};
}