-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
181 lines (176 loc) · 5.31 KB
/
webpack.config.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
175
176
177
178
179
180
181
const HtmlWebpackPlugin = require('html-webpack-plugin');
const EslintWebpackPlugin = require('eslint-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const webpack = require('webpack');
const DotenvPlugin = require('dotenv-webpack');
const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
require('dotenv').config({
path: './.env',
});
const { DEV_PORT } = process.env;
const config = {
DEV_PORT,
};
const { ModuleFederationPlugin } = webpack.container;
module.exports = {
// Class names are needed for integration testing of the production build
// `testcafe-react-selector` needs these classnames to be present
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
keep_classnames: true,
keep_fnames: true,
sourceMap: true,
},
}),
],
},
entry: './src/index',
devtool: 'cheap-module-source-map',
devServer: {
disableHostCheck: true,
// Enable gzip compression of generated files.
compress: false,
// Silence WebpackDevServer's own logs since they're generally not useful.
// It will still show compile warnings and errors with this setting.
clientLogLevel: 'none',
// By default files from `contentBase` will not trigger a page reload.
watchContentBase: true,
// Enable hot reloading server. It will provide WDS_SOCKET_PATH endpoint
// for the WebpackDevServer client so it can learn when the files were
// updated. The WebpackDevServer client is included as an entry point
// in the webpack development configuration. Note that only changes
// to CSS are currently hot reloaded. JS changes will refresh the browser.
hot: true,
// Use 'ws' instead of 'sockjs-node' on server since we're using native
// websockets in `webpackHotDevClient`.
transportMode: 'ws',
// Prevent a WS client from getting injected as we're already including
// `webpackHotDevClient`.
injectClient: false,
historyApiFallback: true, // React Router
contentBase: path.join(__dirname, 'dist'),
port: config.DEV_PORT,
host: '0.0.0.0',
publicPath: '/',
proxy: {
'/central-ledger': {
// For local testing update `target` to point to your
// locally hosted or port-forwarded `central-ledger` service
target: 'http://localhost:46029',
pathRewrite: { '^/central-ledger': '' },
secure: false,
},
},
},
output: {
path: path.resolve(__dirname, 'dist'),
// It automatically determines the public path from either
// `import.meta.url`, `document.currentScript`, `<script />`
// or `self.location`.
publicPath: 'auto',
// Hash files for cache busting
filename: '[name].[contenthash].js',
assetModuleFilename: "images/[hash][ext][query]",
},
resolve: {
alias: {
react: path.resolve(__dirname, 'node_modules', 'react'),
'react-redux': path.resolve(__dirname, 'node_modules', 'react-redux'),
},
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
extensions: ['.ts', '.tsx', '.js', '.jsx', '.css'],
},
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: [/node_modules/],
use: [
{
loader: 'babel-loader',
options: {
plugins: [
require.resolve('@babel/plugin-proposal-class-properties'),
require.resolve('@babel/plugin-proposal-object-rest-spread'),
require.resolve('babel-plugin-syntax-async-functions'),
require.resolve('@babel/plugin-transform-runtime'),
].filter(Boolean),
},
},
],
},
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
{
test: /\.(s)?css$/i,
use: [
// Creates `style` nodes from JS strings
'style-loader',
// Translates CSS into CommonJS
'css-loader',
// SCSS
'sass-loader',
],
},
{
test: /\.svg$/,
loader: '@svgr/webpack',
options: {
svgoConfig: {
plugins: [{ removeViewBox: false }],
},
},
},
],
},
plugins: [
new CopyPlugin({
patterns: [{ from: 'public/runtime-env.js', to: 'runtime-env.js' }],
}),
new EslintWebpackPlugin({
extensions: ['ts', 'js', 'tsx', 'jsx'],
exclude: [`node_modules`],
}),
new DotenvPlugin({
systemvars: true,
}),
new ForkTsCheckerWebpackPlugin({
eslint: {
files: './src/**/*.{ts,tsx,js,jsx}',
},
}),
new ModuleFederationPlugin({
name: 'reporting_hub_bop_positions_ui',
library: { type: 'var', name: 'reporting_hub_bop_positions_ui' },
filename: 'app.js',
exposes: {
'./App': './src/Injector',
'./Menu': './src/Menu',
},
shared: [
'react',
'react-dom',
'react-redux',
'react-router-dom',
'redux',
'redux-saga',
'history',
'@reduxjs/toolkit',
'@modusbox/react-components',
],
}),
new HtmlWebpackPlugin({
template: './public/index.html',
}),
].filter(Boolean),
};