-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.ts
92 lines (88 loc) · 2.59 KB
/
webpack.config.ts
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
/// <reference types="webpack-dev-server" />
import { CleanWebpackPlugin as CleanPlugin } from 'clean-webpack-plugin'
import CSPHTMLPlugin from 'csp-html-webpack-plugin'
import HTMLPlugin from 'html-webpack-plugin'
import path from 'path'
import type { Configuration } from 'webpack'
import { emitAssetLinks } from './scripts/asset-links'
import { emitHeaders } from './scripts/headers'
import { emitRedirects } from './scripts/redirects'
import { emitRobotsTXT } from './scripts/robots'
const ASSETS_FILE = path.join(__dirname, 'assets')
const asset = (...paths: string[]) => path.join(ASSETS_FILE, ...paths)
const configure: Configuration = {
context: __dirname,
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: {
'react': 'preact/compat',
'react-dom': 'preact/compat',
'react/jsx-runtime': 'preact/jsx-runtime',
},
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].[chunkhash].js',
},
module: {
rules: [
{
test: /\.tsx?$/,
use: [require.resolve('babel-loader'), require.resolve('ts-loader')],
},
{
type: 'asset/inline',
include: [path.join(__dirname, 'src', 'components', 'assets')],
},
],
},
plugins: [
new HTMLPlugin({
title: 'eSIM QRCode Portal',
favicon: asset('favicon.png'),
template: asset('template.ejs'),
inject: 'body',
meta: buildMeta({
description: 'This is the eSIM QRCode portal page',
viewport: { 'width': 'device-width', 'initial-scale': 1.0 },
robots: ['noindex', 'nofollow'],
google: ['notranslate', 'nopangereadaloud'],
}),
}),
new CSPHTMLPlugin({
'style-src': ["'unsafe-inline'"],
'img-src': ["'self'", 'blob:', 'data:'],
}),
new CleanPlugin({
cleanOnceBeforeBuildPatterns: [path.join(__dirname, 'dist')],
}),
emitAssetLinks(),
emitRedirects(),
emitHeaders(),
emitRobotsTXT(),
],
devServer: {
server: 'https',
compress: true,
hot: false,
liveReload: false,
client: false,
historyApiFallback: {
rewrites: [{ from: /./, to: '/index.html' }],
},
},
}
function buildMeta(records: Record<string, string | string[] | object>) {
const entries = Object.entries(records).map(([name, value]): [string, string] => {
if (Array.isArray(value)) {
value = value.join(',')
} else if (typeof value === 'object') {
value = Object.entries(value)
.map((entry) => entry.join('='))
.join(',')
}
return [name, value]
})
return Object.fromEntries(entries)
}
export default configure