-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.config.babel.js
170 lines (158 loc) · 4.76 KB
/
webpack.config.babel.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
import 'dotenv/config'
import path from 'path'
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin'
import { CleanWebpackPlugin } from 'clean-webpack-plugin'
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
import { GitRevisionPlugin } from 'git-revision-webpack-plugin'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import TerserPlugin from 'terser-webpack-plugin'
import { v4 as uuidv4 } from 'uuid'
import webpack from 'webpack'
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
const buildReport = process.env.BUILD_REPORT === 'true'
const config = {
mode: process.env.NODE_ENV || 'development',
path: path.resolve(__dirname, 'dist/client'),
}
const isDevelopment = process.env.NODE_ENV !== 'production'
const gitRevisionPlugin = config.mode === 'production' ? null : new GitRevisionPlugin()
const fontCssFileName = 'woff2.css'
const port = process.env.WEB_APP_PORT ? process.env.WEB_APP_PORT : 9000
const plugins = [
...(gitRevisionPlugin ? [gitRevisionPlugin] : []),
new MiniCssExtractPlugin({ filename: 'style/styles-[fullhash].css' }),
new HtmlWebpackPlugin({ template: './web-resources/index.html' }),
new webpack.DefinePlugin({
__DEV__: isDevelopment,
__BUST__: `"${uuidv4()}"`,
__GOOGLE_API__: JSON.stringify(process.env.FRA_GOOGLE_API),
__GOOGLE_MAPS_API_KEY__: JSON.stringify(process.env.FRA_GOOGLE_MAPS_API_KEY),
__APPLICATION_VERSION__: gitRevisionPlugin
? JSON.stringify(gitRevisionPlugin.version())
: JSON.stringify(process.env.APP_VERSION),
__BUILD_DATE__: JSON.stringify(new Date().toISOString().split('T')[0]),
__URL_STATISTICAL_FACTSHEETS__: JSON.stringify(process.env.URL_STATISTICAL_FACTSHEETS),
}),
new CleanWebpackPlugin(),
]
if (isDevelopment) {
plugins.push(new webpack.HotModuleReplacementPlugin())
plugins.push(new ReactRefreshWebpackPlugin())
}
if (buildReport) {
plugins.push(new BundleAnalyzerPlugin())
}
const appConfig = {
mode: config.mode,
devtool: 'source-map',
entry: ['./src/client/Main.tsx'],
resolve: {
extensions: ['.webpack-loader.js', '.web-loader.js', '.loader.js', '.js', '.jsx', '.ts', '.tsx'],
alias: {
i18n: path.resolve(__dirname, 'src/i18n/'),
client: path.resolve(__dirname, 'src/client/'),
meta: path.resolve(__dirname, 'src/meta/'),
server: path.resolve(__dirname, 'src/server/'),
test: path.resolve(__dirname, 'src/test/'),
tools: path.resolve(__dirname, 'src/tools/'),
utils: path.resolve(__dirname, 'src/utils/'),
},
},
output: {
filename: 'js/bundle-[fullhash].js',
path: config.path,
publicPath: '/',
},
devServer: {
hot: true,
allowedHosts: ['fra-data.local'],
proxy: [
{
// Proxy all server-served routes:
context: ['/auth', '/img', '/css', '/video', '/api', '/definitions'],
target: process.env.APP_URI ?? `http://localhost:9001`,
},
{
context: ['/socket.io'],
target: process.env.APP_URI ?? `http://localhost:9001`, // .replace('http','ws'),
ws: true,
},
],
compress: false,
port,
historyApiFallback: true,
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'babel-loader',
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
plugins: isDevelopment ? [require.resolve('react-refresh/babel')] : [],
},
},
],
},
{
test: /\.(less|css)$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
options: {
url: false,
import: {
filter: (url) => {
// Don't handle font css file import
if (url.includes(fontCssFileName)) {
return false
}
return true
},
},
},
},
'less-loader',
],
},
{
test: /\.s[ac]ss$/i,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
url: false,
},
},
{
loader: 'sass-loader',
options: {
implementation: require.resolve('sass'),
sassOptions: {
outputStyle: 'compressed',
},
},
},
],
},
],
},
plugins,
stats: { children: false },
optimization: {
minimize: !isDevelopment,
minimizer: [new TerserPlugin(), new CssMinimizerPlugin()],
},
}
export default appConfig