Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Mar 30, 2022. It is now read-only.

Commit 5bd0581

Browse files
committed
add manifest
1 parent cb00b20 commit 5bd0581

File tree

5 files changed

+902
-131
lines changed

5 files changed

+902
-131
lines changed

‎configs/env.mapping.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ const path = require('path');
33
require('dotenv').config({
44
path: path.join(__dirname, `../.env/${process.env.NODE_ENV}.env`),
55
});
6-
const packageLockJson = require('../package-lock.json');
76

87
// env mapping for exposure to client
98
module.exports = {
109
TEST_CLIENT: process.env.test,
1110
TEST_PAGE_VAR: process.env.TEST_PAGE_VAR,
1211
ENV: process.env.NODE_ENV,
13-
LINK_PREFIX: process.env.LINK_PREFIX || '',
14-
THEME_COLOR: process.env.THEME_COLOR,
15-
MANIEFST_PATH: process.env.MANIEFST_PATH,
16-
ICON_192_PATH: process.env.ICON_192_PATH,
17-
FAV_ICON_PATH: process.env.FAV_ICON_PATH,
18-
SQL_JS_VERSION: packageLockJson.dependencies['sql.js'].version,
12+
FOLDER: process.env.FOLDER || '',
13+
LINK_PREFIX: `/${process.env.FOLDER}` || '',
14+
THEME_COLOR: process.env.THEME_COLOR || '',
15+
MANIEFST_PATH: process.env.MANIEFST_PATH || '',
16+
ICON_192_PATH: process.env.ICON_192_PATH || '',
17+
ICON_512_PATH: process.env.ICON_512_PATH || '',
18+
FAV_ICON_PATH: process.env.FAV_ICON_PATH || '',
1919
};

‎next.config.js

Lines changed: 97 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
22
const withPWA = require('next-pwa');
3+
const withManifest = require('next-manifest');
34
const withTM = require('next-transpile-modules')(['typeorm/browser']);
45
const webpack = require('webpack');
56
const defaultCache = require('next-pwa/cache');
67
const envMapping = require('./configs/env.mapping');
78

89
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;
1017

1118
// tranfrom precache url for browsers that encode dynamic routes
1219
// i.e. "[id].js" => "%5Bid%5D.js"
@@ -19,69 +26,99 @@ const encodeUriTransform = async (manifestEntries) => {
1926
};
2027

2128
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+
},
3948

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,
4453

45-
pwa: {
46-
disable: !isProd,
47-
subdomainPrefix: LINK_PREFIX,
48-
dest: 'public',
49-
manifestTransforms: [encodeUriTransform],
50-
runtimeCaching: [
51-
...defaultCache,
52-
{
53-
urlPattern: /^https?.*/,
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: /^https?.*/,
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+
},
6475
},
6576
},
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+
},
7889
},
7990
},
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+
)
87124
);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /