-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
113 lines (109 loc) · 3.09 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
const path = require('path');
const webpack = require('webpack');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const isDev = process.env.NODE_ENV === 'development';
const makeConfig = (env) => {
const targetEnv = env?.legacy || env === 'legacy' ? 'legacy' : 'modern';
return {
mode: isDev ? 'development' : 'production',
name: `config:${targetEnv}`,
target: `browserslist:${targetEnv}`,
entry: {
app: './src/web-entry.tsx'
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json', '.scss'],
alias: {
...(targetEnv === 'modern' ? { url: 'native-url' } : {})
}
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: `[name].js`,
assetModuleFilename: `[name][ext]`,
publicPath: '/'
},
module: {
rules: [
{
test: /\.png/,
type: 'asset/resource'
},
{
test: /\.ts?/,
exclude: [/node_modules/],
use: {
loader: 'babel-loader',
options: {
envName: [targetEnv, isDev && 'development']
.filter(Boolean)
.join(' ')
.trim()
}
}
},
{
test: /\.scss?/,
use: [
isDev ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
mode: 'local',
localIdentName: '[local]--[hash:base64:5]'
},
importLoaders: 1,
sourceMap: isDev
}
},
'postcss-loader',
{
loader: 'sass-loader',
options: { sourceMap: isDev }
}
]
}
]
},
plugins: [
isDev && new webpack.HotModuleReplacementPlugin(),
isDev && new ReactRefreshWebpackPlugin(),
new ForkTsCheckerWebpackPlugin(),
new webpack.DefinePlugin({
API: JSON.stringify('https://607c19c267e6530017573aa0.mockapi.io'),
IMAGE_API: JSON.stringify('http://api.lightning-fast.pwa/data/images')
}),
new HTMLWebpackPlugin({
inject: true,
favicon: path.join(__dirname, './src/assets/favicon.png'),
template: path.join(__dirname, './src/templates/template.html')
}),
!isDev &&
new MiniCssExtractPlugin({
filename: `[name].css`
})
].filter(Boolean),
optimization: {
minimize: false
},
performance: {
hints: 'warning'
},
stats: 'normal',
...(isDev && {
devtool: 'eval-cheap-module-source-map',
devServer: {
contentBase: path.join(__dirname, 'dist'),
hot: true,
historyApiFallback: true,
port: 3000,
overlay: true
}
})
};
};
module.exports = makeConfig;