forked from erikvullings/hpet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
199 lines (196 loc) · 6.27 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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackPwaManifest = require('webpack-pwa-manifest');
const HtmlWebpackTagsPlugin = require('html-webpack-tags-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const WorkboxPlugin = require('workbox-webpack-plugin');
module.exports = (env) => {
console.log(JSON.stringify(env, null, 2));
const isProduction = env.production;
const outputPath = path.resolve(__dirname, isProduction ? 'docs' : 'dist');
const publicPath = isProduction ? 'https://tno.github.io/hei/' : '/';
const mode = isProduction ? 'production' : 'development';
console.log(`Running in ${mode} mode, path ${publicPath}, output directed to ${outputPath}.`);
return {
mode,
entry: './src/app.ts',
devtool: isProduction ? 'source-map' : 'inline-source-map',
devServer: {
port: isProduction ? 3377 : 3378,
},
plugins: [
new webpack.DefinePlugin({
'process.env': JSON.stringify({ NODE_ENV: mode, PUBLIC_URL: publicPath }),
}),
new HtmlWebpackPlugin({
title: 'Human Performance Augmentation Dashboard',
favicon: './src/favicon.ico',
meta: {
viewport: 'width=device-width, initial-scale=1',
'': { 'http-equiv': 'Permissions-Policy', content: 'interest-cohort=(), user-id=()' },
'og:title': 'Human Performance Augmentation Dashboard',
'og:description': 'A database with known interventions to enhance human performance.',
'og:url': 'https://tno.github.io/hei/',
'og:site_name': 'Human Performance Augmentation Dashboard',
'og:image:alt': 'Human Performance Augmentation Dashboard',
'og:image': './src/assets/logo.svg',
'og:image:type': 'image/svg',
'og:image:width': '200',
'og:image:height': '200',
},
}),
new WebpackPwaManifest({
name: 'Human Performance Augmentation Dashboard',
short_name: "H'POD",
// start_url: '.',
// scope: '/',
description: 'A database with known interventions to enhance human performance.',
background_color: '#ffffff',
theme_color: '#ffffff',
crossorigin: null, //can be null, use-credentials or anonymous
display: 'standalone',
lang: 'en',
categories: ['government', 'personalization', 'productivity', 'utitlies'],
icons: [
{
src: path.resolve('src/assets/android-chrome-512x512.png'),
sizes: [96, 128, 192, 256, 384, 512], // multiple sizes
},
// {
// src: path.resolve('src/assets/large-icon.png'),
// size: '1024x1024', // you can also use the specifications pattern
// },
// {
// src: path.resolve('src/assets/maskable-icon.png'),
// size: '1024x1024',
// purpose: 'maskable',
// },
],
}),
isProduction
? new WorkboxPlugin.GenerateSW({
// these options encourage the ServiceWorkers to get in there fast
// and not allow any straggling "old" SWs to hang around
maximumFileSizeToCacheInBytes: 5 * 1024 * 1024,
clientsClaim: true,
skipWaiting: true,
exclude: [/\.map$/, /manifest.*\.json$/],
})
: undefined,
new HtmlWebpackTagsPlugin({
metas: [
{
attributes: {
property: 'og:title',
content: "H'POD, Human Performance Augmentation Dashboard",
},
},
{
attributes: {
property: 'og:description',
content:
'A database where you can look for means to enhance human performance, e.g. by using drugs, specific training or other means.',
},
},
{
attributes: {
property: 'og:url',
content: publicPath,
},
},
{
path: './src/assets/logo.svg',
attributes: {
property: 'og:image',
},
},
{
attributes: { property: 'og:locale', content: 'en_UK' },
},
{
attributes: { property: 'og:site_name', content: 'HEI' },
},
{
attributes: {
property: 'og:image:alt',
content: 'Human Performance Augmentation Dashboard ',
},
},
{
attributes: {
property: 'og:image:type',
content: 'image/svg',
},
},
{
attributes: {
property: 'og:image:width',
content: '200',
},
},
{
attributes: {
property: 'og:image:height',
content: '200',
},
},
],
}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
}),
].filter((p) => p),
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/,
},
// {
// test: /\.css$/i,
// use: ['style-loader', 'css-loader'],
// },
{
test: /\.(png|svg|jpg|jpeg|gif|webp)$/i,
type: 'asset/resource',
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/resource',
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
// {
// test: /\.(csv|tsv)$/i,
// use: ['csv-loader'],
// },
// {
// test: /\.xml$/i,
// use: ['xml-loader'],
// },
],
},
resolve: {
extensions: ['.ts', '.js'],
},
optimization: {
minimizer: [
// For webpack@5 you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line
// `...`,
new CssMinimizerPlugin(),
],
},
output: {
filename: '[name].bundle.js',
path: outputPath,
publicPath,
clean: true,
},
};
};