Install the HBuilderX development tool
Download HBuilderX
HBuilderX is the official uni-app development tool from DCloud, supporting Windows, macOS, and Linux systems. First, download the corresponding installation package from the official website:
- Official download link: https://www.dcloud.io/hbuilderx.html
- Windows users should select the
.exe
installer - macOS users should select the
.dmg
disk image - Linux users should choose the
.AppImage
or.deb
package
After downloading, Windows users can double-click the installer and follow the wizard to complete the installation; macOS users can drag the application to the Applications folder; Linux users can grant execution permissions to the AppImage file and run it directly.
Initial Setup
When launching HBuilderX for the first time, you will be prompted to perform initial setup:
- Choose a theme (recommend "Dark" for eye protection)
- Set the default project storage path
- Install necessary plugins:
- Must install the "uni-app Compilation" plugin
- Recommended to install "ESLint" and "Prettier" for code formatting
- Configure the node.js path (if already installed)
# Check if node.js is installed successfully
node -v
npm -v
Create a uni-app Project
Create a new project via the top menu:
- File → New → Project
- Select the "uni-app" project type
- Fill in the project name and storage path
- Choose a template (recommend "Default Template")
- Click the "Create" button
Project directory structure explanation:
├── pages # Pages directory
│ └── index # Homepage
│ ├── index.vue
│ └── index.json
├── static # Static resources
├── App.vue # Application entry
└── manifest.json # App configuration
Run and Debug
HBuilderX provides multiple ways to run and debug:
- Run in Browser: Click "Run" → "Run to Browser" in the toolbar
- Real Device Debugging:
- Android: Connect the phone and enable USB debugging
- iOS: Requires macOS system
- Emulator Run:
- Recommended Android emulator: "Nox Player"
- iOS emulator requires Xcode
Debugging tips:
- Use
console.log()
to output logs - View runtime information in the "Debug Console"
- Use the "Element Inspection" feature to examine page structure
// Example: Print current page route
onLoad() {
console.log('Current page path:', this.$route.path)
}
Common Feature Configuration
Enhanced Code Hinting
- Install the "Vetur" plugin for better Vue syntax support
- Configure jsconfig.json for path alias hints:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}
Shortcut Settings
Recommended shortcut configurations (File → Preferences → Shortcuts):
- Format document: Ctrl+Alt+L
- Quick comment: Ctrl+/
- Rename: F2
Code Snippets
Create custom code snippets to improve efficiency:
- Tools → Snippet Settings → vue.json
- Add common templates:
{
"uni-page": {
"prefix": "upage",
"body": [
"<template>",
" <view class=\"container\">",
" $1",
" </view>",
"</template>",
"",
"<script>",
"export default {",
" data() {",
" return {",
" $2",
" }",
" }",
"}",
"</script>",
"",
"<style scoped>",
".container {",
" padding: 20rpx;",
"}",
"</style>"
]
}
}
Project Packaging and Release
WeChat Mini Program Packaging
- Configure the WeChat Mini Program AppID in manifest.json
- Run → Release → WeChat Mini Program
- Open the generated dist directory in WeChat Developer Tools
APP Packaging
- Certificates are required (Android: keystore, iOS: p12)
- Select "Native APP - Cloud Packaging"
- Wait for DCloud servers to complete compilation
// Example: Get app version number
plus.runtime.getProperty(plus.runtime.appid, (info) => {
console.log('Current version:', info.version)
})
Plugin Ecosystem
HBuilderX supports a rich set of plugins:
- UI Library Plugins:
- uView UI
- colorUI
- Tool Plugins:
- Git version control
- Code beautification
- Debugging Plugins:
- Network request capture
- Performance analyzer
Installation method:
- Tools → Plugin Installation
- Search for the desired plugin and click install
- Restart to take effect
Performance Optimization Tips
- Use "Runtime Compression" to reduce package size
- Configure "Image Compression" to automatically process static resources
- Enable "Tree Shaking" to remove unused code
- Use subpackage loading for large projects:
// manifest.json
{
"optimization": {
"subPackages": true
}
}
Troubleshooting
Common issue resolutions:
-
Cannot recognize node_modules:
- Delete package-lock.json in the project
- Run
npm install
again
-
Blank screen on real device debugging:
- Check if USB debugging is enabled on the phone
- Reconnect the data cable
-
Styles not taking effect:
- Check if the
scoped
attribute is added - Use deep selectors:
- Check if the
/* Penetrate component styles */
::v-deep .custom-class {
color: red;
}
本站部分内容来自互联网,一切版权均归源网站或源作者所有。
如果侵犯了你的权益请来信告知我们删除。邮箱:cc@cccx.cn
上一篇:与原生混合开发方案
下一篇:Vue3整体架构概述