windows下npm安裝vue
1、使用以前,咱們先來掌握3個東西是用來幹什麼的。
npm: Nodejs下的包管理器。
webpack: 它主要的用途是經過CommonJS的語法把全部瀏覽器端須要發佈的靜態資源作相應的準備,好比資源的合併和打包。
vue-cli: 用戶生成Vue工程模板。(幫你快速開始一個vue的項目,也就是給你一套vue的結構,包含基礎的依賴庫,只須要 npm install就能夠安裝)
開始:
![](http://static.javashuo.com/static/loading.gif)
如圖,下載8.9.3 LTS (推薦給絕大部分用戶使用)
![](http://static.javashuo.com/static/loading.gif)
雙擊安裝
![](http://static.javashuo.com/static/loading.gif)
可使用默認路徑,本例子中自行修改成d:\nodejs
![](http://static.javashuo.com/static/loading.gif)
一路點Next
![](http://static.javashuo.com/static/loading.gif)
點Finish完成
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
打開CMD,檢查是否正常
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
再看看另外2個目錄,npm的本地倉庫跑在系統盤c盤的用戶目錄了(沒見到npm-cache是由於沒有用過,一使用緩存目錄就生成了),咱們試圖把這2個目錄移動回到D:\nodejs
先以下圖創建2個目錄
![](http://static.javashuo.com/static/loading.gif)
而後運行如下2條命令
npm config set prefix "D:\nodejs\node_global"
npm config set cache "D:\nodejs\node_cache"
![](http://static.javashuo.com/static/loading.gif)
如上圖,咱們再來關注一下npm的本地倉庫,輸入命令npm list -global
![](http://static.javashuo.com/static/loading.gif)
輸入命令npm config set registry=http://registry.npm.taobao.org 配置鏡像站
![](http://static.javashuo.com/static/loading.gif)
輸入命令npm config list 顯示全部配置信息,咱們關注一個配置文件
C:\Users\Administrator\.npmrc
![](http://static.javashuo.com/static/loading.gif)
使用文本編輯器編輯它,能夠看到剛纔的配置信息
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
檢查一下鏡像站行不行命令1
npm config get registry
![](http://static.javashuo.com/static/loading.gif)
檢查一下鏡像站行不行命令2
Npm info vue 看看可否得到vue的信息
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
注意,此時,默認的模塊D:\nodejs\node_modules 目錄
將會改變爲D:\nodejs\node_global\node_modules 目錄,
若是直接運行npm install等命令會報錯的。
咱們須要作1件事情:
一、增長環境變量NODE_PATH 內容是:D:\nodejs\node_global\node_modules
![](http://static.javashuo.com/static/loading.gif)
(注意,一下操做須要從新打開CMD讓上面的環境變量生效)
1、測試NPM安裝vue.js
命令:npm install vue -g
這裏的-g是指安裝到global全局目錄去
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
2、測試NPM安裝vue-router
命令:npm install vue-router -g
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
運行npm install vue-cli -g安裝vue腳手架
![](http://static.javashuo.com/static/loading.gif)
![](http://static.javashuo.com/static/loading.gif)
編輯環境編輯path
![](http://static.javashuo.com/static/loading.gif)
對path環境變量添加D:\nodejs\node_global
win10如下版本的,橫向顯示PATH的,注意添加到最後時,不要有分號【;】
![](http://static.javashuo.com/static/loading.gif)
從新打開CMD,而且測試vue是否使用正常
![](http://static.javashuo.com/static/loading.gif)
注意,vue-cli工具是內置了模板包括 webpack 和 webpack-simple,前者是比較複雜專業的項目,
他的配置並不全放在根目錄下的 webpack.config.js 中。
![](http://static.javashuo.com/static/loading.gif)
初始化,安裝依賴
![](http://static.javashuo.com/static/loading.gif)
運行npm install安裝依賴
![](http://static.javashuo.com/static/loading.gif)
npm run dev
![](http://static.javashuo.com/static/loading.gif)
成功界面,提示打開地址http://localhost:8080
![](http://static.javashuo.com/static/loading.gif)
自動打開瀏覽器http://localhost:8080/#/
![](http://static.javashuo.com/static/loading.gif)
npm run build
生成靜態文件,打開dist文件夾下新生成的index.html文件
nmp下新建出來的vue01的目錄描述:
![](http://static.javashuo.com/static/loading.gif)
歡迎關注本站公眾號,獲取更多信息