This repository has been archived by the owner on Dec 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 240
/
webpack.config.dev.js
97 lines (84 loc) · 2.59 KB
/
webpack.config.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
const path = require('path');
const os = require('os');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const { merge } = require('webpack-merge');
const {
getDevConfiguration,
devJscTransformConfiguration,
devRefreshJscTransformConfiguration,
} = require('centreon-frontend/packages/frontend-config/webpack/patch/dev');
const getBaseConfiguration = require('./webpack.config');
const devServerPort = 9090;
const interfaces = os.networkInterfaces();
const externalInterface = Object.keys(interfaces).find(
(interfaceName) =>
!interfaceName.includes('docker') &&
interfaces[interfaceName][0].family === 'IPv4' &&
interfaces[interfaceName][0].internal === false &&
!process.env.IS_STATIC_PORT_FORWARDED,
);
const devServerAddress = externalInterface
? interfaces[externalInterface][0].address
: 'localhost';
const publicPath = `http://${devServerAddress}:${devServerPort}/static/`;
const isServeMode = process.env.WEBPACK_ENV === 'serve';
const isDevelopmentMode = process.env.WEBPACK_ENV === 'development';
const plugins = isServeMode ? [new ReactRefreshWebpackPlugin()] : [];
const output =
isServeMode || isDevelopmentMode
? {
publicPath,
}
: {};
const getStaticDirectoryPath = (moduleName) =>
`${__dirname}/www/modules/${moduleName}/static`;
const modules = [
{
getDirectoryPath: getStaticDirectoryPath,
name: 'centreon-license-manager',
},
{
getDirectoryPath: getStaticDirectoryPath,
name: 'centreon-autodiscovery-server',
},
{ getDirectoryPath: getStaticDirectoryPath, name: 'centreon-bam-server' },
{
getDirectoryPath: getStaticDirectoryPath,
name: 'centreon-augmented-services',
},
{
getDirectoryPath: () => `${__dirname}/www/modules/centreon-map4-web-client`,
name: 'centreon-map4-web-client',
},
];
module.exports = merge(
getBaseConfiguration(
isServeMode
? devRefreshJscTransformConfiguration
: devJscTransformConfiguration,
),
getDevConfiguration(),
{
devServer: {
compress: true,
headers: { 'Access-Control-Allow-Origin': '*' },
host: '0.0.0.0',
hot: true,
port: devServerPort,
static: modules.map(({ name, getDirectoryPath }) => ({
directory: path.resolve(getDirectoryPath(name)),
publicPath,
watch: true,
})),
},
output,
plugins,
resolve: {
alias: {
'@mui/material': path.resolve('./node_modules/@mui/material'),
dayjs: path.resolve('./node_modules/dayjs'),
'react-router-dom': path.resolve('./node_modules/react-router-dom'),
},
},
},
);