使用 Parcel 打包的 React HelloWorld 應(yīng)用。GitHub 地址: https://github.com/justjavac/...
0. 新建目錄mkdir react-helloworld cd react-helloworld1. 初始化 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)容
7. 新建 index.js 文件
import React from "react"; import ReactDOM from "react-dom"; const App = () => { return8. 添加打包命令Hello World!
; }; ReactDOM.render(, document.getElementById("root"));
{ "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
打包過程會(huì)生產(chǎn) .cache 和 dist 兩個(gè)目錄,如果是 git 工程,可以新建 .gitignore 文件忽略這兩個(gè)目錄:
.cache dist node_modules
GitHub 地址: https://github.com/justjavac/...
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://www.ezyhdfw.cn/yun/112831.html
使用 Parcel 打包的 React HelloWorld 應(yīng)用。GitHub 地址: https://github.com/justjavac/... 0. 新建目錄 mkdir react-helloworld cd react-helloworld 1. 初始化 npm yarn init -y 或 npm init -y 此時(shí)會(huì)創(chuàng)建要給 package.json 文件,文件內(nèi)容: ...
摘要:一個(gè)基于打包工具的急速開發(fā)腳手架解決方案強(qiáng)烈建議使用以上項(xiàng)目地址初始化項(xiàng)目安裝依賴其中是主要的工具,對(duì)于結(jié)尾的單文件,需要單獨(dú)處理文件類型,這個(gè)插件會(huì)通過來生成對(duì)應(yīng)的代碼,會(huì)自動(dòng)加載開頭的依賴。 parcel-vue 一個(gè)基于Parcel打包工具的 VueJS急速開發(fā)腳手架解決方案,強(qiáng)烈建議使用node8.0以上 項(xiàng)目地址: https://github.com/w3c-king/p....
摘要:前言是前端最受歡迎的框架之一,解讀其源碼的文章非常多,但是我想從另一個(gè)角度去解讀從零開始實(shí)現(xiàn)一個(gè),從層面實(shí)現(xiàn)的大部分功能,在這個(gè)過程中去探索為什么有虛擬為什么這樣設(shè)計(jì)等問題。 前言 React是前端最受歡迎的框架之一,解讀其源碼的文章非常多,但是我想從另一個(gè)角度去解讀React:從零開始實(shí)現(xiàn)一個(gè)React,從API層面實(shí)現(xiàn)React的大部分功能,在這個(gè)過程中去探索為什么有虛擬DOM、d...
摘要:接下來來看一段代碼示例語法與語言比較當(dāng)類型不對(duì)的時(shí)候,會(huì)提示錯(cuò)誤編譯后語法聯(lián)想大致可以把它看成是加了類型系統(tǒng)的。 一篇文章學(xué)會(huì) TypeScript (內(nèi)部分享標(biāo)題:TypeScript 基礎(chǔ)) 這篇文章是我在公司前端小組內(nèi)部的演講分享稿,目的是教會(huì)大家使用 TypeScript,這篇文章雖然標(biāo)著基礎(chǔ),但我指的基礎(chǔ)是學(xué)完后就能夠勝任 TypeScript 的開發(fā)工作。從我分享完的效果來...
閱讀 2592·2021-10-11 10:58
閱讀 1113·2019-08-29 13:58
閱讀 1714·2019-08-26 13:32
閱讀 883·2019-08-26 10:40
閱讀 3313·2019-08-26 10:18
閱讀 1807·2019-08-23 14:18
閱讀 1166·2019-08-23 10:54
閱讀 503·2019-08-22 18:39