欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue執(zhí)行配置選項npm?run?serve的本質(zhì)圖文詳解

 更新時間:2023年05月04日 11:23:08   作者:pulledup  
本地開發(fā)一般通過執(zhí)行npm run serve命令來啟動項目,那這行命令到底存在什么魔法?下面這篇文章主要給大家介紹了關(guān)于vue執(zhí)行配置選項npm?run?serve的本質(zhì)的相關(guān)資料,需要的朋友可以參考下

一、啟動開發(fā)服務(wù)器、調(diào)用“工具鏈”、編譯、并運(yùn)行當(dāng)前工程

npm run serve

該命令的配置文件在當(dāng)前工程的package.json文件中,隨@vue/cli腳手架驅(qū)動產(chǎn)生的vue的工程默認(rèn)自動生成: 

 (圖1)

  (圖2)

二、npm run serve內(nèi)部原理分析

打開“工程”下的node包依賴路徑下的“可執(zhí)行腳本”目錄:node_modules\bin

(圖3)

如 圖3 所示,vue-cli-service.cmd文件,即 圖1 所運(yùn)行的實(shí)際腳本,運(yùn)行其命令行幫助:

(圖4)

得知其需要1些選項來執(zhí)行命令( 如 圖4 所示):

(圖5)

分別打開 圖5 所示的兩個文件,得知vue-cli-service.cmd需要帶1個“選項參數(shù)”來執(zhí)行內(nèi)部命令( 如 圖6、圖7 所示):

(圖6)

(圖7)

通過分析 vue-cli-service.js 源碼:

(圖8)

得知,“選項參數(shù)” 的別名,分別為 build、 serve 、inspect :

#!/usr/bin/env node
const { semver, error } = require('@vue/cli-shared-utils')
const requiredVersion = require('../package.json').engines.node
if (!semver.satisfies(process.version, requiredVersion, { includePrerelease: true })) {
  error(
    `You are using Node ${process.version}, but vue-cli-service ` +
    `requires Node ${requiredVersion}.\nPlease upgrade your Node version.`
  )
  process.exit(1)
}
const Service = require('../lib/Service')
const service = new Service(process.env.VUE_CLI_CONTEXT || process.cwd())
const rawArgv = process.argv.slice(2)
const args = require('minimist')(rawArgv, {
  boolean: [
    // build
    'modern',
    'report',
    'report-json',
    'inline-vue',
    'watch',
    // serve
    'open',
    'copy',
    'https',
    // inspect
    'verbose'
  ]
})
const command = args._[0]
service.run(command, args, rawArgv).catch(err => {
  error(err)
  process.exit(1)
})

因而,開發(fā)環(huán)境,npm run serve 的原生CLI命令行腳本為:

node .\node_modules\@vue\cli-service\bin\vue-cli-service.js serve

同理,生產(chǎn)環(huán)境,進(jìn)行分發(fā)時,npm run build 的原生CLI命令行腳本為:

node .\node_modules\@vue\cli-service\bin\vue-cli-service.js build

三、vue編譯運(yùn)行過程

npm run serve、npm run build等“調(diào)試運(yùn)行腳本”:僅僅是Vue默認(rèn)在內(nèi)部做了1個“命令行”封裝而已!以包配置文件(package.json)的形式與用戶交互。

 
# 過程大致如此:
#         INFO  Starting development server... 
# node調(diào)用各個相關(guān)模塊并運(yùn)行:
node.exe
# vue內(nèi)置webpack開始啟動開發(fā)服務(wù)器webpack-dev-server :
 .\node_modules\webpack-dev-server\client\index.js?http://192.168.3.242:8081&sockPath=/sockjs-node 
 .\node_modules\webpack\hot\dev-server.js
 .\node_modules\webpack-dev-server\client\index.js?http://192.168.3.242:8081&sockPath=/
# vue內(nèi)置webpack調(diào)用cache-loader和babel-loader解析代碼進(jìn)行語法分析、依賴分析:
 .\node_modules\cache-loader\dist\cjs.js??ref--13-0!
 .\node_modules\babel-loader\lib\index.js!
# ...........
# vue-loader加載器啟動選項:
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!
# 對你的工程中的文件進(jìn)行語法及依賴分析:
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!.\src\App.vue?vue&type=te
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!.\src\A
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!.\src\components\Avatar.vue?vue&type=tem
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!.\src\components\Avat
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!.\src\A
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!.\src\components\Avat
 .\node_modules\babel-loader\lib\index.js
 .\node_modules\cache-loader\dist\cjs.js??ref--13-0!
# ...........
# vue-loader開始調(diào)用index.js處理你的工程中的文件:
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!.\src\App.vue?vue&type=te
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!.\src\components\Avatar.vue?vue&type=tem
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!.\src\components\Avatar.vue?vue&type=tem
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!.\src\App.vue?vue&type=style&index=0&id=
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!.\src\components\Avatar.vue?vue&type=style&index=0&id=5811d
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!.\src\App.vue?vue&type=style&index=0&id=
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!.\src\components\Avatar.vue?vue&type=style&index=0&id=5811d
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!.\src\App.vue?vue&type=style&index=0&id=
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!.\src\components\Avatar.vue?vue&type=style&index=0&id=5811d
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!.\src\components\Avatar.vue?vue&type=style&index=0&id=5811d
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!.\src\components\Avatar.vue?vue&type=style&index=0&id=5811d
 .\node_modules\vue-loader\lib\index.js??vue-loader-options!.\src\components\Avatar.vue?vue&type=style&index=0&id=5811d
# 完成“構(gòu)建”并啟動應(yīng)用:
# 98% after emitting CopyPlugin
#  DONE  Compiled successfully in 5177ms                                                                                                                                                                                                                                                                                                   上午4:56:59
#   App running at:
#   - Local:   http://localhost:8081/
#   - Network: http://192.168.3.242:8081/
# 
#   Note that the development build is not optimized.
#   To create a production build, run npm run build.
 

總結(jié)

到此這篇關(guān)于vue執(zhí)行配置選項npm run serve的本質(zhì)的文章就介紹到這了,更多相關(guān)vue執(zhí)行配置選項npm run serve內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 基于Vue設(shè)計實(shí)現(xiàn)一個彈幕組件

    基于Vue設(shè)計實(shí)現(xiàn)一個彈幕組件

    這篇文章主要給大家分享一個開發(fā)中常見的需求,接下來將為大家詳細(xì)介紹彈幕的實(shí)現(xiàn)以及設(shè)計思路一步一步描述出來,希望大家能夠喜歡
    2023-06-06
  • Vue.Draggable使用文檔超詳細(xì)總結(jié)

    Vue.Draggable使用文檔超詳細(xì)總結(jié)

    Vue拖拽組件(Draggable)是一個允許與View-Model同步進(jìn)行拖放排序的Vue組件,下面這篇文章主要給大家介紹了關(guān)于Vue.Draggable使用文檔的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-08-08
  • vue中el-table多層級嵌套的具體實(shí)現(xiàn)

    vue中el-table多層級嵌套的具體實(shí)現(xiàn)

    本文主要介紹了vue中el-table多層級嵌套的具體實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-10-10
  • vue之如何實(shí)現(xiàn)打印功能

    vue之如何實(shí)現(xiàn)打印功能

    這篇文章主要介紹了vue之如何實(shí)現(xiàn)打印功能問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • vue封裝swiper代碼實(shí)例解析

    vue封裝swiper代碼實(shí)例解析

    這篇文章主要介紹了vue封裝swiper代碼實(shí)例解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-10-10
  • 關(guān)于vue.js v-bind 的一些理解和思考

    關(guān)于vue.js v-bind 的一些理解和思考

    本篇文章主要介紹了關(guān)于vue.js v-bind 的一些理解和思考,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06
  • vue如何監(jiān)聽瀏覽器主動刷新

    vue如何監(jiān)聽瀏覽器主動刷新

    這篇文章主要介紹了vue如何監(jiān)聽瀏覽器主動刷新,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • Vue v-for中:key中item.id與Index使用的區(qū)別解析

    Vue v-for中:key中item.id與Index使用的區(qū)別解析

    這篇文章主要介紹了Vue v-for中:key中item.id與Index使用的區(qū)別解析,推薦使用【:key="item.id"】而不是將數(shù)組下標(biāo)當(dāng)做唯一標(biāo)識,前者能做到全部復(fù)用,本文給大家詳細(xì)講解,感興趣的朋友跟隨小編一起看看吧
    2024-02-02
  • 詳解Vue+Element的動態(tài)表單,動態(tài)表格(后端發(fā)送配置,前端動態(tài)生成)

    詳解Vue+Element的動態(tài)表單,動態(tài)表格(后端發(fā)送配置,前端動態(tài)生成)

    這篇文章主要介紹了Vue+Element動態(tài)表單動態(tài)表格,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • MVVM模型在Vue中的使用詳解

    MVVM模型在Vue中的使用詳解

    MVVM模型主要是為了分離視圖(View)和模型(Model),其優(yōu)點(diǎn)為:低耦合、可重用性、獨(dú)立開發(fā)以及可測試,視圖和模型分離的特點(diǎn)給了 Vue 很大的啟發(fā),這篇文章主要介紹了MVVM模型在Vue中的使用,需要的朋友可以參考下
    2022-11-11

最新評論