This repository has been archived by the owner on Dec 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
175 lines (169 loc) · 5.92 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
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const Dotenv = require('dotenv-webpack')
const FaviconsWebpackPlugin = require('favicons-webpack-plugin')
const WorkboxPlugin = require('workbox-webpack-plugin')
const generate = require('generate-file-webpack-plugin')
const fs = require('fs')
const TerserPlugin = require('terser-webpack-plugin')
const isProduction =
process.argv[process.argv.indexOf('--mode') + 1] === 'production'
function getInfos(envValues) {
const appPackage = JSON.parse(
fs.readFileSync(path.resolve(__dirname, 'package.json')).toString()
)
const info = {
hosted_by: envValues.HOSTED_BY || '',
hosted_by_name: envValues.HOSTED_BY_NAME || '',
version: appPackage.version,
country: envValues.COUNTRY || '',
backend_addr: envValues.REACT_APP_NYM_CLIENT_SERVER || '',
}
return JSON.stringify(info)
}
module.exports = (env) => {
let pluginList = [
new HtmlWebpackPlugin({
title: 'Pastenym',
description: 'Share text anonymously',
public_url: 'https://pastenym.ch',
template: path.resolve(__dirname, './src/index.html'), // template file
filename: 'index.html', // output file
}),
new FaviconsWebpackPlugin({
logo: './public/logo.svg',
favicons: {
appName: 'Pastenym',
appDescription: 'Share text anonymously',
developerName: 'No Trust Verify',
developerURL: null, // prevent retrieving from the nearest package.json
background: '#FFFFFF',
theme_color: '#e8e5e1',
icons: {
coast: false,
yandex: false,
},
inject: true,
},
}),
new CleanWebpackPlugin(),
new Dotenv(),
new WorkboxPlugin.GenerateSW({
// these options encourage the ServiceWorkers to get in there fast
// and not allow any straggling "old" SWs to hang around
clientsClaim: true,
skipWaiting: true,
maximumFileSizeToCacheInBytes: 90000000,
}),
]
// process.env contains the env variables from upstream (OS, docker, you-name-it,…)
// Parse the .env file and add variables to the process.env
var _ = require('dotenv').config({ path: __dirname + '/.env' })
// If instance owner does not want to expose the info.json file, we do not generate it
if (
process.env.hasOwnProperty('GENERATE_INFO_FILE_ABOUT_INSTANCE') &&
process.env.GENERATE_INFO_FILE_ABOUT_INSTANCE.toLowerCase() === 'true'
) {
console.log('Will generate info.json file as allowed.')
// Using generate-file-webpack-plugin: works but old!
pluginList.push(
generate({
file: 'info.json',
content: getInfos(process.env),
})
)
}
return {
entry: {
main: path.resolve(__dirname, './src/index.js'),
app: path.resolve(__dirname, './src/UserInput.js'),
app: path.resolve(__dirname, './src/Texts.js'),
//worker: path.resolve(__dirname, './src/worker.js'),
//bootstrap: path.resolve(__dirname, './src/bootstrap.js')
},
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].bundle.js',
},
mode: 'production',
plugins: pluginList,
module: {
rules: [
// JavaScript
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
// Images
{
test: /\.(?:ico|gif|png|jpg|jpeg)$/i,
type: 'asset/resource',
generator: {
filename: 'images/[name]-[hash][ext]',
},
},
{
test: /\.(png|jpg)$/i,
type: 'asset/resource',
generator: {
filename: 'images/[name]-[hash][ext]',
},
},
// Fonts and SVGs
{
test: /\.(woff(2)?|eot|ttf|otf|svg|)$/,
type: 'asset/inline',
},
// CSS, PostCSS, and Sass
{
test: /\.(scss|css)$/,
use: [
'style-loader',
'css-loader',
'postcss-loader',
'sass-loader',
],
},
],
// According: https://github.com/bitwiseshiftleft/sjcl/issues/345#issuecomment-345640858
noParse: [/sjcl\.js$/],
},
devServer: {
historyApiFallback: true,
static: {
directory: path.join(__dirname, './dist'),
},
open: false,
compress: false,
port: 8081,
hot: false,
liveReload: true,
},
experiments: {
syncWebAssembly: true,
topLevelAwait: true,
},
performance: {
maxEntrypointSize: 20012000,
maxAssetSize: 200212000,
},
optimization: {
minimize: true,
minimizer: [new TerserPlugin()],
splitChunks: {
chunks: 'all',
minSize: 10000,
maxSize: 100000,
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
},
},
},
},
}
}