-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.cjs
105 lines (103 loc) · 2.5 KB
/
webpack.config.cjs
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
require('dotenv').config({ override: true })
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const InlineChunkHtmlPlugin = require('inline-chunk-html-plugin')
const path = require('path')
const TerserJSPlugin = require('terser-webpack-plugin')
const webpack = require('webpack')
module.exports = {
devServer: {
static: {
directory: path.join(__dirname, 'public'),
serveIndex: true
},
historyApiFallback: true,
hot: true,
port: process.env.PORT
},
entry: {
app: './index.js'
},
module: {
rules: [
{
test: /\.jsx?$/,
use: [{
loader: 'ts-loader',
options: {
transpileOnly: true
}
}],
exclude: '/node_modules/'
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /\.(?<ext>ico|png|svg|jpg|jpeg|gif|mp4|ogg|webm|woff|woff2|eot|ttf|otf)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[contenthash].[ext]'
}
}
],
exclude: '/node_modules/'
}
]
},
optimization: {
minimizer: [
new TerserJSPlugin({
terserOptions: {
keep_fnames: true,
safari10: true
}
})
]
},
output: {
clean: true,
chunkFilename: '[name].[contenthash].js',
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'public'),
publicPath: process.env.PUBLIC_PATH
},
performance: {
hints: process.env.HINTS,
maxAssetSize: Number(process.env.MAX_ASSET_SIZE),
maxEntrypointSize: Number(process.env.MAX_ENTRYPOINT_SIZE)
},
plugins: [
new webpack.DefinePlugin({
'process.env': JSON.stringify(process.env)
}),
new webpack.EnvironmentPlugin({
SW_CACHE: Math.random().toString(32)
}),
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [
{ from: path.resolve(__dirname, '.assets'), to: '.' }
]
}),
new HtmlWebpackPlugin({
inject: 'body',
template: 'index.html'
}),
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/(app)/]),
new BundleAnalyzerPlugin({
analyzerMode: process.env.ANALYZER_MODE
})
],
resolve: {
extensions: ['.js', '.jsx']
}
}