Skip to content
This repository was archived by the owner on Dec 21, 2024. It is now read-only.

Commit d6216b5

Browse files
sven-hashcgi-bin
andauthored
service worker (#106)
Co-authored-by: cgi-bin <[email protected]>
1 parent c1bff67 commit d6216b5

File tree

2 files changed

+152
-149
lines changed

2 files changed

+152
-149
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pastenym",
3-
"version": "3.0.3",
3+
"version": "3.0.4",
44
"homepage": "http://pastenym.ch/",
55
"private": true,
66
"main": "index.js",

webpack.config.js

Lines changed: 151 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -6,167 +6,170 @@ const FaviconsWebpackPlugin = require('favicons-webpack-plugin')
66
const WorkboxPlugin = require('workbox-webpack-plugin')
77
const generate = require('generate-file-webpack-plugin')
88
const fs = require('fs')
9-
const TerserPlugin = require("terser-webpack-plugin");
9+
const TerserPlugin = require('terser-webpack-plugin')
1010

11-
const isProduction = process.argv[process.argv.indexOf('--mode') + 1] === 'production';
11+
const isProduction =
12+
process.argv[process.argv.indexOf('--mode') + 1] === 'production'
1213

1314
function getInfos(envValues) {
14-
const appPackage = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'package.json')).toString());
15-
const info = {
16-
hosted_by: envValues.HOSTED_BY || "",
17-
hosted_by_name: envValues.HOSTED_BY_NAME || "",
18-
version: appPackage.version,
19-
country: envValues.COUNTRY || "",
20-
backend_addr: envValues.REACT_APP_NYM_CLIENT_SERVER || ""
21-
}
22-
return JSON.stringify(info)
15+
const appPackage = JSON.parse(
16+
fs.readFileSync(path.resolve(__dirname, 'package.json')).toString()
17+
)
18+
const info = {
19+
hosted_by: envValues.HOSTED_BY || '',
20+
hosted_by_name: envValues.HOSTED_BY_NAME || '',
21+
version: appPackage.version,
22+
country: envValues.COUNTRY || '',
23+
backend_addr: envValues.REACT_APP_NYM_CLIENT_SERVER || '',
24+
}
25+
return JSON.stringify(info)
2326
}
2427

25-
2628
module.exports = (env) => {
29+
let pluginList = [
30+
new HtmlWebpackPlugin({
31+
title: 'Pastenym',
32+
description: 'Share text anonymously',
33+
public_url: 'https://pastenym.ch',
34+
template: path.resolve(__dirname, './src/index.html'), // template file
35+
filename: 'index.html', // output file
36+
}),
37+
new FaviconsWebpackPlugin({
38+
logo: './public/logo.svg',
39+
favicons: {
40+
appName: 'Pastenym',
41+
appDescription: 'Share text anonymously',
42+
developerName: 'No Trust Verify',
43+
developerURL: null, // prevent retrieving from the nearest package.json
44+
background: '#FFFFFF',
45+
theme_color: '#e8e5e1',
46+
icons: {
47+
coast: false,
48+
yandex: false,
49+
},
50+
inject: true,
51+
},
52+
}),
53+
new CleanWebpackPlugin(),
54+
new Dotenv(),
55+
new WorkboxPlugin.GenerateSW({
56+
// these options encourage the ServiceWorkers to get in there fast
57+
// and not allow any straggling "old" SWs to hang around
58+
clientsClaim: true,
59+
skipWaiting: true,
60+
maximumFileSizeToCacheInBytes: 90000000,
61+
}),
62+
]
2763

28-
let pluginList = [
29-
new HtmlWebpackPlugin({
30-
title: 'Pastenym',
31-
description: "Share text anonymously",
32-
public_url: "https://pastenym.ch",
33-
template: path.resolve(__dirname, './src/index.html'), // template file
34-
filename: 'index.html', // output file
35-
}),
36-
new FaviconsWebpackPlugin({logo: './public/logo.svg',favicons: {
37-
appName: 'Pastenym',
38-
appDescription: 'Share text anonymously',
39-
developerName: 'No Trust Verify',
40-
developerURL: null, // prevent retrieving from the nearest package.json
41-
background: '#FFFFFF',
42-
theme_color: '#e8e5e1',
43-
icons: {
44-
coast: false,
45-
yandex: false
46-
},
47-
inject: true,
48-
}}),
49-
new CleanWebpackPlugin(),
50-
new Dotenv(),
51-
]
52-
53-
if(isProduction){
54-
pluginList.push(
55-
new WorkboxPlugin.GenerateSW({
56-
// these options encourage the ServiceWorkers to get in there fast
57-
// and not allow any straggling "old" SWs to hang around
58-
clientsClaim: true,
59-
skipWaiting: true,
60-
maximumFileSizeToCacheInBytes: 90000000,
61-
})
62-
)
63-
}
64-
65-
66-
64+
// process.env contains the env variables from upstream (OS, docker, you-name-it,…)
65+
// Parse the .env file and add variables to the process.env
66+
var _ = require('dotenv').config({ path: __dirname + '/.env' })
6767

68-
// process.env contains the env variables from upstream (OS, docker, you-name-it,…)
69-
// Parse the .env file and add variables to the process.env
70-
var _ = require('dotenv').config({path: __dirname + '/.env'})
71-
72-
// If instance owner does not want to expose the info.json file, we do not generate it
73-
if (process.env.hasOwnProperty("GENERATE_INFO_FILE_ABOUT_INSTANCE") && process.env.GENERATE_INFO_FILE_ABOUT_INSTANCE.toLowerCase() === "true") {
74-
console.log("Will generate info.json file as allowed.")
75-
// Using generate-file-webpack-plugin: works but old!
76-
pluginList.push(
77-
generate({
78-
file: 'info.json',
79-
content: getInfos(process.env)
80-
}))
81-
}
68+
// If instance owner does not want to expose the info.json file, we do not generate it
69+
if (
70+
process.env.hasOwnProperty('GENERATE_INFO_FILE_ABOUT_INSTANCE') &&
71+
process.env.GENERATE_INFO_FILE_ABOUT_INSTANCE.toLowerCase() === 'true'
72+
) {
73+
console.log('Will generate info.json file as allowed.')
74+
// Using generate-file-webpack-plugin: works but old!
75+
pluginList.push(
76+
generate({
77+
file: 'info.json',
78+
content: getInfos(process.env),
79+
})
80+
)
81+
}
8282

83-
return {
84-
entry: {
85-
main: path.resolve(__dirname, './src/index.js'),
86-
app: path.resolve(__dirname, './src/UserInput.js'),
87-
app: path.resolve(__dirname, './src/Texts.js'),
88-
//worker: path.resolve(__dirname, './src/worker.js'),
89-
//bootstrap: path.resolve(__dirname, './src/bootstrap.js')
90-
},
91-
output: {
92-
path: path.resolve(__dirname, './dist'),
93-
filename: '[name].bundle.js',
94-
},
95-
mode: 'production',
96-
plugins: pluginList,
97-
module: {
98-
rules: [
99-
// JavaScript
100-
{
101-
test: /\.js$/,
102-
exclude: /node_modules/,
103-
use: ['babel-loader'],
83+
return {
84+
entry: {
85+
main: path.resolve(__dirname, './src/index.js'),
86+
app: path.resolve(__dirname, './src/UserInput.js'),
87+
app: path.resolve(__dirname, './src/Texts.js'),
88+
//worker: path.resolve(__dirname, './src/worker.js'),
89+
//bootstrap: path.resolve(__dirname, './src/bootstrap.js')
90+
},
91+
output: {
92+
path: path.resolve(__dirname, './dist'),
93+
filename: '[name].bundle.js',
94+
},
95+
mode: 'production',
96+
plugins: pluginList,
97+
module: {
98+
rules: [
99+
// JavaScript
100+
{
101+
test: /\.js$/,
102+
exclude: /node_modules/,
103+
use: ['babel-loader'],
104+
},
105+
// Images
106+
{
107+
test: /\.(?:ico|gif|png|jpg|jpeg)$/i,
108+
type: 'asset/resource',
109+
generator: {
110+
filename: 'images/[name]-[hash][ext]',
111+
},
112+
},
113+
{
114+
test: /\.(png|jpg)$/i,
115+
type: 'asset/resource',
116+
generator: {
117+
filename: 'images/[name]-[hash][ext]',
118+
},
119+
},
120+
// Fonts and SVGs
121+
{
122+
test: /\.(woff(2)?|eot|ttf|otf|svg|)$/,
123+
type: 'asset/inline',
124+
},
125+
// CSS, PostCSS, and Sass
126+
{
127+
test: /\.(scss|css)$/,
128+
use: [
129+
'style-loader',
130+
'css-loader',
131+
'postcss-loader',
132+
'sass-loader',
133+
],
134+
},
135+
],
136+
// According: https://github.com/bitwiseshiftleft/sjcl/issues/345#issuecomment-345640858
137+
noParse: [/sjcl\.js$/],
104138
},
105-
// Images
106-
{
107-
test: /\.(?:ico|gif|png|jpg|jpeg)$/i,
108-
type: 'asset/resource',
109-
generator: {
110-
filename: 'images/[name]-[hash][ext]'
111-
}
139+
devServer: {
140+
historyApiFallback: true,
141+
static: {
142+
directory: path.join(__dirname, './dist'),
143+
},
144+
open: false,
145+
compress: false,
146+
port: 8081,
147+
hot: false,
148+
liveReload: true,
112149
},
113-
{
114-
test: /\.(png|jpg)$/i,
115-
type: 'asset/resource',
116-
generator: {
117-
filename: 'images/[name]-[hash][ext]'
118-
}
150+
experiments: {
151+
syncWebAssembly: true,
152+
topLevelAwait: true,
119153
},
120-
// Fonts and SVGs
121-
{
122-
test: /\.(woff(2)?|eot|ttf|otf|svg|)$/,
123-
type: 'asset/inline',
154+
performance: {
155+
maxEntrypointSize: 20012000,
156+
maxAssetSize: 200212000,
124157
},
125-
// CSS, PostCSS, and Sass
126-
{
127-
test: /\.(scss|css)$/,
128-
use: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader'],
158+
optimization: {
159+
minimize: true,
160+
minimizer: [new TerserPlugin()],
161+
splitChunks: {
162+
chunks: 'all',
163+
minSize: 10000,
164+
maxSize: 100000,
165+
cacheGroups: {
166+
commons: {
167+
test: /[\\/]node_modules[\\/]/,
168+
name: 'vendors',
169+
chunks: 'all',
170+
},
171+
},
172+
},
129173
},
130-
],
131-
// According: https://github.com/bitwiseshiftleft/sjcl/issues/345#issuecomment-345640858
132-
noParse: [
133-
/sjcl\.js$/,
134-
]
135-
},
136-
devServer: {
137-
historyApiFallback: true,
138-
static: {
139-
directory: path.join(__dirname, './dist'),
140-
},
141-
open: false,
142-
compress: false,
143-
port: 8081,
144-
hot: false,
145-
liveReload: true,
146-
},
147-
experiments: {
148-
syncWebAssembly: true,
149-
topLevelAwait: true
150-
},
151-
performance: {
152-
maxEntrypointSize: 20012000,
153-
maxAssetSize: 200212000,
154-
},
155-
optimization: {
156-
minimize: true,
157-
minimizer: [new TerserPlugin()],
158-
splitChunks: {
159-
chunks: 'all',
160-
minSize: 10000,
161-
maxSize: 100000,
162-
cacheGroups: {
163-
commons: {
164-
test: /[\\/]node_modules[\\/]/,
165-
name: "vendors",
166-
chunks: "all"
167-
}
168-
}
169-
}
170174
}
171-
}
172175
}

0 commit comments

Comments
 (0)