最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Parcel 打包示例(React HelloWorld)

 更新時(shí)間:2018年01月16日 09:15:14   作者:justjavac  
本篇文章主要介紹了Parcel 打包示例(React HelloWorld),詳細(xì)的介紹了Parcel打包的特點(diǎn)和使用示例,有興趣的可以了解一下

Parcel 打包特點(diǎn)

極速打包時(shí)間

Parcel 使用 worker 進(jìn)程去啟用多核編譯。同時(shí)有文件系統(tǒng)緩存,即使在重啟構(gòu)建后也能快速再編譯。

 將你所有的資源打包

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

自動(dòng)轉(zhuǎn)換

如若有需要,Babel, PostCSS, 和PostHTML甚至 node_modules 包會(huì)被用于自動(dòng)轉(zhuǎn)換代碼.

配置代碼分拆

使用動(dòng)態(tài) import() 語(yǔ)法, Parcel 將你的輸出文件束(bundles)分拆,因此你只需要在初次加載時(shí)加載你所需要的代碼。

 熱模塊替換

Parcel 無(wú)需配置,在開發(fā)環(huán)境的時(shí)候會(huì)自動(dòng)在瀏覽器內(nèi)隨著你的代碼更改而去更新模塊。

友好的錯(cuò)誤日志

當(dāng)遇到錯(cuò)誤時(shí),Parcel 會(huì)輸出 語(yǔ)法高亮的代碼片段,幫助你定位問(wèn)題。

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

0. 新建目錄

mkdir react-helloworld
cd react-helloworld

1. 初始化 npm

yarn init -y

npm init -y

此時(shí)會(huì)創(chuàng)建要給 package.json 文件,文件內(nèi)容:

{
 "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 文件內(nèi)容:

 {
  "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

輸入內(nèi)容:

{
 "presets": ["react"]
}

添加 babel-preset-react:

yarn:

yarn add babel-preset-react -D

npm:

npm install babel-preset-react --D

此時(shí) package.json 文件內(nèi)容:

 {
  "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"
+  }
 }

5. 添加 Parcel

yarn:

yarn add parcel-bundler -D

npm:

npm install parcel-bundler --D

此時(shí) package.json 文件內(nèi)容:

 {
  "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"
+   "babel-preset-react": "^6.24.1",
+   "parcel-bundler": "^1.0.3"  
  }
 }

6. 新建 index.html 文件

內(nèi)容

<html>
<body>
  <div id="root"></div>
  <script src="./index.js"></script>
</body>
</html>

7. 新建 index.js 文件

import React from "react";
import ReactDOM from "react-dom";
const App = () => {
 return <h1>Hello World!</h1>;
};

ReactDOM.render(<App />, document.getElementById("root"));

8. 添加打包命令

 {
  "name": "parcel-example-react-helloworld",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
-  "test": "echo \"Error: no test specified\" && exit 1"
+  "start": "parcel index.html"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
   "react": "^16.2.0",
   "react-dom": "^16.2.0"
  },
  "devDependencies": {
    "babel-preset-react": "^6.24.1"
    "babel-preset-react": "^6.24.1",
    "parcel-bundler": "^1.0.3"  
  }
 }

9. 完成

運(yùn)行

yarn start

npm start

在瀏覽器中打開 http://localhost:1234

打包過(guò)程會(huì)生產(chǎn) .cache 和 dist 兩個(gè)目錄,如果是 git 工程,可以新建 .gitignore 文件忽略這兩個(gè)目錄:

.cache
dist
node_modules

GitHub 地址: https://github.com/justjavac/parcel-example/tree/master/react-helloworld

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Ant?Design?組件庫(kù)按鈕實(shí)現(xiàn)示例詳解

    Ant?Design?組件庫(kù)按鈕實(shí)現(xiàn)示例詳解

    這篇文章主要介紹了Ant?Design?組件庫(kù)按鈕實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪</P><P><BR>
    2022-08-08
  • Mobx實(shí)現(xiàn)React?應(yīng)用的狀態(tài)管理詳解

    Mobx實(shí)現(xiàn)React?應(yīng)用的狀態(tài)管理詳解

    這篇文章主要為大家介紹了Mobx?實(shí)現(xiàn)?React?應(yīng)用的狀態(tài)管理,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • 需要避免的五個(gè)react的ref錯(cuò)誤用法

    需要避免的五個(gè)react的ref錯(cuò)誤用法

    react是一個(gè)優(yōu)秀的框架,提供了我們很多的便利,但是在使用的過(guò)程中,我們也會(huì)遇到很多的問(wèn)題,其中一個(gè)就是ref的使用,以下是我列出的5個(gè)使用ref的錯(cuò)誤用法,并提供了正確的用法,需要的朋友可以參考下
    2024-12-12
  • Iconfont不能上傳如何維護(hù)Icon

    Iconfont不能上傳如何維護(hù)Icon

    這篇文章主要為大家介紹了在Iconfont還是不能上傳,要如何維護(hù)你的Icon,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-07-07
  • antd form表單如何處理自定義組件

    antd form表單如何處理自定義組件

    這篇文章主要介紹了antd form表單如何處理自定義組件問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • react實(shí)現(xiàn)點(diǎn)擊選中的li高亮的示例代碼

    react實(shí)現(xiàn)點(diǎn)擊選中的li高亮的示例代碼

    本篇文章主要介紹了react實(shí)現(xiàn)選中的li高亮的示例代碼,頁(yè)面上有很多個(gè)li,要實(shí)現(xiàn)點(diǎn)擊到哪個(gè)就哪個(gè)高亮。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05
  • react?card?slider實(shí)現(xiàn)滑動(dòng)卡片教程示例

    react?card?slider實(shí)現(xiàn)滑動(dòng)卡片教程示例

    這篇文章主要為大家介紹了react?card?slider實(shí)現(xiàn)滑動(dòng)卡片教程示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • 關(guān)于React Native使用axios進(jìn)行網(wǎng)絡(luò)請(qǐng)求的方法

    關(guān)于React Native使用axios進(jìn)行網(wǎng)絡(luò)請(qǐng)求的方法

    axios是一個(gè)基于Promise的Http網(wǎng)絡(luò)庫(kù),可運(yùn)行在瀏覽器端和Node.js中,Vue應(yīng)用的網(wǎng)絡(luò)請(qǐng)求基本都是使用它完成的。這篇文章主要介紹了React Native使用axios進(jìn)行網(wǎng)絡(luò)請(qǐng)求,需要的朋友可以參考下
    2021-08-08
  • React生命周期方法之componentDidMount的使用

    React生命周期方法之componentDidMount的使用

    這篇文章主要介紹了React生命周期方法之componentDidMount的使用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • React實(shí)現(xiàn)隨機(jī)顏色選擇器的示例代碼

    React實(shí)現(xiàn)隨機(jī)顏色選擇器的示例代碼

    顏色選擇器是一個(gè)用于選擇和調(diào)整顏色的工具,它可以讓用戶選擇他們喜歡的顏色,本文主要介紹了React實(shí)現(xiàn)隨機(jī)顏色選擇器的示例代碼,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-12-12

最新評(píng)論

峨山| 禄丰县| 门源| 广东省| 鱼台县| 富蕴县| 葵青区| 昌吉市| 潮州市| 洛宁县| 砀山县| 隆尧县| 鸡东县| 浦江县| 丹江口市| 辛集市| 曲麻莱县| 环江| 金塔县| 平罗县| 荆州市| 尤溪县| 兰西县| 天镇县| 原阳县| 清徐县| 淮阳县| 竹北市| 九江县| 八宿县| 常州市| 西畴县| 通州区| 筠连县| 颍上县| 手机| 邛崃市| 磐安县| 始兴县| 绥德县| 普兰店市|