-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathwebpack.config.js
More file actions
158 lines (145 loc) · 4.54 KB
/
Copy pathwebpack.config.js
File metadata and controls
158 lines (145 loc) · 4.54 KB
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
/**
* © Copyright IBM Corp. 2022, 2025
* SPDX-License-Identifier: Apache-2.0
*/
const fs = require('fs');
const {readFile} = require('fs/promises');
const path = require('path');
const autoprefixer = require('autoprefixer');
const {loginWithApiKey} = require('cp4waiops-ui-bundle-tools');
const targetData = fs.readFileSync('./target.json');
const targetDataJSON = JSON.parse(targetData);
async function loadRoutesFile() {
const routesFile = String(await readFile(path.join(__dirname, './config/routes.json')));
return routesFile.replace(/\{\{BUNDLE_PATH\}\}/g, `bundles/${targetDataJSON.bundleName}/files/${targetDataJSON.bundleName}-bundle.js`);
}
const PORT = process.env.PORT || 9443;
module.exports = async (env) => {
// For insecure mode (no certs)
// if (targetDataJSON.insecure) { // currently no support for cert checking, api validation only
process.removeAllListeners('warning');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
// }
let mconfig;
if (env.WEBPACK_SERVE) {
mconfig = await loginWithApiKey(targetDataJSON.url, targetDataJSON.username, targetDataJSON.apiKey);
console.log('Logged into cluster 📡');
}
return {
mode: 'development',
entry: './src/index.js',
output: {
// this will need to match the route specified in aiopsuiextension cr
filename: `${targetDataJSON.bundleName}-bundle.js`,
path: path.resolve(__dirname, 'dist'),
},
devtool: 'eval-source-map',
devServer: {
setupMiddlewares: (middlewares, devServer) => {
if (!devServer) {
throw new Error('webpack-dev-server is not defined');
}
middlewares.unshift({
name: 'ui-routes',
path: '/aiops/static/uiextensions/configuration',
middleware: async (req, res) => {
const routesFile = JSON.stringify(JSON.parse(await loadRoutesFile()).spec);
res.contentType('application/json');
res.send(routesFile);
},
});
(async () => {
const routesFile = JSON.parse(await loadRoutesFile());
console.log('#################################');
console.log('Access your stuff at these links (note port may differ if existing dev server running. Please see webpack-dev-server logs.):');
console.log(routesFile.spec.routes.map(route => ` ${route.title}: https://127.0.0.1:${PORT}/aiops/${targetDataJSON.tenantId}/page${route.path}`).join('\n'));
console.log('#################################');
console.log('');
})();
console.log(middlewares);
return middlewares;
},
devMiddleware: {
index: true,
publicPath: `/api/p/hdm_custom_panel/${targetDataJSON.tenantId}/bundles/${targetDataJSON.bundleName}/files`
},
server: 'https',
port: PORT,
proxy: env.WEBPACK_SERVE && {
'/': {
target: mconfig.zenUrl,
secure: false,
changeOrigin: true,
onProxyReq: (proxyReq, req, res) => {
proxyReq.setHeader('Cookie', `${req.headers.cookie}; ibm-private-cloud-session=${encodeURIComponent(mconfig.authToken)}`);
},
logLevel: 'debug'
}
},
client: {
overlay: false
}
},
module: {
strictExportPresence: true,
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["@babel/preset-env", "@babel/preset-react"],
},
},
},
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.(sa|sc|c)ss$/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [autoprefixer]
},
sourceMap: true
}
},
'sass-loader'
]
},
{
test: /\.svg$/,
use: [
{
loader: 'svg-sprite-loader',
options: {
name: '[name]',
prefixize: true,
runtimeCompat: true
}
}
]
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: 'file-loader',
},
],
},
],
},
resolve: {
extensions: [".ts", ".js", ".tsx"],
},
}
};