When to use this skill
Use this skill for Web frontend project development when you need to:
- Develop web frontend pages and interfaces
- Deploy static websites to CloudBase static hosting
- Integrate CloudBase Web SDK for database, cloud functions, and authentication
- Set up modern frontend build systems (Vite, Webpack, etc.)
- Handle routing and build configurations for static hosting
Do NOT use for:
- Mini-program development (use miniprogram-development skill)
- Backend service development (use cloudrun-development skill)
- UI design only (use ui-design skill, but may combine with this skill)
How to use this skill (for a coding agent)
Follow project structure conventions
- Frontend source code in
src directory
- Build output in
dist directory
- Cloud functions in
cloudfunctions directory
- Use modern frontend build systems (Vite, etc.)
Use CloudBase Web SDK correctly
- Always use SDK built-in authentication features
- Never implement login logic in cloud functions
- Use
envQuery tool to get environment ID
Deploy and preview properly
- Build project first (ensure
npm install is executed)
- Use relative paths for
publicPath configuration
- Use hash routing for better static hosting compatibility
- Deploy to subdirectory if user doesn't specify root directory
Web Frontend Development Rules
Project Structure
Directory Organization:
- Frontend source code should be stored in
src directory
- Build output should be placed in
dist directory
- Cloud functions should be in
cloudfunctions directory
Build System:
- Projects should use modern frontend build systems like Vite
- Install dependencies via npm
Routing:
- If the frontend project involves routing, use hash routing by default
- Hash routing solves the 404 refresh issue and is more suitable for static website hosting deployment
Deployment and Preview
Static Hosting Deployment:
- For frontend projects, after building, you can use CloudBase static hosting
- First start local preview, then confirm with user if deployment to CloudBase static hosting is needed
- When deploying, if user has no special requirements, generally do not deploy directly to root directory
- Return deployed address in markdown link format
Local Preview:
- To preview static web pages locally, navigate to the specified output directory and use
npx live-server
Public Path Configuration:
- When web projects are deployed to static hosting CDN, since paths cannot be known in advance,
publicPath and similar configurations should use relative paths instead of absolute paths
- This solves resource loading issues
CloudBase Web SDK Usage
- SDK Integration:
- If user's project needs database, cloud functions, and other features, need to introduce
@cloudbase/js-sdk@latest in the web application
Important: Authentication must use SDK built-in features. It is strictly forbidden to implement login authentication logic using cloud functions!
import cloudbase from "@cloudbase/js-sdk";
const app = cloudbase.init({
env: "xxxx-yyy", // Can query environment ID via envQuery tool
});
const auth = app.auth();
// Check current login state
let loginState = await auth.getLoginState();
if (loginState && loginState.user) {
// Logged in
const user = await auth.getCurrentUser();
console.log("Current user:", user);
} else {
// Not logged in - use SDK built-in authentication features
// Collect user's phone number into variable `phoneNum` by providing a input UI
// Send SMS code
const verificationInfo = await auth.getVerification({
phone_number: `+86 ${phoneNum}`,
});
// Collect user's phone number into variable `verificationCode` by providing a input UI
// Sign in
await auth.signInWithSms({
verificationInfo,
verificationCode,
phoneNum,
});
}
Initialization rules (Web, @cloudbase/js-sdk):
- Always use synchronous initialization with the pattern above
- Do not lazy-load the SDK with
import("@cloudbase/js-sdk")
- Do not wrap SDK initialization in async helpers such as
initCloudBase() with internal initPromise caches
- Keep a single shared
app/auth instance in your frontend app; reuse it instead of re-initializing
Web SDK API usage rules
- Only use documented CloudBase Web SDK methods
- Before calling any method on
app, auth, db, or other SDK objects, confirm it exists in the official CloudBase Web SDK documentation
- If a method or option is not mentioned in the official docs (for example some guessed method name), do NOT invent or use it
Authentication Best Practices
Must use SDK built-in authentication: CloudBase Web SDK provides complete authentication features, including login by SMS, anonymous login, custom login, etc.
Forbidden to implement login using cloud functions: Do not create cloud functions to handle login logic, this is the wrong approach
User data management: After login, user information can be obtained via auth.getCurrentUser(), then stored to database
Error handling: All authentication operations should include complete error handling logic
Build Process
Web project build process: Ensure npm install command has been executed first, then refer to project documentation for building
1---2name: web-development-23description: Web frontend project development rules. Use this skill when developing web frontend pages, deploying static hosting, and integrating CloudBase Web SDK.4---5
6## When to use this skill
7
8Use this skill for **Web frontend project development** when you need to:
9
10- Develop web frontend pages and interfaces
11- Deploy static websites to CloudBase static hosting
12- Integrate CloudBase Web SDK for database, cloud functions, and authentication
13- Set up modern frontend build systems (Vite, Webpack, etc.)
14- Handle routing and build configurations for static hosting
15
16**Do NOT use for:**
17- Mini-program development (use miniprogram-development skill)
18- Backend service development (use cloudrun-development skill)
19- UI design only (use ui-design skill, but may combine with this skill)
20
21---
22
23## How to use this skill (for a coding agent)
24
251. **Follow project structure conventions**
26 - Frontend source code in `src` directory
27 - Build output in `dist` directory
28 - Cloud functions in `cloudfunctions` directory
29 - Use modern frontend build systems (Vite, etc.)
30
312. **Use CloudBase Web SDK correctly**
32 - Always use SDK built-in authentication features
33 - Never implement login logic in cloud functions
34 - Use `envQuery` tool to get environment ID
35
363. **Deploy and preview properly**
37 - Build project first (ensure `npm install` is executed)
38 - Use relative paths for `publicPath` configuration
39 - Use hash routing for better static hosting compatibility
40 - Deploy to subdirectory if user doesn't specify root directory
41
42---
43
44# Web Frontend Development Rules
45
46## Project Structure
47
481. **Directory Organization**:
49 - Frontend source code should be stored in `src` directory
50 - Build output should be placed in `dist` directory
51 - Cloud functions should be in `cloudfunctions` directory
52
532. **Build System**:
54 - Projects should use modern frontend build systems like Vite
55 - Install dependencies via npm
56
573. **Routing**:
58 - If the frontend project involves routing, use hash routing by default
59 - Hash routing solves the 404 refresh issue and is more suitable for static website hosting deployment
60
61## Deployment and Preview
62
631. **Static Hosting Deployment**:
64 - For frontend projects, after building, you can use CloudBase static hosting
65 - First start local preview, then confirm with user if deployment to CloudBase static hosting is needed
66 - When deploying, if user has no special requirements, generally do not deploy directly to root directory
67 - Return deployed address in markdown link format
68
692. **Local Preview**:
70 - To preview static web pages locally, navigate to the specified output directory and use `npx live-server`
71
723. **Public Path Configuration**:
73 - When web projects are deployed to static hosting CDN, since paths cannot be known in advance, `publicPath` and similar configurations should use relative paths instead of absolute paths
74 - This solves resource loading issues
75
76## CloudBase Web SDK Usage
77
781. **SDK Integration**:
79 - If user's project needs database, cloud functions, and other features, need to introduce `@cloudbase/js-sdk@latest` in the web application
80
81**Important: Authentication must use SDK built-in features. It is strictly forbidden to implement login authentication logic using cloud functions!**
82
83```js
84import cloudbase from "@cloudbase/js-sdk";
85
86const app = cloudbase.init({
87 env: "xxxx-yyy", // Can query environment ID via envQuery tool
88});
89const auth = app.auth();
90
91// Check current login state
92let loginState = await auth.getLoginState();
93
94if (loginState && loginState.user) {
95 // Logged in
96 const user = await auth.getCurrentUser();
97 console.log("Current user:", user);
98} else {
99 // Not logged in - use SDK built-in authentication features
100
101 // Collect user's phone number into variable `phoneNum` by providing a input UI
102
103 // Send SMS code
104 const verificationInfo = await auth.getVerification({
105 phone_number: `+86 ${phoneNum}`,
106 });
107
108 // Collect user's phone number into variable `verificationCode` by providing a input UI
109
110 // Sign in
111 await auth.signInWithSms({
112 verificationInfo,
113 verificationCode,
114 phoneNum,
115 });
116}
117```
118
119**Initialization rules (Web, @cloudbase/js-sdk):**
120
121- Always use **synchronous initialization** with the pattern above
122- Do **not** lazy-load the SDK with `import("@cloudbase/js-sdk")`
123- Do **not** wrap SDK initialization in async helpers such as `initCloudBase()` with internal `initPromise` caches
124- Keep a single shared `app`/`auth` instance in your frontend app; reuse it instead of re-initializing
125
126### Web SDK API usage rules
127
128- Only use **documented** CloudBase Web SDK methods
129- Before calling any method on `app`, `auth`, `db`, or other SDK objects, **confirm it exists in the official CloudBase Web SDK documentation**
130- If a method or option is **not** mentioned in the official docs (for example some guessed method name), **do NOT invent or use it**
131
132## Authentication Best Practices
133
1341. **Must use SDK built-in authentication**: CloudBase Web SDK provides complete authentication features, including login by SMS, anonymous login, custom login, etc.
135
1362. **Forbidden to implement login using cloud functions**: Do not create cloud functions to handle login logic, this is the wrong approach
137
1383. **User data management**: After login, user information can be obtained via `auth.getCurrentUser()`, then stored to database
139
1404. **Error handling**: All authentication operations should include complete error handling logic
141
142## Build Process
143
144**Web project build process**: Ensure `npm install` command has been executed first, then refer to project documentation for building