-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
104 lines (101 loc) · 3.14 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
require('dotenv').config();
const { DefinePlugin } = require('webpack');
const { resolve } = require('path');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
// const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const preparedModulePathsAliases = require('./commons/moduleAliasesResolvers').frontend();
module.exports = (env) => {
// TODO: handle it in better way
process.env.NODE_ENV = env;
const IS_DEVELOPMENT_MODE = env === 'development';
const middleware = IS_DEVELOPMENT_MODE ? require('./dist/src/middleware/middleware-index').default : () => {};
return {
mode: env,
entry: ['react-hot-loader/patch', './src/frontend/index.jsx'],
output: {
filename: 'index.js',
path: resolve(__dirname, './dist/src/frontend'),
},
resolve: {
alias: preparedModulePathsAliases,
},
module: {
rules: [
{
test: /\.(t|j)s(x?)$/,
loader: ['babel-loader', 'eslint-loader', 'prettier-loader'],
resolve: { extensions: ['.ts', '.js', '.tsx', '.jsx'] },
},
{
test: /\.scss$/,
use: [
/* TODO: [build code redundancy] find a way for MUI to pre-export it's styles to external CSS */
// {
// loader: MiniCssExtractPlugin.loader,
// options: {
// hmr: IS_DEVELOPMENT_MODE,
// },
// },
'style-loader',
'css-loader',
'sass-loader',
],
},
],
},
plugins: [
new DefinePlugin({
__IS_DEV_MODE__: JSON.stringify(IS_DEVELOPMENT_MODE)
}),
new ForkTsCheckerWebpackPlugin({
typescript: {
configFile: 'tsconfig.frontend.json',
},
}),
/* TODO: [refactor] improve MUI integration regarding attaching CSS */
// new MiniCssExtractPlugin({
// filename: 'styles.css',
// chunkFilename: '[id].css',
// }),
new HtmlWebpackPlugin({
template: './src/frontend/index.html',
}),
new HtmlWebpackPlugin({
filename: 'embedded/shipment-map.html',
template: './src/frontend/assets/embedded/shipment-map.html',
inject: false,
}),
new CopyPlugin({
patterns: ['shipment-map-3rd-party.js', 'shipment-map-3rd-party.css', 'shipment-map.js'].map((fileName) => ({
from: `./src/frontend/assets/embedded/${fileName}`,
to: `./embedded/${fileName}`,
})),
}),
],
devtool: 'source-map',
devServer: {
publicPath: '/',
watchContentBase: true,
historyApiFallback: true,
before: middleware,
port: process.env.APP_PORT,
hotOnly: true,
liveReload: false,
watchOptions: {
ignored: [
'node_modules',
'dist',
'.*',
'src/middleware',
'src/database',
'test/middleware',
'test/database',
'__mocks__',
'public/images'
].map((path) => resolve(__dirname, path)),
},
},
};
};