This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.common.js
160 lines (158 loc) · 5.06 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
/* eslint-disable */
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const Dotenv = require('dotenv-webpack');
const {dependencies, federatedModuleName, peerDependencies} = require("./package.json");
delete dependencies.serve; // Needed for nodeshift bug
const webpack = require('webpack');
const ChunkMapper = require('@redhat-cloud-services/frontend-components-config/chunk-mapper');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const isPatternflyStyles = (stylesheet) => stylesheet.includes('@patternfly/react-styles/css/') || stylesheet.includes('@patternfly/react-core/');
module.exports = (env, argv) => {
const isProduction = argv && argv.mode === 'production';
return {
entry: {
app: path.resolve(__dirname, 'src/bootstrap', 'index.tsx')
},
module: {
rules: [
{
test: /\.(tsx|ts|jsx)?$/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: false,
experimentalWatchApi: true,
}
}
]
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
include: (stylesheet => !isPatternflyStyles(stylesheet)),
sideEffects: true,
},
{
test: /\.css$/,
include: isPatternflyStyles,
use: ['null-loader'],
sideEffects: true
},
{
test: /\.(ttf|eot|woff|woff2)$/,
use: {
loader: 'file-loader',
options: {
limit: 5000,
name: isProduction ? '[contenthash:8].[ext]' : '[name].[ext]',
}
}
},
{
test: /\.(svg|jpg|jpeg|png|gif)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 5000,
name: isProduction ? '[contenthash:8].[ext]' : '[name].[ext]',
}
}
]
},
]
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: "auto"
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src/public', 'index.html')
}),
new Dotenv({
systemvars: true,
silent: true
}),
new CopyPlugin({
patterns: [
{from: './src/public/favicon.png', to: 'images'},
]
}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash:8].css',
chunkFilename: '[contenthash:8].css',
insert: (linkTag) => {
const preloadLinkTag = document.createElement('link')
preloadLinkTag.rel = 'preload'
preloadLinkTag.as = 'style'
preloadLinkTag.href = linkTag.href
document.head.appendChild(preloadLinkTag)
document.head.appendChild(linkTag)
}
}),
new ChunkMapper({
modules: [
federatedModuleName
]
}),
new webpack.container.ModuleFederationPlugin({
name: federatedModuleName,
filename: `${federatedModuleName}${isProduction ? '.[chunkhash:8]' : ''}.js`,
exposes: {
"./ServiceRegistry":"./src/ServiceRegistry/ServiceRegistryFederated",
"./ApicurioRegistry":"./src/ServiceRegistry/ApicurioRegistryFederated",
"./ServiceRegistryMapping":"./src/ServiceRegistry/components/ServiceRegistryMapping/ServiceRegistryMappingFederated"
},
shared: {
...dependencies,
...peerDependencies,
react: {
singleton: true,
requiredVersion: peerDependencies["react"],
},
"react-dom": {
singleton: true,
requiredVersion: peerDependencies["react-dom"],
},
"react-i18next": {
singleton: true,
requiredVersion: peerDependencies["react-i18next"],
},
"react-router-dom": {
singleton: false, // consoledot needs this to be off to be able to upgrade the router to v6. We don't need this to be a singleton, so let's keep this off
requiredVersion: dependencies["react-router-dom"],
},
"@rhoas/app-services-ui-shared": {
singleton: true,
requiredVersion: peerDependencies["@rhoas/app-services-ui-shared"]
},
"@rhoas/app-services-ui-components": {
singleton: true,
requiredVersion:
peerDependencies["@rhoas/app-services-ui-components"],
},
'@patternfly/quickstarts': {
singleton: true,
requiredVersion: '*',
},
},
})
],
resolve: {
extensions: ['.js', '.ts', '.tsx', '.jsx'],
plugins: [
new TsconfigPathsPlugin({
configFile: path.resolve(__dirname, './tsconfig.json')
})
],
symlinks: false,
cacheWithContext: false
},
}
};