This repository has been archived by the owner on Apr 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
88 lines (86 loc) · 2.56 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
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const html = (head, body) => (`
<html lang="en">
<head>
<meta charset="UTF-8">
<!-- Use minimum-scale=1 to enable GPU rasterization -->
<meta
name='viewport'
content='user-scalable=0, initial-scale=1, minimum-scale=1, width=device-width, height=device-height'
/>
<title>Area51</title>
<meta property='og:type' content='website' />
<meta property='og:title' content='Area51' />
<meta property='og:image' content='/icon.png' />
<meta property='og:description' content='A secure file server for HTTP(S).' />
<meta name='Description' content='A secure file server for HTTP(S).'} />
<meta name='robots' content='noindex,nofollow' />
<meta name='theme-color' content='#43d98e' />
<link rel='icon' href='/icon.png' />
<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap' />
<style id="jss-server-side"></style>
<script id="injected"></script>
${head}
</head>
<body>
<div id="app"></div>
${body}
</body>
</html>
`)
const isDev = env => (
(env && env.NODE_ENV === 'development') ||
process.env.NODE_ENV === 'development'
)
module.exports = env => ({
entry: './src/client/index.js',
mode: isDev(env) ? 'development' : 'production',
devtool: isDev(env) ? 'inline-source-map' : undefined,
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [{
test: /\.(c|m)?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-react', ['@babel/preset-env', {
corejs: 3,
targets: 'defaults',
useBuiltIns: 'usage'
}]]
}
}
}]
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
inject: false,
publicPath: '/',
templateContent: ({ htmlWebpackPlugin: { tags } }) => html(tags.headTags, tags.bodyTags)
}),
new CompressionWebpackPlugin(),
new CompressionWebpackPlugin({ filename: '[path][base].br', algorithm: 'brotliCompress' })
],
// Chunk splitting optimization.
optimization: {
moduleIds: 'deterministic',
runtimeChunk: 'single',
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
}
}
})