Skip to content

Commit 8dd729d

Browse files
authored
feat: migrate page functions to wokers (#1041)
1 parent b41666b commit 8dd729d

File tree

13 files changed

+10361
-13366
lines changed

13 files changed

+10361
-13366
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ pnpm web firefox:zip # output zip file at in .output/md-{version}-firefox.zip
124124

125125
# uTools 插件打包
126126
pnpm utools:package # output zip file at apps/utools/release/md-utools-v{version}.zip
127+
128+
# cloudflare workers
129+
pnpm web wrangler:dev # cloudflare workers dev 模式
130+
pnpm web wrangler:deploy # cloudflare workers 部署命令
127131
```
128132

129133
## 🚀 快速搭建私有服务

apps/web/functions/cgi-bin/material/add_material/index.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

apps/web/functions/cgi-bin/media/uploadimg/index.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

apps/web/functions/cgi-bin/stable_token.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

apps/web/functions/parseFormDataRequest.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

apps/web/functions/utils.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

apps/web/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"build:analyze": "cross-env ANALYZE=true vite build",
1515
"compile:extension": "pnpm --prefix ./src/extension run compile",
1616
"preview": "pnpm run build && vite preview",
17-
"preview:pages": "cross-env CF_PAGES=1 pnpm run build:h5-netlify && wrangler pages dev ./dist",
17+
"wrangler:dev": "cross-env CF_PAGES=1 vite --host",
18+
"wrangler:deploy": "cross-env CF_PAGES=1 pnpm run build:h5-netlify && wrangler deploy",
1819
"release:cli": "node ./scripts/release.js",
1920
"ext:dev": "wxt",
2021
"ext:zip": "wxt zip",
@@ -73,6 +74,7 @@
7374
"yup": "^1.7.1"
7475
},
7576
"devDependencies": {
77+
"@cloudflare/vite-plugin": "^1.13.10",
7678
"@cloudflare/workers-types": "^4.20251001.0",
7779
"@md/config": "workspace:*",
7880
"@tailwindcss/postcss": "^4.1.13",

apps/web/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
},
1212
{
1313
"path": "./tsconfig.node.json"
14+
},
15+
{
16+
"path": "./tsconfig.worker.json"
1417
}
1518
],
1619
"files": []
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
2+
"extends": "./tsconfig.node.json",
23
"compilerOptions": {
3-
"target": "esnext",
4-
"lib": ["esnext"],
5-
"module": "esnext",
64
"types": ["@cloudflare/workers-types"]
75
}
86
}

apps/web/vite.config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'node:path'
22
import process from 'node:process'
33

4+
import { cloudflare } from '@cloudflare/vite-plugin'
45
import tailwindcss from '@tailwindcss/vite'
56
import vue from '@vitejs/plugin-vue'
67
import { visualizer } from 'rollup-plugin-visualizer'
@@ -13,8 +14,9 @@ import { VitePluginRadar } from 'vite-plugin-radar'
1314
import vueDevTools from 'vite-plugin-vue-devtools'
1415

1516
const isUTools = process.env.SERVER_ENV === `UTOOLS`
17+
const isCfWorkers = process.env.CF_PAGES === `1`
1618
const base
17-
= process.env.SERVER_ENV === `NETLIFY`
19+
= process.env.SERVER_ENV === `NETLIFY` || isCfWorkers
1820
? `/`
1921
: isUTools
2022
? `./`
@@ -29,6 +31,7 @@ export default defineConfig(({ mode }) => {
2931
envPrefix: [`VITE_`, `CF_`],
3032
plugins: [
3133
vue(),
34+
isCfWorkers && cloudflare(),
3235
tailwindcss(),
3336
vueDevTools({
3437
launchEditor: env.VITE_LAUNCH_EDITOR ?? `code`,
@@ -70,7 +73,7 @@ export default defineConfig(({ mode }) => {
7073
}),
7174
]
7275
: []),
73-
nodePolyfills({
76+
!isCfWorkers && nodePolyfills({
7477
include: [`path`, `util`, `timers`, `stream`, `fs`],
7578
overrides: {
7679
// Since `fs` is not supported in browsers, we can use the `memfs` package to polyfill it.

0 commit comments

Comments
 (0)