Skip to content

Commit 7904c91

Browse files
fix: support PWA on Netlify (#79)
Co-authored-by: yzh990918 <251205668@qq.com>
1 parent 071158c commit 7904c91

File tree

12 files changed

+2320
-2533
lines changed

12 files changed

+2320
-2533
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ Q: Accelerate domestic access without the need for proxy deployment tutorial?
6565

6666
A: You can refer to this tutorial: https://github.com/anse-app/chatgpt-demo/discussions/270
6767

68-
Q: `PWA` is not working?
69-
70-
A: Current `PWA` does not support deployment on Netlify, you can choose vercel or node deployment.
7168
## Contributing
7269

7370
This project exists thanks to all those who contributed.

README.zh-CN.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ Q: 无需代理部署教程即可加速国内访问??
6767

6868
A: 你可以参考此教程: https://github.com/anse-app/chatgpt-demo/discussions/270
6969

70-
Q: `PWA` 不工作?
71-
72-
A: 当前的 PWA 不支持 Netlify 部署,您可以选择 vercel 或 node 部署。
73-
7470
## 参与贡献
7571

7672
这个项目的存在要感谢所有做出贡献的人。

README_JA-JP.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ Q: プロキシを導入することなく国内アクセスを高速化する
6565

6666
A: こちらのチュートリアルをご参照ください: https://github.com/anse-app/chatgpt-demo/discussions/270
6767

68-
Q: `PWA` が動作しません。
69-
70-
A: 現在の `PWA` は Netlify へのデプロイをサポートしていません。
7168
## コントリビュート
7269

7370
このプロジェクトが存在するのは、コントリビュートしてくださったすべての方々のおかげです。

astro.config.mjs

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,16 @@ import { defineConfig } from 'astro/config'
22
import unocss from 'unocss/astro'
33
import solidJs from '@astrojs/solid-js'
44
import node from '@astrojs/node'
5-
import { VitePWA } from 'vite-plugin-pwa'
5+
import AstroPWA from '@vite-pwa/astro'
66
import vercel from '@astrojs/vercel/edge'
77
import netlify from '@astrojs/netlify/edge-functions'
88
import disableBlocks from './plugins/disableBlocks'
99

1010
const envAdapter = () => {
11-
if (process.env.OUTPUT === 'vercel') {
12-
return vercel()
13-
} else if (process.env.OUTPUT === 'netlify') {
14-
return netlify()
15-
} else {
16-
return node({
17-
mode: 'standalone',
18-
})
11+
switch (process.env.OUTPUT) {
12+
case 'vercel': return vercel()
13+
case 'netlify': return netlify()
14+
default: return node({ mode: 'standalone' })
1915
}
2016
}
2117

@@ -24,6 +20,42 @@ export default defineConfig({
2420
integrations: [
2521
unocss(),
2622
solidJs(),
23+
AstroPWA({
24+
registerType: 'autoUpdate',
25+
injectRegister: 'inline',
26+
manifest: {
27+
name: 'Anse',
28+
short_name: 'Anse',
29+
description: 'Anse is a fully optimized UI for AI Chats.',
30+
theme_color: '#101010',
31+
background_color: '#ffffff',
32+
icons: [
33+
{
34+
src: 'pwa-192.png',
35+
sizes: '192x192',
36+
type: 'image/png',
37+
},
38+
{
39+
src: 'pwa-512.png',
40+
sizes: '512x512',
41+
type: 'image/png',
42+
},
43+
{
44+
src: 'logo.svg',
45+
sizes: '32x32',
46+
type: 'image/svg',
47+
purpose: 'any maskable',
48+
},
49+
],
50+
},
51+
client: {
52+
installPrompt: true,
53+
periodicSyncForUpdates: 20,
54+
},
55+
devOptions: {
56+
enabled: false,
57+
},
58+
}),
2759
],
2860
output: 'server',
2961
adapter: envAdapter(),
@@ -33,42 +65,7 @@ export default defineConfig({
3365
vite: {
3466
plugins: [
3567
process.env.OUTPUT === 'vercel' && disableBlocks(),
36-
process.env.OUTPUT === 'netlify' && disableBlocks('netlify'),
37-
process.env.OUTPUT !== 'netlify' && VitePWA({
38-
registerType: 'autoUpdate',
39-
manifest: {
40-
name: 'Anse',
41-
short_name: 'Anse',
42-
description: 'Anse is a fully optimized UI for AI Chats.',
43-
theme_color: '#101010',
44-
background_color: '#ffffff',
45-
icons: [
46-
{
47-
src: 'pwa-192.png',
48-
sizes: '192x192',
49-
type: 'image/png',
50-
},
51-
{
52-
src: 'pwa-512.png',
53-
sizes: '512x512',
54-
type: 'image/png',
55-
},
56-
{
57-
src: 'logo.svg',
58-
sizes: '32x32',
59-
type: 'image/svg',
60-
purpose: 'any maskable',
61-
},
62-
],
63-
},
64-
client: {
65-
installPrompt: true,
66-
periodicSyncForUpdates: 20,
67-
},
68-
devOptions: {
69-
enabled: false,
70-
},
71-
}),
68+
process.env.OUTPUT === 'netlify' && disableBlocks(),
7269
],
7370
},
7471
})

package.json

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,65 +16,63 @@
1616
"postinstall": "npx simple-git-hooks"
1717
},
1818
"dependencies": {
19-
"@astrojs/netlify": "2.0.0",
20-
"@astrojs/node": "^5.1.1",
21-
"@astrojs/solid-js": "^2.1.0",
22-
"@astrojs/vercel": "^3.2.2",
19+
"@astrojs/netlify": "2.3.0",
20+
"@astrojs/node": "^5.3.0",
21+
"@astrojs/solid-js": "^2.2.0",
22+
"@astrojs/vercel": "^3.6.0",
2323
"@mapbox/rehype-prism": "^0.8.0",
24-
"@nanostores/solid": "^0.3.2",
25-
"@solid-primitives/clipboard": "^1.5.4",
26-
"@solid-primitives/keyboard": "^1.1.0",
24+
"@nanostores/solid": "^0.4.2",
25+
"@solid-primitives/clipboard": "^1.5.6",
26+
"@solid-primitives/keyboard": "^1.2.3",
2727
"@solid-primitives/scheduled": "^1.3.2",
28-
"@solid-primitives/scroll": "^2.0.14",
29-
"@unocss/reset": "^0.50.6",
30-
"@zag-js/checkbox": "^0.9.2",
31-
"@zag-js/dialog": "^0.9.2",
32-
"@zag-js/menu": "^0.9.2",
33-
"@zag-js/select": "^0.9.2",
34-
"@zag-js/slider": "^0.9.2",
35-
"@zag-js/solid": "^0.9.2",
36-
"@zag-js/switch": "^0.9.2",
37-
"@zag-js/tabs": "^0.9.2",
38-
"@zag-js/toast": "^0.9.2",
39-
"@zag-js/toggle": "^0.9.2",
40-
"@zag-js/tooltip": "^0.9.2",
41-
"astro": "^2.2.0",
42-
"bumpp": "^9.1.0",
43-
"destr": "^1.2.2",
44-
"eslint": "^8.37.0",
45-
"eventsource-parser": "^0.1.0",
46-
"idb-keyval": "^6.2.0",
28+
"@solid-primitives/scroll": "^2.0.17",
29+
"@unocss/reset": "^0.53.4",
30+
"@zag-js/checkbox": "^0.10.3",
31+
"@zag-js/dialog": "^0.10.3",
32+
"@zag-js/menu": "^0.10.3",
33+
"@zag-js/select": "^0.10.3",
34+
"@zag-js/slider": "^0.10.3",
35+
"@zag-js/solid": "^0.10.3",
36+
"@zag-js/switch": "^0.10.3",
37+
"@zag-js/tabs": "^0.10.3",
38+
"@zag-js/toast": "^0.10.3",
39+
"@zag-js/toggle": "^0.10.3",
40+
"@zag-js/tooltip": "^0.10.3",
41+
"astro": "^2.7.3",
42+
"bumpp": "^9.1.1",
43+
"destr": "^2.0.0",
44+
"eslint": "^8.44.0",
45+
"eventsource-parser": "^1.0.0",
46+
"idb-keyval": "^6.2.1",
4747
"js-sha256": "^0.9.0",
48-
"katex": "^0.16.4",
49-
"nanostores": "^0.7.4",
48+
"katex": "^0.16.8",
49+
"nanostores": "^0.9.3",
5050
"prism-theme-vars": "^0.2.4",
51-
"rehype-katex": "^6.0.2",
51+
"rehype-katex": "^6.0.3",
5252
"rehype-stringify": "^9.0.3",
5353
"remark-gfm": "^3.0.1",
5454
"remark-math": "^5.1.1",
55-
"remark-parse": "^10.0.1",
55+
"remark-parse": "^10.0.2",
5656
"remark-rehype": "^10.1.0",
5757
"solid-emoji-picker": "^0.2.0",
58-
"solid-js": "1.6.12",
58+
"solid-js": "1.7.7",
5959
"solid-transition-group": "^0.2.2",
6060
"unified": "^10.1.2"
6161
},
6262
"devDependencies": {
6363
"@evan-yang/eslint-config": "^1.0.9",
64-
"@iconify-json/carbon": "^1.1.16",
65-
"@iconify-json/simple-icons": "^1.1.48",
64+
"@iconify-json/carbon": "^1.1.18",
65+
"@iconify-json/simple-icons": "^1.1.58",
6666
"@types/mapbox__rehype-prism": "^0.8.0",
67-
"@typescript-eslint/parser": "^5.57.1",
68-
"@unocss/preset-attributify": "^0.50.6",
69-
"@unocss/preset-icons": "^0.50.6",
70-
"@unocss/preset-typography": "^0.50.6",
71-
"eslint-plugin-astro": "^0.24.0",
67+
"@typescript-eslint/parser": "^5.60.1",
68+
"@vite-pwa/astro": "^0.1.1",
69+
"eslint-plugin-astro": "^0.27.2",
7270
"html2canvas": "^1.4.1",
73-
"lint-staged": "^13.2.2",
71+
"lint-staged": "^13.2.3",
7472
"punycode": "^2.3.0",
7573
"simple-git-hooks": "^2.8.1",
76-
"unocss": "^0.50.6",
77-
"vite-plugin-pwa": "^0.14.7"
74+
"unocss": "^0.50.8",
75+
"vite-plugin-pwa": "^0.16.4"
7876
},
7977
"simple-git-hooks": {
8078
"pre-commit": "pnpm lint-staged"

plugins/disableBlocks.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
export default function plugin(platform?: string) {
1+
export default function plugin() {
22
const transform = (code: string, id: string) => {
33
if (id.includes('pages/api/generate.ts')) {
44
return {
55
code: code.replace(/^.*?#vercel-disable-blocks([\s\S]+?)#vercel-end.*?$/gm, ''),
66
map: null,
77
}
88
}
9-
if (platform === 'netlify' && id.includes('layouts/Layout.astro')) {
10-
return {
11-
code: code.replace(/^.*?<!-- netlify-disable-blocks -->([\s\S]+?)<!-- netlify-disable-end -->.*?$/gm, ''),
12-
map: null,
13-
}
14-
}
159
}
1610

1711
return {

0 commit comments

Comments
 (0)