国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

Parcel 打包示例(React HelloWorld)

2024-05-06 15:22:38
字體:
來源:轉載
供稿:網友

Parcel 打包特點

極速打包時間

Parcel 使用 worker 進程去啟用多核編譯。同時有文件系統緩存,即使在重啟構建后也能快速再編譯。

 將你所有的資源打包

Parcel 具備開箱即用的對 JS, CSS, HTML, 文件 及更多的支持,而且不需要插件。

自動轉換

如若有需要,Babel, PostCSS, 和PostHTML甚至 node_modules 包會被用于自動轉換代碼.

配置代碼分拆

使用動態 import() 語法, Parcel 將你的輸出文件束(bundles)分拆,因此你只需要在初次加載時加載你所需要的代碼。

 熱模塊替換

Parcel 無需配置,在開發環境的時候會自動在瀏覽器內隨著你的代碼更改而去更新模塊。

友好的錯誤日志

當遇到錯誤時,Parcel 會輸出 語法高亮的代碼片段,幫助你定位問題。

使用 Parcel 打包的 React HelloWorld 應用。GitHub 地址: https://github.com/justjavac/parcel-example/tree/master/react-helloworld

0. 新建目錄

mkdir react-helloworldcd react-helloworld

1. 初始化 npm

yarn init -y

npm init -y

此時會創建要給 package.json 文件,文件內容:

{ "name": "parcel-example-react-helloworld", "version": "1.0.0", "description": "", "main": "index.js", "scripts": {  "test": "echo /"Error: no test specified/" && exit 1" }, "keywords": [], "author": "", "license": "ISC"}

2. 添加 React

yarn:

yarn add react react-dom

npm:

npm install react react-dom --save

package.json 文件內容:

 {  "name": "parcel-example-react-helloworld",  "version": "1.0.0",  "description": "",  "main": "index.js",  "scripts": {   "test": "echo /"Error: no test specified/" && exit 1"  },  "keywords": [],  "author": "",- "license": "ISC"+ "license": "ISC",+ "dependencies": {+  "react": "^16.2.0",+  "react-dom": "^16.2.0"+ } }

3. 添加 Babel

新建 .babelrc 文件

touch .babelrc

輸入內容:

{ "presets": ["react"]}

添加 babel-preset-react:

yarn:

yarn add babel-preset-react -D

npm:

npm install babel-preset-react --D

此時 package.json 文件內容:

 {  "name": "parcel-example-react-helloworld",  "version": "1.0.0",  "description": "",  "main": "index.js",  "scripts": {   "test": "echo /"Error: no test specified/" && exit 1"  },  "keywords": [],  "author": "",  "license": "ISC",  "dependencies": {   "react": "^16.2.0",   "react-dom": "^16.2.0"-  }+  },+  "devDependencies": {+   "babel-preset-react": "^6.24.1"+  } }            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 石嘴山市| 通江县| 碌曲县| 桂阳县| 武威市| 和硕县| 常熟市| 奉节县| 加查县| 沙田区| 竹山县| 名山县| 易门县| 阳朔县| 方城县| 灌阳县| 章丘市| 克东县| 定兴县| 青龙| 大方县| 桃源县| 吉林省| 华坪县| 利川市| 木里| 黄浦区| 上林县| 双牌县| 恩平市| 三台县| 昭觉县| 个旧市| 沧州市| 天峻县| 涿州市| 阿鲁科尔沁旗| 惠州市| 民和| 邻水| 新和县|