如何安装wepy/cli 1.x和2.x

现在wepy已经到2.x了

我们看下如何安装 wepy 1.x 和 wepy 2.x

如果wepy版本冲突会有什么发生什么情况呢?

wepy目录

安装 wepy/cli 1.x

安装 wepy/cli 2.x

wepy 1.x 执行 wepy-templates-2.0.x 模板报错解决方案

安装 wepy/cli 1.x

npm install wepy-cli -g

npm install wepy-cli -g

安装 wepy/cli 2.x

npm install @wepy/cli -g

npm install @wepy/cli -g

初始化创建一个工程wepy

C:\Users\Administrator>wepy init standard myprojection
[23:31:51] WARN Download from Github raw failed, try Tencent COS download
[23:31:51] WARN connect ETIMEDOUT 199.232.68.133:443

'git'
? Project name myprojection
? AppId touristappid
? Project description A WePY project
? Author
? Use ESLint to lint your code? Yes
? Choose a state container Vuex

[23:50:11] info Generated "myprojection".

wepy安装依赖

C:\Users\Administrator\myprojection>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 circular-json@0.3.3: CircularJSON is in maintenance only, fl
atted is its successor.
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 smartwrap@1.2.5: Backported compatibility to node > 6
npm WARN deprecated request@2.88.0: request has been deprecated, see https://git
hub.com/request/request/issues/3142
npm WARN deprecated request@2.88.2: request has been deprecated, see https://git
hub.com/request/request/issues/3142
npm WARN deprecated coffee-script@1.12.7: CoffeeScript on NPM has moved to "coff
eescript" (no hyphen)
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 54s

启动并开始监听wepy项目

wepy build --watch

wepy 1.x 执行 wepy-templates-2.0.x 模板时报错如下:

 var mainPages = wpy.config.pages.map(function (v) {
                                             ^

TypeError: Cannot read property 'map' of undefined

wepy build --watch
[23:12:58] [编译] 入口: src\app.wpy
C:\Users\Administrator\AppData\Roaming\npm\node_modules\wepy-cli\lib\compile-wpy
.js:478
            var mainPages = wpy.config.pages.map(function (v) {
                                             ^

TypeError: Cannot read property 'map' of undefined
    at Object.compile (C:\Users\Administrator\AppData\Roaming\npm\node_modules\
[4mwepy-cli\lib\compile-wpy.js:478:46)
    at Object.compile (C:\Users\Administrator\AppData\Roaming\npm\node_modules\
[4mwepy-cli\lib\compile.js:407:38)
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\wepy-cli
\lib\compile.js:385:47
    at Array.forEach (<anonymous>)
    at Object.build (C:\Users\Administrator\AppData\Roaming\npm\node_modules\[4
mwepy-cli\lib\compile.js:379:19)
    at Command.module.exports (C:\Users\Administrator\AppData\Roaming\npm\node_m
odules\wepy-cli\lib\bin\wepy-build.js:12:21)
    at Command.listener (C:\Users\Administrator\AppData\Roaming\npm\node_modules
\wepy-cli\node_modules\commander\index.js:315:8)
    at Command.emit (events.js:210:5)
    at Command.parseArgs (C:\Users\Administrator\AppData\Roaming\npm\node_module
s\wepy-cli\node_modules\commander\index.js:651:12)
    at Command.parse (C:\Users\Administrator\AppData\Roaming\npm\node_modules\[
4mwepy-cli\node_modules\commander\index.js:474:21)
    at Object.<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modul
es\wepy-cli\lib\bin\wepy.js:44:21)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10
)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Module.require (internal/modules/cjs/loader.js:852:19)

解决方案 卸载wepy 1.x ,安装 wepy/cli 2.x

npm install @wepy/cli -g

最后执行 wepy build --watch 发现项目正常启动

C:\Users\Administrator\myprojection>wepy build --watch
[23:53:01] info build app start...
[23:53:03] info app building App
[23:53:04] info component building components
[23:53:04] info component building components
[23:53:04] info component building components
[23:53:04] info vendor building vendor
[23:53:04] info assets building assets
[23:53:04] info build finished
[23:53:04] info watching...