path:
/webpack.config.js
3.74 KB | plain
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
import path from 'path';
import { fileURLToPath } from 'url';
import webpack from 'webpack';
import CopyPlugin from 'copy-webpack-plugin';
import WorkboxPlugin from 'workbox-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import HtmlWebpackInjectPreload from '@principalstudio/html-webpack-inject-preload';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
import { GitRevisionPlugin } from 'git-revision-webpack-plugin';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const dist = path.resolve(__dirname, 'dist');
const gitRevisionPlugin = new GitRevisionPlugin();
const isDevServer = process.env.WEBPACK_SERVE;
const appName = "Öffisearch";
export default {
mode: 'production',
entry: './src/main.js',
output: {
path: dist,
filename: "[name].js"
},
module: {
rules: [{
test: /\.css$/,
use: [
isDevServer ? 'style-loader' : MiniCssExtractPlugin.loader, 'css-loader',
],
}],
},
performance: {
hints: false,
},
optimization: {
minimize: true,
minimizer: [
`...`,
new CssMinimizerPlugin(),
],
},
devServer: {
static: dist,
client: {
progress: true,
},
proxy: [{
context: [ '/hafas', '/db' ],
target: 'https://oeffi.katja.wtf',
changeOrigin: true,
}],
},
plugins: [
new webpack.NormalModuleReplacementPlugin(/(node:|https-proxy-agent|cross-fetch|db-hafas-stations)/, (resource) => {
const newRequest = {
'node:buffer': 'buffer',
'node:assert': 'assert',
'https-proxy-agent': path.resolve(__dirname, 'src/shim/https-proxy-agent.js'),
'cross-fetch': path.resolve(__dirname, 'src/shim/cross-fetch.js'),
'db-hafas-stations': path.resolve(__dirname, 'src/shim/db-hafas-stations.js'),
}[resource.request];
if (newRequest) {
resource.request = newRequest;
}
}),
new webpack.DefinePlugin({
'process.env': '{}',
'isDevServer': isDevServer,
'APPNAME': JSON.stringify(appName),
'VERSION': JSON.stringify(process.env.GIT_VERSION ? process.env.GIT_VERSION : gitRevisionPlugin.version()),
'COMMIT': JSON.stringify(process.env.GIT_COMMIT ? process.env.GIT_COMMIT : gitRevisionPlugin.commithash()),
'COMMITDATE': JSON.stringify(process.env.GIT_COMMITDATE ? process.env.GIT_COMMITDATE : gitRevisionPlugin.lastcommitdatetime()),
}),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
new CopyPlugin({
patterns: [
{ from: 'src/assets/favicon.png', },
{ from: 'src/assets/manifest.json', },
],
}),
new HtmlWebpackPlugin({
title: appName,
favicon: './src/assets/favicon.svg',
scriptLoading: 'module',
hash: true,
inject: 'body',
template: './src/assets/index.html',
minify: {
collapseWhitespace: true,
keepClosingSlash: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
minifyCSS: true,
}
}),
new HtmlWebpackInjectPreload({
files: [{
match: /.*\.js$/,
attributes: {as: 'script'},
}],
}),
].concat(isDevServer ? [] : [
new MiniCssExtractPlugin(),
new WorkboxPlugin.GenerateSW({
clientsClaim: true,
skipWaiting: true,
}),
]),
resolve: {
modules: [
'node_modules',
'node_modules/hafas-client/node_modules',
],
fallback: {
'buffer': 'buffer',
'assert': 'assert',
'https': path.resolve(__dirname, './src/shim/https.js'),
'crypto': path.resolve(__dirname, './src/shim/crypto.js'),
'stream': false,
'http': false,
'url': false,
'tls': false,
'net': false,
}
}
};