@@ -6,167 +6,170 @@ const FaviconsWebpackPlugin = require('favicons-webpack-plugin')
6
6
const WorkboxPlugin = require ( 'workbox-webpack-plugin' )
7
7
const generate = require ( 'generate-file-webpack-plugin' )
8
8
const fs = require ( 'fs' )
9
- const TerserPlugin = require ( " terser-webpack-plugin" ) ;
9
+ const TerserPlugin = require ( ' terser-webpack-plugin' )
10
10
11
- const isProduction = process . argv [ process . argv . indexOf ( '--mode' ) + 1 ] === 'production' ;
11
+ const isProduction =
12
+ process . argv [ process . argv . indexOf ( '--mode' ) + 1 ] === 'production'
12
13
13
14
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 )
23
26
}
24
27
25
-
26
28
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
+ ]
27
63
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' } )
67
67
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
+ }
82
82
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 : / \. j s $ / ,
102
- exclude : / n o d e _ m o d u l e s / ,
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 : / \. j s $ / ,
102
+ exclude : / n o d e _ m o d u l e s / ,
103
+ use : [ 'babel-loader' ] ,
104
+ } ,
105
+ // Images
106
+ {
107
+ test : / \. (?: i c o | g i f | p n g | j p g | j p e g ) $ / i,
108
+ type : 'asset/resource' ,
109
+ generator : {
110
+ filename : 'images/[name]-[hash][ext]' ,
111
+ } ,
112
+ } ,
113
+ {
114
+ test : / \. ( p n g | j p g ) $ / i,
115
+ type : 'asset/resource' ,
116
+ generator : {
117
+ filename : 'images/[name]-[hash][ext]' ,
118
+ } ,
119
+ } ,
120
+ // Fonts and SVGs
121
+ {
122
+ test : / \. ( w o f f ( 2 ) ? | e o t | t t f | o t f | s v g | ) $ / ,
123
+ type : 'asset/inline' ,
124
+ } ,
125
+ // CSS, PostCSS, and Sass
126
+ {
127
+ test : / \. ( s c s s | c s s ) $ / ,
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 : [ / s j c l \. j s $ / ] ,
104
138
} ,
105
- // Images
106
- {
107
- test : / \. (?: i c o | g i f | p n g | j p g | j p e g ) $ / 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 ,
112
149
} ,
113
- {
114
- test : / \. ( p n g | j p g ) $ / i,
115
- type : 'asset/resource' ,
116
- generator : {
117
- filename : 'images/[name]-[hash][ext]'
118
- }
150
+ experiments : {
151
+ syncWebAssembly : true ,
152
+ topLevelAwait : true ,
119
153
} ,
120
- // Fonts and SVGs
121
- {
122
- test : / \. ( w o f f ( 2 ) ? | e o t | t t f | o t f | s v g | ) $ / ,
123
- type : 'asset/inline' ,
154
+ performance : {
155
+ maxEntrypointSize : 20012000 ,
156
+ maxAssetSize : 200212000 ,
124
157
} ,
125
- // CSS, PostCSS, and Sass
126
- {
127
- test : / \. ( s c s s | c s s ) $ / ,
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 : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] / ,
168
+ name : 'vendors' ,
169
+ chunks : 'all' ,
170
+ } ,
171
+ } ,
172
+ } ,
129
173
} ,
130
- ] ,
131
- // According: https://github.com/bitwiseshiftleft/sjcl/issues/345#issuecomment-345640858
132
- noParse : [
133
- / s j c l \. j s $ / ,
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 : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] / ,
165
- name : "vendors" ,
166
- chunks : "all"
167
- }
168
- }
169
- }
170
174
}
171
- }
172
175
}
0 commit comments