Skip to content

Commit 2fbde5d

Browse files
committed
refactor: 把 nextjs 换成 qwik
1 parent 0eb27ea commit 2fbde5d

File tree

68 files changed

+1808
-4447
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1808
-4447
lines changed

.idea/aquadx-bot.iml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/web/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ next-env.d.ts
3939
.wrangler
4040
.dev.vars
4141
.worker-next
42+
43+
# Cloudflare
44+
functions/**/*.js
45+
server

apps/web/README.md

Lines changed: 32 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,46 @@
1-
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`c3`](https://developers.cloudflare.com/pages/get-started/c3).
1+
## Cloudflare Pages
22

3-
## Getting Started
3+
Cloudflare's [wrangler](https://github.com/cloudflare/wrangler) CLI can be used to preview a production build locally. To start a local server, run:
44

5-
First, run the development server:
6-
7-
```bash
8-
npm run dev
9-
# or
10-
yarn dev
11-
# or
12-
pnpm dev
13-
# or
14-
bun dev
5+
```
6+
pnpm serve
157
```
168

17-
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18-
19-
## Cloudflare integration
20-
21-
Besides the `dev` script mentioned above `c3` has added a few extra scripts that allow you to integrate the application with the [Cloudflare Pages](https://pages.cloudflare.com/) environment, these are:
22-
- `pages:build` to build the application for Pages using the [`@cloudflare/next-on-pages`](https://github.com/cloudflare/next-on-pages) CLI
23-
- `preview` to locally preview your Pages application using the [Wrangler](https://developers.cloudflare.com/workers/wrangler/) CLI
24-
- `deploy` to deploy your Pages application using the [Wrangler](https://developers.cloudflare.com/workers/wrangler/) CLI
25-
26-
> __Note:__ while the `dev` script is optimal for local development you should preview your Pages application as well (periodically or before deployments) in order to make sure that it can properly work in the Pages environment (for more details see the [`@cloudflare/next-on-pages` recommended workflow](https://github.com/cloudflare/next-on-pages/blob/05b6256/internal-packages/next-dev/README.md#recommended-workflow))
27-
28-
### Bindings
9+
Then visit [http://localhost:8787/](http://localhost:8787/)
2910

30-
Cloudflare [Bindings](https://developers.cloudflare.com/pages/functions/bindings/) are what allows you to interact with resources available in the Cloudflare Platform.
11+
### Deployments
3112

32-
You can use bindings during development, when previewing locally your application and of course in the deployed application:
13+
[Cloudflare Pages](https://pages.cloudflare.com/) are deployable through their [Git provider integrations](https://developers.cloudflare.com/pages/platform/git-integration/).
3314

34-
- To use bindings in dev mode you need to define them in the `next.config.js` file under `setupDevBindings`, this mode uses the `next-dev` `@cloudflare/next-on-pages` submodule. For more details see its [documentation](https://github.com/cloudflare/next-on-pages/blob/05b6256/internal-packages/next-dev/README.md).
15+
If you don't already have an account, then [create a Cloudflare account here](https://dash.cloudflare.com/sign-up/pages). Next go to your dashboard and follow the [Cloudflare Pages deployment guide](https://developers.cloudflare.com/pages/framework-guides/deploy-anything/).
3516

36-
- To use bindings in the preview mode you need to add them to the `pages:preview` script accordingly to the `wrangler pages dev` command. For more details see its [documentation](https://developers.cloudflare.com/workers/wrangler/commands/#dev-1) or the [Pages Bindings documentation](https://developers.cloudflare.com/pages/functions/bindings/).
17+
Within the projects "Settings" for "Build and deployments", the "Build command" should be `pnpm build`, and the "Build output directory" should be set to `dist`.
3718

38-
- To use bindings in the deployed application you will need to configure them in the Cloudflare [dashboard](https://dash.cloudflare.com/). For more details see the [Pages Bindings documentation](https://developers.cloudflare.com/pages/functions/bindings/).
19+
### Function Invocation Routes
3920

40-
#### KV Example
21+
Cloudflare Page's [function-invocation-routes config](https://developers.cloudflare.com/pages/platform/functions/routing/#functions-invocation-routes) can be used to include, or exclude, certain paths to be used by the worker functions. Having a `_routes.json` file gives developers more granular control over when your Function is invoked.
22+
This is useful to determine if a page response should be Server-Side Rendered (SSR) or if the response should use a static-site generated (SSG) `index.html` file.
4123

42-
`c3` has added for you an example showing how you can use a KV binding.
24+
By default, the Cloudflare pages adaptor _does not_ include a `public/_routes.json` config, but rather it is auto-generated from the build by the Cloudflare adaptor. An example of an auto-generate `dist/_routes.json` would be:
4325

44-
In order to enable the example:
45-
- Search for javascript/typescript lines containing the following comment:
46-
```ts
47-
// KV Example:
48-
```
49-
and uncomment the commented lines below it.
50-
- Do the same in the `wrangler.toml` file, where
51-
the comment is:
52-
```
53-
# KV Example:
54-
```
55-
- If you're using TypeScript run the `cf-typegen` script to update the `env.d.ts` file:
56-
```bash
57-
npm run cf-typegen
58-
# or
59-
yarn cf-typegen
60-
# or
61-
pnpm cf-typegen
62-
# or
63-
bun cf-typegen
64-
```
26+
```
27+
{
28+
"include": [
29+
"/*"
30+
],
31+
"exclude": [
32+
"/_headers",
33+
"/_redirects",
34+
"/build/*",
35+
"/favicon.ico",
36+
"/manifest.json",
37+
"/service-worker.js",
38+
"/about"
39+
],
40+
"version": 1
41+
}
42+
```
6543

66-
After doing this you can run the `dev` or `preview` script and visit the `/api/hello` route to see the example in action.
44+
In the above example, it's saying _all_ pages should be SSR'd. However, the root static files such as `/favicon.ico` and any static assets in `/build/*` should be excluded from the Functions, and instead treated as a static file.
6745

68-
Finally, if you also want to see the example work in the deployed application make sure to add a `MY_KV_NAMESPACE` binding to your Pages application in its [dashboard kv bindings settings section](https://dash.cloudflare.com/?to=/:account/pages/view/:pages-project/settings/functions#kv_namespace_bindings_section). After having configured it make sure to re-deploy your application.
46+
In most cases the generated `dist/_routes.json` file is ideal. However, if you need more granular control over each path, you can instead provide you're own `public/_routes.json` file. When the project provides its own `public/_routes.json` file, then the Cloudflare adaptor will not auto-generate the routes config and instead use the committed one within the `public` directory.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { cloudflarePagesAdapter } from "@builder.io/qwik-city/adapters/cloudflare-pages/vite";
2+
import { extendConfig } from "@builder.io/qwik-city/vite";
3+
import baseConfig from "../../vite.config";
4+
5+
export default extendConfig(baseConfig, () => {
6+
return {
7+
build: {
8+
ssr: true,
9+
rollupOptions: {
10+
input: ["src/entry.cloudflare-pages.tsx", "@qwik-city-plan"],
11+
},
12+
},
13+
plugins: [cloudflarePagesAdapter()],
14+
};
15+
});

apps/web/babel.config.js

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

apps/web/dirfix.ts

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

apps/web/next.config.mjs

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

apps/web/package.json

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,28 @@
44
"private": true,
55
"type": "module",
66
"scripts": {
7-
"dev": "tsx dirfix.ts && next dev",
8-
"build": "tsx dirfix.ts && next build",
9-
"start": "next start",
10-
"lint": "next lint",
11-
"build:worker": "tsx dirfix.ts && cloudflare",
12-
"dev:worker": "wrangler dev --port 8771",
13-
"preview:worker": "pnpm run build:worker && pnpm run dev:worker",
14-
"deploy:worker": "pnpm run build:worker && wrangler deploy",
15-
"tail": "pnpm wrangler tail"
7+
"build": "qwik build",
8+
"build.server": "vite build -c adapters/cloudflare-pages/vite.config.ts",
9+
"build.client": "vite build",
10+
"deploy": "pnpm run build && wrangler pages deploy ./dist",
11+
"dev": "vite --mode ssr",
12+
"serve": "wrangler pages dev ./dist --compatibility-flags=nodejs_als"
1613
},
1714
"dependencies": {
1815
"@clansty/maibot-clients": "workspace:^",
1916
"@clansty/maibot-types": "workspace:^",
20-
"@clansty/maibot-utils": "workspace:^",
21-
"next": "^15.0.3",
22-
"react": "^18.3.1",
23-
"react-dom": "^18.3.1"
17+
"@clansty/maibot-utils": "workspace:^"
2418
},
2519
"devDependencies": {
26-
"@babel/plugin-transform-block-scoping": "^7.25.9",
27-
"@babel/preset-env": "^7.26.0",
28-
"@babel/preset-typescript": "^7.26.0",
29-
"@babel/runtime": "^7.26.0",
20+
"@builder.io/qwik": "^1.7.3",
21+
"@builder.io/qwik-city": "^1.7.3",
3022
"@cloudflare/workers-types": "^4.20241112.0",
3123
"@iconify-json/twemoji": "^1.2.0",
32-
"@opennextjs/cloudflare": "^0.2.1",
3324
"@types/node": "^22.9.1",
34-
"@types/react": "^18.3.12",
35-
"@types/react-dom": "^18.3.1",
36-
"@unocss/postcss": "^0.64.1",
37-
"babel-loader": "^9.2.1",
38-
"esbuild-loader": "^4.2.2",
39-
"json-loader": "^0.5.7",
40-
"postcss": "^8.4.49",
41-
"tsx": "^4.19.2",
4225
"typescript": "^5.6.3",
4326
"unocss": "^0.64.1",
44-
"vercel": "^39.1.0",
45-
"webpack": "^5.96.1",
46-
"wrangler": "^3.88.0"
27+
"vite": "^5.2.10",
28+
"vite-tsconfig-paths": "^4.2.1",
29+
"wrangler": "^3.0.0"
4730
}
4831
}

apps/web/postcss.config.js

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

apps/web/public/_headers

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# https://developers.cloudflare.com/pages/platform/headers/
2+
3+
/*service-worker.js
4+
Cache-Control: no-store
5+
Content-Type: application/javascript
6+
X-Content-Type-Options: nosniff
7+
8+
/build/*
9+
Cache-Control: public, max-age=31536000, s-maxage=31536000, immutable

0 commit comments

Comments
 (0)