Parcel CLI

2020-02-14 17:26 更新

CLI

Commands

服務(wù)(Serve)

serve 命令啟用一個(gè)開發(fā)服務(wù)器,且支持 熱模塊替換 以實(shí)現(xiàn)快速開發(fā)。當(dāng)你更改文件時(shí),該服務(wù)器將自動(dòng)重新構(gòu)建你的應(yīng)用程序。

parcel index.html

你也可以為多個(gè)入口點(diǎn)傳遞一個(gè)glob或 glob 列表。

parcel one.html two.html
# 或
parcel *.html
# 或
parcel ./**/*.html

構(gòu)建(Build)

build 命令會(huì)一次性構(gòu)建資源,它還啟用了壓縮功能,并將 NODE_ENV 變量設(shè)置為生產(chǎn)環(huán)境。詳見生產(chǎn)環(huán)境

parcel build index.html

注意: 對(duì)于特殊用例,它也可以從開發(fā)環(huán)境執(zhí)行單次構(gòu)建:

NODE_ENV=development parcel build <entrypoint> --no-minify

產(chǎn)生與serve相同的打包,但是沒有監(jiān)聽或資源服務(wù)。

監(jiān)聽(Watch)

監(jiān)聽(watch)命令與服務(wù)器類似,主要區(qū)別在于它并不會(huì)啟動(dòng)服務(wù)器。

parcel watch index.html

幫助(Help)

盡可能的顯示所有 cli 的選項(xiàng)

parcel help

版本(Version)

顯示 Parcel 版本號(hào)

parcel --version

Options

設(shè)置輸出目錄

默認(rèn)為:"dist"

可用于:serve,watch,build

parcel build entry.js --out-dir build/output
# 或者
parcel build entry.js -d build/output
root
- build
- - output
- - - entry.js

設(shè)置要提供服務(wù)的公共 URL

默認(rèn)為:"/"

可用于:serve,watch,build

parcel entry.js --public-url ./dist/

將輸出到:

<link rel="stylesheet" type="text/css" href="/dist/entry.1a2b3c.css" />
<!-- 或者 -->
<script src="/dist/entry.e5f6g7.js"></script>

目標(biāo)(Target)

默認(rèn)為:browser

可用于:serve,watch,build

parcel build entry.js --target node

?? Target 為node and electron的將不會(huì)打包dependencies(然而卻包含devDependencies)。使用--bundle-node-modules 標(biāo)記可以覆蓋這樣的行為(往下看)

可選的目標(biāo)(target):node, browser, electron

強(qiáng)制 node 模塊打包

默認(rèn)為:false

可用于: serve, watch, build

parcel build entry.js --target node --bundle-node-modules

默認(rèn)情況下,當(dāng)使用 --target node 或 --target electron時(shí),package.json's dependencies將不包含在打包中。這個(gè)標(biāo)記就是為了添加它們進(jìn)去。

緩存目錄

默認(rèn)為: ".cache"

可用于: serve, watch, build

parcel build entry.js --cache-dir build/cache

端口

默認(rèn)為:1234

可用于: serve

parcel serve entry.js --port 1111

更改日志級(jí)別

默認(rèn)為:3

可用于:serve, watch, build

parcel entry.js --log-level 1
日志等級(jí)效果
0禁用記錄
1只記錄錯(cuò)誤
2記錄錯(cuò)誤和警告
3記錄一切

HMR 主機(jī)名

默認(rèn)為:當(dāng)前 window 的 location.hostname

可用于:serve,watch

parcel entry.js --hmr-hostname parceljs.org

HMR 端口

默認(rèn)為:可訪問的隨機(jī)端口

可用于:serve, watch

parcel entry.js --hmr-port 8080

輸出的文件名

默認(rèn)為:源文件名稱

可用于:serve,watch,build

parcel build entry.js --out-file output.html

這改變了入口 bundle 的輸出文件名。

打印詳細(xì)的報(bào)告

默認(rèn)為:精簡(jiǎn)報(bào)告

可選參數(shù)指定要打印報(bào)告的深度(depth)

可用于:build

parcel build entry.js --detailed-report
parcel build entry.js --detailed-report 10

啟用 https

默認(rèn)為:不啟用 https

可用于: serve,watch(熱更新 hmr 采用 https 連接)

parcel entry.js --https

?? 這個(gè)配置會(huì)生成一個(gè)自簽名證書,你可能需要配置你的瀏覽器,使之接受 localhost 上的自簽名證書。

設(shè)置一個(gè)自定義證書

默認(rèn)為:不啟用 https

可用于:serve,watch

parcel entry.js --cert certificate.cert --key private.key

在瀏覽器中打開

默認(rèn)為:禁用

可用于:serve

parcel entry.js --open

禁用源代碼映射(source-maps)

默認(rèn)為:?jiǎn)⒂?/p>

可用于:serve,watch,build

parcel build entry.js --no-source-maps

禁用文件 hash 命名(content-hash)

默認(rèn)為:?jiǎn)⒂?/p>

可用于:build

parcel build entry.js --no-content-hash

禁用自動(dòng)安裝依賴(autoinstall)

默認(rèn)為:?jiǎn)⒂?/p>

可用于:serve,watch

parcel entry.js --no-autoinstall

禁用熱替換(HMR)

默認(rèn)為:?jiǎn)⒂?/p>

可用于:serve,watch

parcel entry.js --no-hmr

禁用代碼壓縮(minification)

默認(rèn)為:?jiǎn)⒂?/p>

可用于:build

parcel build entry.js --no-minify

禁用文件系統(tǒng)緩存

默認(rèn)為:緩存啟用

可用于:serve, watch, build

parcel build entry.js --no-cache

UMD 方式暴露模塊

默認(rèn)為:禁止

可用于:serve, watch, build

parcel serve entry.js --global myvariable

開啟實(shí)驗(yàn)性的 scope hoisting/tree shaking 支持

默認(rèn)為:禁止

可用于:build

parcel build entry.js --experimental-scope-hoisting

更多信息,請(qǐng)查看 Devon Govett's post on Parcel 1.9 Tree Shaking section


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)