This repository has been archived by the owner on Jan 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathwebpack.dev.js
108 lines (103 loc) · 2.98 KB
/
webpack.dev.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
const path = require("path");
const fs = require("fs");
const { merge } = require("webpack-merge");
const common = require("./webpack.common.js");
const CopyPlugin = require("copy-webpack-plugin");
const { port, crc } = require("./package.json");
const proxy = require("@redhat-cloud-services/frontend-components-config-utilities/proxy");
const HOST = process.env.HOST || "0.0.0.0";
const PORT = process.env.PORT || port;
const PROTOCOL = process.env.PROTOCOL || "https";
const BETA = false;
const PROXY_USE_AGENT = process.env.PROXY_USE_AGENT === "false" ? false : true;
const config = require("./config/config.json");
const basePublicPath = `${BETA ? "/preview" : ""}/apps`;
const publicPath = `${basePublicPath}/${crc.bundle}/`;
const distDir = path.resolve(__dirname, "./dist/");
module.exports = merge(
common("development", {
publicPath,
beta: BETA,
}),
{
mode: "development",
devtool: "eval-source-map",
devServer: {
host: HOST,
port: PORT,
compress: true,
static: {
// publicPath,
directory: distDir,
},
hot: false,
server: {
type: PROTOCOL,
options: {
ca: process.env.TLS_CA,
key: process.env.TLS_KEY,
cert: process.env.TLS_CERT,
},
},
open: {
target: [
`https://prod.foo.redhat.com:1337${BETA ? "/preview" : ""}/${
crc.bundle
}/`,
],
},
allowedHosts: "all",
devMiddleware: {
publicPath,
writeToDisk: true,
},
client: false,
webSocketServer: false,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods":
"GET, POST, PUT, DELETE, PATCH, OPTIONS",
"Access-Control-Allow-Headers":
"X-Requested-With, content-type, Authorization",
},
...proxy({
port: PORT,
env: BETA ? "prod-beta" : "prod-stable",
useProxy: true,
useAgent: PROXY_USE_AGENT,
proxyVerbose: true,
publicPath,
customProxy: Object.values(config.federatedModules)
.filter((c) => c.proxyTarget && c.fallbackBasePath)
.map((config) => ({
context: (path) => path.includes(config.basePath),
target: config.proxyTarget,
secure: false,
changeOrigin: true,
autoRewrite: true,
ws: true,
pathRewrite: { [`^${config.basePath}`]: "" },
})),
onBeforeSetupMiddleware: ({ chromePath }) => {
const template = fs.readFileSync(`${chromePath}/index.html`, {
encoding: "utf-8",
});
if (!fs.existsSync(distDir)) {
fs.mkdirSync(distDir);
}
fs.writeFileSync(`${distDir}/index.html`, template);
},
}),
},
plugins: [
new CopyPlugin({
patterns: [
{
from: "config/config.json",
to: `config.json`,
},
],
}),
],
}
);