麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > JavaScript > 正文

Parcel 打包示例(React HelloWorld)

2019-11-19 14:31:13
字體:
來源:轉載
供稿:網友

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

5. 添加 Parcel

yarn:

yarn add parcel-bundler -D

npm:

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

6. 新建 index.html 文件

內容

<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. 完成

運行

yarn start

npm start

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

打包過程會生產 .cache 和 dist 兩個目錄,如果是 git 工程,可以新建 .gitignore 文件忽略這兩個目錄:

.cachedistnode_modules

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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 竹内纱里奈和大战黑人 | 午夜生活理论片 | 国产精品国产成人国产三级 | 污污短视频| 毛片免费一区二区三区 | 成人在线视频精品 | 国产在线精品一区二区不卡 | 久久亚洲精品久久国产一区二区 | 羞羞视频免费观看网站 | 欧美大屁股精品毛片视频 | 亚洲精品aaaaa | 成人在线视频在线观看 | 99激情| 免费观看黄色一级视频 | 爱看久久 | 精品国产乱码久久久久久丨区2区 | 午夜视频在线免费播放 | 欧美成人一区二区三区 | 国产91丝袜在线播放 | 宅男噜噜噜66国产免费观看 | 成人免费视频视频在线观看 免费 | www.com超碰 | 亚洲成年人免费网站 | 欧美大电影免费观看 | 91精品国产手机 | 91av在线免费观看 | 999久久久国产999久久久 | 亚洲成人福利电影 | 主人在调教室性调教女仆游戏 | 久草在线新视觉 | 亚洲成人免费视频在线 | 国产欧美日韩在线不卡第一页 | 国产亚洲精品久久久久久网站 | 亚洲男人的天堂在线视频 | 欧美性猛交一区二区三区精品 | 黄色网页在线观看 | 成人午夜在线免费观看 | 国产亚洲精品美女久久久 | 国产精品a一 | 亚洲精品久久久久久下一站 | qyl在线视频精品免费观看 |