-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.cjs
224 lines (215 loc) · 7.24 KB
/
webpack.config.cjs
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
const { ModuleFederationPlugin } = require('webpack').container
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const { dependencies } = require('./package.json')
const { hawtioBackend } = require('@hawtio/backend-middleware')
const path = require('path')
const bodyParser = require('body-parser')
const publicPath = '/hawtio'
const outputPath = path.resolve(__dirname, 'build')
module.exports = (_, args) => {
const isProduction = args.mode === 'production'
return {
entry: './src/index',
plugins: [
new ModuleFederationPlugin({
// The container name corresponds to 'scope' passed to HawtioPlugin
name: 'samplePlugin',
filename: 'remoteEntry.js',
// The key in `exposes` corresponds to 'remote' passed to HawtioPlugin
exposes: {
'./plugin': './src/sample-plugin',
},
shared: {
...dependencies,
react: {
singleton: true,
requiredVersion: dependencies['react'],
},
'react-dom': {
singleton: true,
requiredVersion: dependencies['react-dom'],
},
'react-router-dom': {
singleton: true,
requiredVersion: dependencies['react-router-dom'],
},
'@hawtio/react': {
singleton: true,
requiredVersion: dependencies['@hawtio/react'],
},
},
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'public/index.html'),
// Trailing slash is really important for proper base path handling
base: publicPath + '/',
publicPath,
}),
new CopyWebpackPlugin({
patterns: [
{
from: '**/*',
to: outputPath,
context: 'public/',
globOptions: {
gitignore: true,
ignore: ['**/index.html', '**/favicon.ico'],
},
noErrorOnMissing: true,
},
],
}),
],
output: {
clean: true,
path: outputPath,
publicPath: 'auto',
filename: isProduction ? 'static/js/[name].[contenthash:8].js' : 'static/js/bundle.js',
chunkFilename: isProduction ? 'static/js/[name].[contenthash:8].chunk.js' : 'static/js/[name].chunk.js',
assetModuleFilename: 'static/media/[name].[hash][ext]',
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: 'swc-loader',
options: {
jsc: {
parser: {
syntax: 'typescript',
},
},
},
},
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource',
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
},
{
test: /\.md$/i,
type: 'asset/source',
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
},
ignoreWarnings: [
// For suppressing sourcemap warnings coming from some dependencies
/Failed to parse source map/,
/Critical dependency: the request of a dependency is an expression/,
],
// For plugin development
devServer: {
port: 3001,
static: path.join(__dirname, 'public'),
historyApiFallback: {
// Needed to fallback to bundled index instead of public/index.html template
index: publicPath,
},
devMiddleware: { publicPath },
setupMiddlewares: (middlewares, devServer) => {
devServer.app.use(bodyParser.json())
// Redirect / or /hawtio to /hawtio/
if (publicPath && publicPath !== '/') {
devServer.app.get('/', (_, res) => res.redirect(`${publicPath}/`))
devServer.app.get(`${publicPath}$`, (_, res) => res.redirect(`${publicPath}/`))
}
const username = 'developer'
const proxyEnabled = true
const plugin = [
// Uncomment to test remote plugins loading
/*
{
url: 'http://localhost:3001',
scope: 'samplePlugin',
module: './plugin',
},
*/
]
// Keycloak
const keycloakEnabled = false
const keycloakClientConfig = {
realm: 'hawtio-demo',
clientId: 'hawtio-client',
url: 'http://localhost:18080/',
jaas: false,
pkceMethod: 'S256',
}
// Hawtio backend API mock
let login = true
devServer.app.get(`${publicPath}/user`, (_, res) => {
login ? res.send(`"${username}"`) : res.sendStatus(403)
})
devServer.app.post(`${publicPath}/auth/login`, (req, res) => {
// Test authentication throttling with username 'throttled'
const { username } = req.body
if (username === 'throttled') {
res.append('Retry-After', 10) // 10 secs
res.sendStatus(429)
return
}
login = true
res.send(String(login))
})
devServer.app.get(`${publicPath}/auth/logout`, (_, res) => {
login = false
res.redirect(`${publicPath}/login`)
})
const oidcEnabled = false
const oidcConfig = {
method: 'oidc',
provider: 'https://login.microsoftonline.com/11111111-2222-3333-4444-555555555555/v2.0',
client_id: '66666666-7777-8888-9999-000000000000',
response_mode: 'fragment',
scope: 'openid email profile api://hawtio-server/Jolokia.Access',
redirect_uri: 'http://localhost:3000/hawtio/',
code_challenge_method: 'S256',
prompt: 'login',
}
devServer.app.get(`${publicPath}/auth/config`, (_, res) => {
res.type('application/json')
if (oidcEnabled) {
res.send(JSON.stringify(oidcConfig))
} else {
res.send('{}')
}
})
devServer.app.get(`${publicPath}/auth/config/session-timeout`, (_, res) => {
res.type('application/json')
res.send('{}')
})
devServer.app.get(`${publicPath}/proxy/enabled`, (_, res) => res.send(String(proxyEnabled)))
devServer.app.get(`${publicPath}/plugin`, (_, res) => res.send(JSON.stringify(plugin)))
devServer.app.get(`${publicPath}/keycloak/enabled`, (_, res) => res.send(String(keycloakEnabled)))
devServer.app.get(`${publicPath}/keycloak/client-config`, (_, res) =>
res.send(JSON.stringify(keycloakClientConfig)),
)
devServer.app.get(`${publicPath}/keycloak/validate-subject-matches`, (_, res) => res.send('true'))
// Hawtio backend middleware should be run before other middlewares (thus 'unshift')
// in order to handle GET requests to the proxied Jolokia endpoint.
middlewares.unshift({
name: 'hawtio-backend',
path: `${publicPath}/proxy`,
middleware: hawtioBackend({
// Uncomment it if you want to see debug log for Hawtio backend
logLevel: 'debug',
}),
})
return middlewares
},
},
}
}