如何实时编译WePY项目

使用wepy init命令初始化项目后,只是得到了一个模板项目,如果想开启实时编译,得到小程序项目

实时编译WePY项目步骤如下:

运行cd myproject切换至WePY项目根目录

运行npm install 安装WePY项目依赖性,执行显示的信息如下:

npm install
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprec
ated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#dep
recated
npm WARN deprecated smartwrap@1.2.5: Backported compatibility to node > 6
npm WARN deprecated request@2.88.2: request has been deprecated, see https://git
hub.com/request/request/issues/3142
npm WARN deprecated circular-json@0.3.3: CircularJSON is in maintenance only, fl
atted is its successor.
npm WARN deprecated coffee-script@1.12.7: CoffeeScript on NPM has moved to "coff
eescript" (no hyphen)
npm WARN deprecated request@2.88.0: request has been deprecated, see https://git
hub.com/request/request/issues/3142
npm WARN deprecated babel-eslint@7.2.3: babel-eslint is now @babel/eslint-parser
. This package will no longer receive updates.
npm WARN deprecated core-js@2.6.12: core-js@<3 is no longer maintained and not r
ecommended for usage due to the number of issues. Please, upgrade your dependenc
ies to the actual version of core-js@3.

added 778 packages in 56s
npm notice
npm notice New patch version of npm available! 7.6.0 -> 7.6.3
npm notice Changelog: https://github.com/npm/cli/releases/tag/v7.6.3
npm notice Run npm install -g npm@7.6.3 to update!
npm notice

运行 wepy build --watch开启实时编译。

wepy build --watch 命令之后系统信息显示如下:

[23:17:44] info build app start...
[23:17:47] info app building App
[23:17:48] info component building components
[23:17:49] info component building components
[23:17:49] info component building components
[23:17:49] info vendor building vendor
[23:17:49] info assets building assets
[23:17:49] info build finished
[23:17:49] info watching...

注意: wepy build --watch 命令,会循环监听 WePY 项目中源代码的变化。

自动编译成生成小程序项目。生成的小程序项目,默认被存放disc目录中。

WePY项目的目录结构

├── dist  小程序运行代码目录,该目录由wepy的build的指令自动编译生成,请不要直接修改该目录下的文件。
├── node_modules         依赖
├── src                   wepy代码编写的目录
|   ├── components         WePY组件目录
|   |   ├─- com_a.wpy      可复用的WePY组件a
|   |   └── com_b.wpy     可复用的WePY组件b
|   ├── pages                 WePY页面目录(属于完整页面)
|   |   ├── index.wpy       index页面
|   |   └── other.wpy       other页面
|   └── app.wpy  小程序配置项(全局数据、样式、声明钩子等,经过build后,会在disc目录下生成APP.js,app.json和app.wxss文件)
└── package.json           项目的package配置