Foreword
this project API>= 13
In the previous article, we realized the operation of a single module through DevEco Studio plug-in, which is relatively convenient. After all, it is a visual operation. However, the plug-in has a potential problem to inform, that is, if a single module does not have a default page, it will report an error at runtime, that is, each module needs an Index.ets page is used as the main entrance of the module. However, when creating a module, this page will be created by default. Please do not delete it. Of course, the plug-in will be optimized later. Without this default page, one will be created by default.
Today's content is also related to component-based operation, but in a different way, it is implemented through node scripts.
The method of the node script is the same as the method and function of the IDE plug-in, but the implementation is different. To use the node script, you do not need to install the IDE plug-in, just put the script in the project.
node script configuration
the script address is as follows:
https://abnerming888.github.io/vip/load/start.js
you can create a new file with the same name under the root directory of your project and copy the contents, as shown in the following figure:
the script can be divided into four blocks. node start is the first two blocks. It is a fixed mode. start is the name of your footstep file. If you do not save the name of start, you can change it to your name. The third block is the name of the component you want to switch, that is, the module you want to run. The fourth block is the default page path. This can not be transferred. The default is pages/Index, the execution cases are as follows:
node start modulename
Hongmeng development requires a node environment. Generally, we do not need to configure it Additionally. When downloading DevEco Studio, we will configure it ourselves. In order to verify whether the node environment exists, we can enter node -v at the bottom terminal of DevEco Studio. If the publishing number can be displayed correctly, there is a node environment.
If there is no node environment, I mean if, there are two ways to solve it. The first is that you can download it from the node official website and configure your own environment variables. The second is to use the node environment brought by DevEco Studio.
The node environment in DevEco Studio, we can click the Run Menu button at the top, click Edit Configurations..., As shown in the following figure:
click Hvigor on the left to select one. The Node interpreter on the right is the node environment that the IDE comes:
MAC computer use
if your computer is a MAC, after copying, you need to add a "/node" after it, as shown below:
/Applications/DevEco-Studio.app/Contents/tools/node/bin/node
it can be found that the node version can be obtained, but it is only the full path.
Windows computer use
if your computer is a Windows system, double quotation marks are required for copying to execute the command correctly, and the suffix is "\node.exe", as shown below:
"F:\soft\harmonyIDE\devecostudio-windows-5.0.11.100\config\DevEco Studio\tools\node\node.exe"
when executing the Command, directly copy the node path above. Note that the Command Prompt option is selected.
Of course, whether it is Windows or Mac, if there is no node environment, you still hope that you can configure global environment variables to facilitate command execution.
node script using
it is very simple to use. You only need to execute the module command you want to run in the terminal at the bottom. For example, I want the home module to run:
after executing the command, to prevent errors, you need to synchronize and refresh the project, as shown in the following figure:
then select the home module and click Run:
if an application with the same package name is already running on the device, you need to uninstall the original one and install it again. Just click the blue color of the console:
after the above execution, if your module does not set the default Launch, you need to manually configure it once, only for the first time. If it has already been configured, it will run directly on the device.
Click on the running module and select Edit Configuration:
find Launch and select Default Ability:
related Summary
node script needs to manually execute commands in the terminal and switch modules to run. Compared with the IDE plug-in in the previous article, the efficiency is somewhat lower. However, after proficiency, the problem is not big. Currently, two methods have been provided. You can choose the method you like.
This article label: Hongmeng Development Tools/DevEco Studio
Top comments (0)