English
In addition to the HBuilderX visual interface, you can also use cli
scaffolding, and you can create an uni-app
project through vue-cli
.
Install vue-cli globally
npm install -g @vue/cli
Use the official version (corresponding to the latest official version of HBuilderX)
vue create -p dcloudio/uni-preset-vue my-project
Use the alpha version (corresponding to the latest alpha version of HBuilderX)
vue create -p dcloudio/uni-preset-vue#alpha my-alpha-project
Use Vue3/Vite version
npx degit dcloudio/uni-preset-vue#vite my-vue3-project
npx degit dcloudio/uni-preset-vue#vite-alpha my-vue3-project
npx degit dcloudio/uni-preset-vue#vite-ts my-vue3-project
At this point, you will be prompted to select a project template (the Vue3/Vite version will not prompt, currently only the default template can be created). It is recommended to select the hello uni-app
project template for the first experience, as shown below:
Notice
When choosing a custom template, you need to fill in the uni-app template address, which is actually the address of the repository hosted in the Cloud. Take GitHub as an example, the address format is userName/repositoryName
, such as dcloudio/uni-template-picture
is to download the image template.
For more supported download methods, please refer to the description of this plug-in: download-git-repo
The template project is stored in Github. The download may fail due to network problems in China. To solve this problem, the following measures can be taken:
You can use @dcloudio/uvm to manage the version of the compiler. This tool only automatically adds or updates the main dependencies of the uni-app compiler. For new Compilation commands (scripts) of the command line will not be processed automatically for the time being, and need to be manually configured with reference to the new project.
npx @dcloudio/uvm@latest
npx @dcloudio/uvm@latest alpha
npx @dcloudio/uvm@latest 3.2.0
npx @dcloudio/uvm@latest 3.2.12.20211029
npx @dcloudio/uvm@latest 3.2.0-alpha
npx @dcloudio/uvm@latest 3.2.14.20211112-alpha
npm run dev:%PLATFORM%
npm run build:%PLATFORM%
The possible values of %PLATFORM%
are as follows:
Value | Platform |
---|---|
h5 | H5 |
mp-alipay | Alipay Mini Program |
mp-baidu | Baidu Mini Program |
mp-weixin | 微信小程序 |
mp-toutiao | 抖音小程序 |
mp-lark | Feishu Mini Program |
mp-qq | qq applet |
mp-360 | 360 Mini Program |
mp-kuaishou | Kaishou Mini Program |
mp-jd | JD Mini Program |
mp-xhs | Xiaohongshu Mini Program |
quickapp-webview | Quick App(webview) |
quickapp-webview-union | Quick App Union |
quickapp-webview-huawei | Quick App Huawei |
You can customize more conditional compilation platforms, such as DingTalk applet, refer to package.json document.
There are two development methods for quick apps, both of which are supported by uni-app:
HBuilderX version 2.7.12+ support
HBuilderX version 2.7.10+ support
Huawei Quick App Documentation - Mini Program Quick App [https://developer.huawei.com/consumer/cn/doc/development/quickApp-References/quickapp-filestructure](https://developer.huawei.com/consumer/ cn/doc/development/quickApp-References/quickapp-filestructure)
Others:
npm run build:app-plus
will generate app packaging resources under /dist/build/app-plus
. To make a wgt package, compress the files in app-plus
into zip (note: do not include app-plus directory
), and rename it to ${appid}.wgt
. appid
is the appid
in manifest.json
file./dist/dev/
directory under the root directory. Open the development tools of each platform and select the corresponding platform directory to preview (the h5 platform will not be in this directory, but will exist in the cache);/dist/build/
directory under the root directory, and this directory is selected for publishing when publishing;Some developers who are accustomed to cli are not comfortable when using the HBuilderX visualization mode. Explain their differences and why HBuilderX provides multiple ways.
First of all, as a general editor, HBuilderX is compatible with traditional cli development. Not only the cli of uni-app, but also the cli of other frameworks can be dragged into HBuilderX.
That is to say, you can use the visual interface to create projects in HBuilderX, or you can use the cli command line to create projects, which can achieve the purpose of better collaboration with uni-app. Such as pages.json jumps and prompts, manifest visual interface, conditional compilation, rpx and other css units... Many optimizations for uni-app can be used.
These are the characteristics of HBuilderX and have nothing to do with the project structure.
Well understood. Because other IDEs do not have built-in uni-app compilers, other IDEs develop uni-apps and can only install the compiler under the project, which is the project format created by cli.
CLI projects can be developed using a variety of IDEs, but there are differences between IDEs:
HBuilderX creates, runs, and publishes projects visually, and the underlying calls are also npm's run, build and other commands. It's just that the compiler is not under the project, but in the directory of HBuilderX.
Many developers are unfamiliar with node and have psychological resistance to the command line. Don't take it for granted that all developers can use node. HBuilder has millions of developers, and less than half of them master node.
When using cli to create a project, cli needs to be installed from npm, and the preset project template can be downloaded from github. These are often stuck due to network problems. Visually created projects do not have this problem.
An HBuilderX developer has a lot of uni-app projects. If each project decentralizes a set of compilers, there will be many unreasonable: - Creating projects can be very slow - Very disk space intensive (uni-app's compiler has tens of thousands of files) - It is troublesome to upgrade, and there are many compatibility problems. The compiler under the cli project will not be upgraded with the upgrade of HBuilderX, and only the developer can upgrade by typing the npm command. When HBuilderX is upgraded, the compilers of some uni-app projects have not been upgraded, while others have been upgraded. Developers are easily confused when reporting errors, and DCloud is also confused when reporting bugs to DCloud. Keeping the ide version, compiler version, and uni-app runtime version consistent will reduce a lot of problems.
The compiler is built into HBuilderX, developers only need to care about their own business code when creating a project, and the project structure is clean and refreshing.
Every applet also does this. The compiler is in the applet development tool. When creating a project, it will not bring a set of compilers under the project (the applet also needs to compile wxml into js).
The node-free development provided by HBuilderX is not only easy to use, but also more efficient.
Ctrl+N
Ctrl+R
Ctrl+U
This is much faster than starting the terminal, moving the focus to the terminal window, and typing commands.
In uni-app, the terminal commands are more and longer than traditional web development, and you need to type the platform parameters to choose whether you want to run to the web or an app or a small program.
To sum up,
If you are used to node, you can also accept and manage the way of a set of compilers under each project, and know the above pros and cons, then you can choose cli to create a project.
As for ide, it is definitely more efficient to develop HBuilderX with uni-app.
If you are used to other IDEs and it doesn't matter if developing uni-apps is inefficient, you can use other IDEs too. But note that at least when running the debugging app and uniCloud, you have to open HBuilderX, just like opening the WeChat applet tool for debugging.
Inside DCloud, uni-app and HBuilderX are different teams.
cli
创建的项目,编译器安装在项目下。并且不会跟随HBuilderX升级。如需升级编译器,可以参考:更新依赖到指定版本。cli
创建的项目,如果想继续在HBuilderX里使用,可以把工程拖到HBuilderX中。注意如果是把整个项目拖入HBuilderX,则编译时走的是项目下的编译器。如果是把src目录拖入到HBuilderX中,则走的是HBuilderX安装目录下plugin目录下的编译器。cli
创建的项目,内置了d.ts,同其他常规npm库一样,可在vscode、webstorm等支持d.ts的开发工具里正常开发并有语法提示。npm init
,然后npm i @dcloudio/types -D
,来补充d.ts。cli
to create a project, the uni-app compiler in the HBuilderX plugin list can not be installedcli
, please scan the code to join the uni-app WeChat exchange group discussion: