-
Notifications
You must be signed in to change notification settings - Fork 14
/
webpack.common.js
174 lines (172 loc) · 5.49 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const { dependencies, federatedModuleName } = require('./package.json');
delete dependencies.serve; // Needed for nodeshift bug
const ChunkMapper = require('@redhat-cloud-services/frontend-components-config/chunk-mapper');
const CopyPlugin = require('copy-webpack-plugin');
const Dotenv = require('dotenv-webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ReactRefreshTypeScript = require('react-refresh-typescript');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
//const BG_IMAGES_DIRNAME = 'bgimages';
const path = require('path');
const webpack = require('webpack');
const isPatternflyStyles = (stylesheet) =>
stylesheet.includes('@patternfly/react-styles/css/') ||
stylesheet.includes('@patternfly/react-core/');
module.exports = (env, argv) => {
const isProduction = argv && argv.mode === 'production';
const isDevelopment = argv && argv.mode === 'development';
const entryName =
process.env.DEMO_APP === 'true' ? federatedModuleName : 'app';
return {
entry: {
[entryName]: path.resolve(__dirname, 'src', 'index.tsx'),
},
module: {
rules: [
{
test: /\.(tsx|ts|jsx)?$/,
use: [
{
loader: 'ts-loader',
options: {
getCustomTransformers: () => ({
before: [
isDevelopment && new ReactRefreshTypeScript(),
].filter(Boolean),
}),
transpileOnly: isDevelopment, // dev type checking is done via fork-ts-checker-webpack-plugin
},
},
],
},
{
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]',
},
},
],
},
{
test: /\.(json)$/i,
include: path.resolve(__dirname, 'src/locales'),
use: [
{
loader: 'url-loader',
options: {
limit: 5000,
outputPath: 'locales',
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, 'public', 'index.html'),
}),
new Dotenv({
systemvars: true,
silent: true,
}),
// new CopyPlugin({
// patterns: [{ from: './favicon.png', to: 'images' }],
// }),
new CopyPlugin({
patterns: [{ from: './locales', to: 'locales' }],
}),
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: {
'./OpenshiftManagedConnectors': './src/AppFederated',
},
shared: {
...dependencies,
react: {
singleton: true,
requiredVersion: dependencies['react'],
},
'react-dom': {
singleton: true,
requiredVersion: dependencies['react-dom'],
},
'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: dependencies['@rhoas/app-services-ui-shared'],
},
'@scalprum/react-core': { requiredVersion: '*', singleton: true },
'@patternfly/quickstarts': {
singleton: true,
requiredVersion: '*',
},
},
}),
].filter(Boolean),
resolve: {
extensions: ['.js', '.ts', '.tsx', '.jsx'],
plugins: [
new TsconfigPathsPlugin({
configFile: path.resolve(__dirname, './tsconfig.json'),
}),
],
symlinks: false,
cacheWithContext: false,
},
};
};