1
1
/* eslint-disable @typescript-eslint/no-var-requires */
2
2
const withPWA = require ( 'next-pwa' ) ;
3
+ const withManifest = require ( 'next-manifest' ) ;
3
4
const withTM = require ( 'next-transpile-modules' ) ( [ 'typeorm/browser' ] ) ;
4
5
const webpack = require ( 'webpack' ) ;
5
6
const defaultCache = require ( 'next-pwa/cache' ) ;
6
7
const envMapping = require ( './configs/env.mapping' ) ;
7
8
8
9
const isProd = process . env . NODE_ENV === 'production' ;
9
- const { LINK_PREFIX } = envMapping ;
10
+ const {
11
+ LINK_PREFIX ,
12
+ FOLDER ,
13
+ THEME_COLOR ,
14
+ ICON_192_PATH ,
15
+ ICON_512_PATH ,
16
+ } = envMapping ;
10
17
11
18
// tranfrom precache url for browsers that encode dynamic routes
12
19
// i.e. "[id].js" => "%5Bid%5D.js"
@@ -19,69 +26,99 @@ const encodeUriTransform = async (manifestEntries) => {
19
26
} ;
20
27
21
28
module . exports = ( ) =>
22
- withPWA (
23
- withTM ( {
24
- webpack : ( config , { isServer } ) => {
25
- config . plugins . push (
26
- new webpack . ProvidePlugin ( {
27
- 'window.SQL' : 'sql.js/dist/sql-wasm.js' ,
28
- } )
29
- ) ;
30
- if ( ! isServer ) {
31
- config . node = {
32
- fs : 'empty' ,
33
- net : 'empty' ,
34
- tls : 'empty' ,
35
- } ;
36
- }
37
- return config ;
38
- } ,
29
+ withManifest (
30
+ withPWA (
31
+ withTM ( {
32
+ // sql.js
33
+ webpack : ( config , { isServer } ) => {
34
+ config . plugins . push (
35
+ new webpack . ProvidePlugin ( {
36
+ 'window.SQL' : 'sql.js/dist/sql-wasm.js' ,
37
+ } )
38
+ ) ;
39
+ if ( ! isServer ) {
40
+ config . node = {
41
+ fs : 'empty' ,
42
+ net : 'empty' ,
43
+ tls : 'empty' ,
44
+ } ;
45
+ }
46
+ return config ;
47
+ } ,
39
48
40
- env : envMapping ,
41
- target : 'serverless' ,
42
- poweredByHeader : false ,
43
- assetPrefix : LINK_PREFIX ,
49
+ env : envMapping ,
50
+ target : 'serverless' ,
51
+ poweredByHeader : false ,
52
+ assetPrefix : LINK_PREFIX ,
44
53
45
- pwa : {
46
- disable : ! isProd ,
47
- subdomainPrefix : LINK_PREFIX ,
48
- dest : 'public' ,
49
- manifestTransforms : [ encodeUriTransform ] ,
50
- runtimeCaching : [
51
- ...defaultCache ,
52
- {
53
- urlPattern : / ^ h t t p s ? .* / ,
54
- handler : 'NetworkFirst' ,
55
- options : {
56
- cacheName : 'offlineCache' ,
57
- networkTimeoutSeconds : 15 ,
58
- expiration : {
59
- maxEntries : 150 ,
60
- maxAgeSeconds : 30 * 24 * 60 * 60 ,
61
- } ,
62
- cacheableResponse : {
63
- statuses : [ 0 , 200 ] ,
54
+ // service worker
55
+ pwa : {
56
+ disable : ! isProd ,
57
+ subdomainPrefix : LINK_PREFIX ,
58
+ dest : 'public' ,
59
+ manifestTransforms : [ encodeUriTransform ] ,
60
+ runtimeCaching : [
61
+ ...defaultCache ,
62
+ {
63
+ urlPattern : / ^ h t t p s ? .* / ,
64
+ handler : 'NetworkFirst' ,
65
+ options : {
66
+ cacheName : 'offlineCache' ,
67
+ networkTimeoutSeconds : 15 ,
68
+ expiration : {
69
+ maxEntries : 150 ,
70
+ maxAgeSeconds : 30 * 24 * 60 * 60 ,
71
+ } ,
72
+ cacheableResponse : {
73
+ statuses : [ 0 , 200 ] ,
74
+ } ,
64
75
} ,
65
76
} ,
66
- } ,
67
- {
68
- urlPattern : ( { event } ) => event . request . mode === 'navigate ',
69
- handler : 'CacheFirst' ,
70
- options : {
71
- cacheName : 'offlineCache' ,
72
- expiration : {
73
- maxEntries : 150 ,
74
- maxAgeSeconds : 30 * 24 * 60 * 60 ,
75
- } ,
76
- cacheableResponse : {
77
- statuses : [ 0 , 200 ] ,
77
+ {
78
+ urlPattern : ( { event } ) => event . request . mode === 'navigate' ,
79
+ handler : 'CacheFirst ',
80
+ options : {
81
+ cacheName : 'offlineCache' ,
82
+ expiration : {
83
+ maxEntries : 150 ,
84
+ maxAgeSeconds : 30 * 24 * 60 * 60 ,
85
+ } ,
86
+ cacheableResponse : {
87
+ statuses : [ 0 , 200 ] ,
88
+ } ,
78
89
} ,
79
90
} ,
80
- } ,
81
- ] ,
82
- navigationPreload : true ,
83
- // publicExcludes: [],
84
- // exclude: ['**/node_modules/**/*'],
85
- } ,
86
- } )
91
+ ] ,
92
+ navigationPreload : true ,
93
+ // publicExcludes: [],
94
+ // exclude: ['**/node_modules/**/*'],
95
+ } ,
96
+
97
+ // manifest
98
+ manifest : {
99
+ /* eslint-disable @typescript-eslint/camelcase */
100
+ output : 'public' ,
101
+ short_name : FOLDER ,
102
+ name : FOLDER ,
103
+ start_url : `${ LINK_PREFIX } /` ,
104
+ background_color : THEME_COLOR ,
105
+ display : 'standalone' ,
106
+ scope : `${ LINK_PREFIX } /` ,
107
+ dir : 'ltr' , // text direction: left to right
108
+ theme_color : THEME_COLOR ,
109
+ icons : [
110
+ {
111
+ src : `${ LINK_PREFIX } ${ ICON_192_PATH } ` ,
112
+ sizes : '192x192' ,
113
+ type : 'image/png' ,
114
+ } ,
115
+ {
116
+ src : `${ LINK_PREFIX } ${ ICON_512_PATH } ` ,
117
+ sizes : '512x512' ,
118
+ type : 'image/png' ,
119
+ } ,
120
+ ] ,
121
+ } ,
122
+ } )
123
+ )
87
124
) ;
0 commit comments