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
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)命令與服務(wù)器類似,主要區(qū)別在于它并不會(huì)啟動(dòng)服務(wù)器。
parcel watch index.html
盡可能的顯示所有 cli 的選項(xiàng)
parcel help
顯示 Parcel 版本號(hào)
parcel --version
默認(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
默認(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>
默認(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
默認(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
默認(rèn)為:3
可用于:serve, watch, build
parcel entry.js --log-level 1
日志等級(jí) | 效果 |
---|---|
0 | 禁用記錄 |
1 | 只記錄錯(cuò)誤 |
2 | 記錄錯(cuò)誤和警告 |
3 | 記錄一切 |
默認(rèn)為:當(dāng)前 window 的 location.hostname
可用于:serve,watch
parcel entry.js --hmr-hostname parceljs.org
默認(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 的輸出文件名。
默認(rèn)為:精簡(jiǎn)報(bào)告
可選參數(shù)指定要打印報(bào)告的深度(depth)
可用于:build
parcel build entry.js --detailed-report
parcel build entry.js --detailed-report 10
默認(rèn)為:不啟用 https
可用于: serve,watch(熱更新 hmr 采用 https 連接)
parcel entry.js --https
?? 這個(gè)配置會(huì)生成一個(gè)自簽名證書,你可能需要配置你的瀏覽器,使之接受 localhost 上的自簽名證書。
默認(rèn)為:不啟用 https
可用于:serve,watch
parcel entry.js --cert certificate.cert --key private.key
默認(rèn)為:禁用
可用于:serve
parcel entry.js --open
默認(rèn)為:?jiǎn)⒂?/p>
可用于:serve,watch,build
parcel build entry.js --no-source-maps
默認(rèn)為:?jiǎn)⒂?/p>
可用于:build
parcel build entry.js --no-content-hash
默認(rèn)為:?jiǎn)⒂?/p>
可用于:serve,watch
parcel entry.js --no-autoinstall
默認(rèn)為:?jiǎn)⒂?/p>
可用于:serve,watch
parcel entry.js --no-hmr
默認(rèn)為:?jiǎn)⒂?/p>
可用于:build
parcel build entry.js --no-minify
默認(rèn)為:緩存啟用
可用于:serve, watch, build
parcel build entry.js --no-cache
默認(rèn)為:禁止
可用于:serve, watch, build
parcel serve entry.js --global myvariable
默認(rèn)為:禁止
可用于:build
parcel build entry.js --experimental-scope-hoisting
更多信息,請(qǐng)查看 Devon Govett's post on Parcel 1.9 Tree Shaking section
更多建議: