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