forked from juspay/hyperswitch-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
188 lines (176 loc) · 5.35 KB
/
webpack.common.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
const webpack = require("webpack");
const path = require("path");
const tailwindcss = require("tailwindcss");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");
const BundleAnalyzerPlugin =
require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const { sentryWebpackPlugin } = require("@sentry/webpack-plugin");
const sdkEnv = process.env.sdkEnv;
const envSdkUrl = process.env.envSdkUrl;
const envBackendUrl = process.env.envBackendUrl;
//git rev-parse --abbrev-ref HEAD
let repoVersion = require("./package.json").version;
let majorVersion = "v" + repoVersion.split(".")[0];
let repoName = require("./package.json").name;
let repoPublicPath =
sdkEnv === "local" ? "" : `/${repoVersion}/${majorVersion}`;
let sdkUrl;
if (envSdkUrl === undefined) {
sdkUrl =
sdkEnv === "prod"
? "https://checkout.hyperswitch.io"
: sdkEnv === "sandbox"
? "https://beta.hyperswitch.io"
: sdkEnv === "integ"
? "https://dev.hyperswitch.io"
: "http://localhost:9050";
} else {
sdkUrl = envSdkUrl;
}
let backendEndPoint;
if (envBackendUrl === undefined) {
backendEndPoint =
sdkEnv === "prod"
? "https://api.hyperswitch.io"
: sdkEnv === "sandbox"
? "https://sandbox.hyperswitch.io"
: sdkEnv === "integ"
? "https://integ-api.hyperswitch.io"
: "https://sandbox.hyperswitch.io";
} else {
backendEndPoint = envBackendUrl;
}
let confirmEndPoint;
if (envBackendUrl === undefined) {
confirmEndPoint =
sdkEnv === "prod"
? "https://api.hyperswitch.io"
: sdkEnv === "sandbox"
? "https://sandbox.hyperswitch.io"
: sdkEnv === "integ"
? "https://integ-api.hyperswitch.io"
: "https://sandbox.hyperswitch.io";
} else {
confirmEndPoint = envBackendUrl;
}
let logEndpoint =
sdkEnv === "prod"
? "https://api.hyperswitch.io/logs/sdk"
: "https://sandbox.hyperswitch.io/logs/sdk";
// Set this to true to enable logging
let enableLogging = true;
// Choose from DEBUG, INFO, WARNING, ERROR, SILENT
let loggingLevel = "DEBUG";
// Maximum logs emitted for a particular event, to rate limit logs
let maxLogsPushedPerEventName = 100;
module.exports = (publicPath = "auto") => {
let entries = {
app: "./index.js",
HyperLoader: "./src/orca-loader/HyperLoader.bs.js",
};
return {
mode: "development",
devtool: "source-map",
output: {
path:
sdkEnv && sdkEnv !== "local"
? path.resolve(__dirname, "dist", sdkEnv)
: path.resolve(__dirname, "dist"),
clean: true,
publicPath: `${repoPublicPath}/`,
},
optimization: {
sideEffects: true,
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: false,
},
},
}),
// For webpack@5 you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line
// `...`,
// new CssMinimizerPlugin(),
],
},
plugins: [
new MiniCssExtractPlugin(),
new CopyPlugin({
patterns: [{ from: "public" }],
}),
new webpack.DefinePlugin({
repoName: JSON.stringify(repoName),
repoVersion: JSON.stringify(repoVersion),
publicPath: JSON.stringify(repoPublicPath),
sdkUrl: JSON.stringify(sdkUrl),
backendEndPoint: JSON.stringify(backendEndPoint),
confirmEndPoint: JSON.stringify(confirmEndPoint),
logEndpoint: JSON.stringify(logEndpoint),
sentryDSN: JSON.stringify(process.env.SENTRY_DSN),
sentryScriptUrl: JSON.stringify(process.env.SENTRY_SCRIPT_URL),
enableLogging: JSON.stringify(enableLogging),
loggingLevel: JSON.stringify(loggingLevel),
maxLogsPushedPerEventName: JSON.stringify(maxLogsPushedPerEventName),
}),
new HtmlWebpackPlugin({
inject: false,
template: "./public/build.html",
}),
new HtmlWebpackPlugin({
inject: false,
template: "./public/build.html",
}),
new HtmlWebpackPlugin({
// Also generate a test.html
inject: false,
filename: "fullscreenIndex.html",
template: "./public/fullscreenIndexTemplate.html",
}),
new BundleAnalyzerPlugin({
analyzerMode: "static",
reportFilename: "bundle-report.html",
openAnalyzer: false,
}),
// new webpack.HTMLInjectPlugin({
// publicPath: JSON.stringify(repoVersion),
// }),
sentryWebpackPlugin({
org: "sentry",
project: "hyperswitch-react-sdk",
authToken: process.env.SENTRY_AUTH_TOKEN,
url: process.env.SENTRY_URL,
release: {
name: "0.2",
uploadLegacySourcemaps: {
paths: ["dist"],
},
},
}),
],
module: {
rules: [
{
test: /\.css$/i,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [[tailwindcss("./tailwind.config.js")]],
},
},
},
],
},
],
},
entry: entries,
};
};