跳转至

开发环境准备

一、NodeJs和npm

1.1 NodeJs

官网地址:https://nodejs.org/en

Node.js®是一个免费、开源、跨平台的JavaScript运行时环境,可让开发人员创建服务器、Web应用程序、命令行工具和脚本。

安装参考 编程语言--NodeJs--NodeJs安装配置

1.2 NVM for Windows

这里建议使用nvm的版本管理工具,NVM for Windows

Text Only
Running version 1.1.12.

Usage:

  nvm arch                     : Show if node is running in 32 or 64 bit mode.
  nvm current                  : Display active version.
  nvm debug                    : Check the NVM4W process for known problems (troubleshooter).
  nvm install <version> [arch] : The version can be a specific version, "latest" for the latest current version, or "lts" for the
                                 most recent LTS version. Optionally specify whether to install the 32 or 64 bit version (defaults
                                 to system arch). Set [arch] to "all" to install 32 AND 64 bit versions.
                                 Add --insecure to the end of this command to bypass SSL validation of the remote download server.
  nvm list [available]         : List the node.js installations. Type "available" at the end to see what can be installed. Aliased as ls.
  nvm on                       : Enable node.js version management.
  nvm off                      : Disable node.js version management.
  nvm proxy [url]              : Set a proxy to use for downloads. Leave [url] blank to see the current proxy.
                                 Set [url] to "none" to remove the proxy.
  nvm node_mirror [url]        : Set the node mirror. Defaults to https://nodejs.org/dist/. Leave [url] blank to use default url.
  nvm npm_mirror [url]         : Set the npm mirror. Defaults to https://github.com/npm/cli/archive/. Leave [url] blank to default url.
  nvm uninstall <version>      : The version must be a specific version.
  nvm use [version] [arch]     : Switch to use the specified version. Optionally use "latest", "lts", or "newest".
                                 "newest" is the latest installed version. Optionally specify 32/64bit architecture.
                                 nvm use <arch> will continue using the selected version, but switch to 32/64 bit mode.
  nvm root [path]              : Set the directory where nvm should store different versions of node.js.
                                 If <path> is not set, the current root will be displayed.
  nvm [--]version              : Displays the current running version of nvm for Windows. Aliased as v.
  • nvm list 可以查看当前已经安装的版本,以及当前正在使用的版本
  • nvm list available 可以查询到库上当前存在的node版本信息,信息数据来自https://nodejs.org/dist/index.json
  • nvm use 设置需要使用的版本。
  • nvm install 指定安装的版本,并进行安装。

1.3 npm命令

npm不需要单独的安装,node.js安装好之后,npm命令就可以执行了。

1)命令帮助

Text Only
npm <command>

Usage:

npm install        install all the dependencies in your project
npm install <foo>  add the <foo> dependency to your project
npm test           run this project's tests
npm run <foo>      run the script named <foo>
npm <command> -h   quick help on <command>
npm -l             display usage info for all commands
npm help <term>    search for help on <term> (in a browser)
npm help npm       more involved overview (in a browser)

All commands:

    access, adduser, audit, bugs, cache, ci, completion,
    config, dedupe, deprecate, diff, dist-tag, docs, doctor,
    edit, exec, explain, explore, find-dupes, fund, get, help,
    help-search, hook, init, install, install-ci-test,
    install-test, link, ll, login, logout, ls, org, outdated,
    owner, pack, ping, pkg, prefix, profile, prune, publish,
    query, rebuild, repo, restart, root, run-script, sbom,
    search, set, shrinkwrap, star, stars, start, stop, team,
    test, token, uninstall, unpublish, unstar, update, version,
    view, whoami

Specify configs in the ini-formatted file:
    C:\Users\z00579768\.npmrc
or on the command line via: npm <command> --key=value

More configuration info: npm help config
Configuration fields: npm help 7 config

npm@10.8.0 D:\NodeJs\node_global\node_modules\npm

2)npmrc的配置

Text Only
1
2
3
4
5
6
7
8
electron_mirror=https://npmmirror.com/mirrors/electron/
electron_builder_binaries_mirror=https://npmmirror.com/mirrors/electron-builder-binaries/
registry=http://registry.npmmirror.com/
@ohos:registry=https://repo.harmonyos.com/npm/
NODE_TLS_REJECT_UNAUTHORIZED=0
always-auth=false
strict-ssl=false
audit=false

3)npm指定镜像进行安装

Text Only
1
2
3
npm install --registry=https://registry.npmmirror.com --loglevel verbose  -g remarkable
// --loglevel verbose 可以在安装过程中,显示日志到console上
// -g 指示安装到系统配置的node_global目录中,作为全局工具使用

4)npm config

设置镜像地址

Text Only
npm config set registry="镜像地址"

获取当前镜像信息

Text Only
npm config get registry

查询所有的配置

Text Only
npm config list

5)npm help

可以使用npm help [command]命令获取详细的帮助信息。

帮助文档实际上是在本地的/node_global/node_modules/npm/docs/output/commands/npm.html

二、vue

2.1 npm

更新到最新版本

Text Only
npm install -g npm
npm install -g npm@latest

2.2 cnpm

国内大家可能使用淘宝的镜像比较多。我个人使用的也是淘宝的镜像。

使用淘宝的镜像,npm命令安装的时候,可能会超时,或者证书过期之类的。所以可以使用定制的cnpm

Text Only
npm install cnpm -g

2.3 vue相关

1)安装vue命令

命令

Text Only
npm install vue

安装Vue的最新稳定版本

Text Only
npm install vue@next

安装Vue的最新指定版本

Text Only
npm install vue@{version}

安装vue-cli

Text Only
npm install @vue/cli
npm install vue-cli

安装vue-router

Text Only
npm install vue-router

2)electron相关

Text Only
npm install electron

electron-builder

Text Only
npm install electron-builder