-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
125 lines (124 loc) · 3.59 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
const HtmlWebpackPlugin = require('html-webpack-plugin');
// TODO: probably only need `yarn install assert`
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
const { ModuleFederationPlugin } = require('webpack').container;
const { DefinePlugin } = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const path = require('path');
module.exports = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
keep_classnames: true,
keep_fnames: true,
sourceMap: true,
},
}),
],
},
entry: './src/index',
devtool: '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: 3000,
publicPath: '/',
proxy: {
'/api': {
target: 'http://localhost:8000',
secure: false,
},
},
},
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: '/', // Where it's going to be expected to be published for being externally loaded
},
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: [
{
enforce: 'pre',
test: /\.(ts|js)x?$/,
use: 'eslint-loader',
exclude: [/node_modules/, /integration_test/, /tests/],
},
{
test: /\.(ts|js)x?$/,
use: 'ts-loader',
exclude: [/node_modules/, /integration_test/, /tests/],
},
{
test: /\.css$/i,
use: [
// Creates `style` nodes from JS strings
'style-loader',
// Translates CSS into CommonJS
'css-loader',
],
},
{
test: /\.(png|jpg|gif)$/i,
use: [
{
loader: 'url-loader',
},
],
},
],
},
plugins: [
new NodePolyfillPlugin(),
new ModuleFederationPlugin({
name: 'app',
library: { type: 'var', name: 'app' },
filename: 'app.js',
exposes: {
'./App': './src/App',
},
shared: [
'react',
'react-dom',
'react-redux',
'react-router-dom',
'redux',
'redux-saga',
'history',
'@reduxjs/toolkit',
'@modusbox/modusbox-ui-components',
],
}),
new HtmlWebpackPlugin({
template: './public/index.html',
}),
],
};