parcel react_如何使用Parcel設置React應用

parcel react

For a long time Webpack was one of the biggest barriers-to-entry for someone wanting to learn React. There's a lot of boilerplate configuration that can be confusing, especially if you're new to React.

長期以來, Webpack一直是想要學習React的人最大的入門障礙之一。 有很多樣板配置可能會令人困惑,尤其是在您不熟悉React的情況下。

Even in a talk trying to show how easy React is to set up, it can be very difficult to try and learn each and every step in the setup process.

即使在試圖說明React設置多么簡單的演講中 ,嘗試并學習設置過程中的每個步驟也可能非常困難。

Not too long after React was first out of beta, the team at Facebook made create-react-app. It was an attempt to make spinning up a (very fully-loaded version of a) React app as simple as typing a single command:

在React首次退出Beta版后不久,Facebook的團隊制作了create-react-app 。 試圖使旋轉(非常完整的版本)React應用程序變得像鍵入單個命令一樣簡單:

npx create-react-app my-app

Nice! And honestly, this 👆 method of creating a new React app is awesome if you want something that has lots of bells and whistles right from the get-go, and you're okay with having your app start as a fairly heavy/large app.

真好! 老實說,如果您想要一開始就具有很多風吹草動的東西, 并且可以將應用程序從一個相當大/大型的應用程序開始,那么創建新的React應用程序的方法非常棒。

That heaviness comes from the many dependencies, loaders, plugins, and so on automatically installed as node_modules that take up a lot of space for each app. The Finder summary image below is from one of my create-react-app apps. 😱

node_modules來自自動安裝為node_modules的許多依賴項,加載程序,插件等,每個應用程序占用大量空間。 下面的Finder摘要圖片來自我的一個create-react-app應用程序。 😱

包裹介紹 (Introducing Parcel)

Parcel is a "Blazing fast, zero configuration web application bundler." This means it handles a lot of the hard bundling stuff for you under the hood and allows you to create a relatively lean setup of React (or any other web project that requires bundling).

Parcel是一個“快速,零配置的Web應用程序捆綁包”。 這意味著它在幕后為您處理了很多硬捆綁的內容, 允許您創建相對精簡的React設置(或任何其他需要捆綁的 Web項目)。

So, let's see what it takes to set up the bare bones "Hello World" React app that displays an h1 element.

因此,讓我們來看看如何設置顯示h1元素的裸露“ Hello World” React應用程序。

步驟1:為您的項目創建一個新文件夾 (Step 1: Create a new folder for your project)

Easy enough. 😏

很簡單。 😏

步驟2:建立您的package.json檔案 (Step 2: Create your package.json file)

In terminal, cd into the new folder and run:

在終端中, cd進入新文件夾并運行:

npm init -y

This automatically creates the package.json file.

這將自動創建package.json文件。

第三步:安裝Parcel,React和ReactDOM (Step 3: Install Parcel, React, and ReactDOM)

npm install --save-dev parcel-bundler
# Shorthand version: npm i -D parcel-bundlernpm install react react-dom
# Shorthand version: npm i react react-dom
# Note that npm will automatically save dependencies to package.json now, so there's no longer a need to do npm install --save ...

第4步:向package.json添加一個“開始”腳本 (Step 4: Add a "start" script to package.json)

In the package.json file, in the "scripts" section, add the following "start" script:

package.json文件的“腳本”部分中,添加以下“開始”腳本:

"start": "parcel index.html --open"

第5步:創建index.html文件并添加幾行 (Step 5: Create the index.html file and add a couple lines)

In VS Code, you can create a new file called index.html and use the built-in emmet shortcut to create a standard boilerplate HTML file by typing an exclamation point and hitting the Tab key on your keyboard.

在VS Code中,您可以創建一個名為index.html的新文件,并使用內置的emmet快捷方式,通過鍵入感嘆號并單擊鍵盤上的Tab鍵來創建標準的樣板HTML文件。

Before we move on, we need to add 2 things:

在繼續之前,我們需要添加兩件事:

  1. A div placeholder where our React app will be inserted

    將在其中插入我們的React應用的div占位符

  2. A script to read in the JavaScript entry file (which we will create next)

    要讀取JavaScript入口文件的script (我們將在接下來創建)

In the body of index.html, add:

index.htmlbody中,添加:

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

步驟6:建立index.js檔案 (Step 6: Create the index.js file)

Create a new file called index.js and enter your bare bones React code:

創建一個名為index.js的新文件,然后輸入您的裸露React代碼:

// index.js
import React from "react"
import ReactDOM from "react-dom"ReactDOM.render(<h1>Hello world!</h1>, document.getElementById("root"))

步驟7:開始! (Step 7: Start it up!)

That's it! Now from the terminal, run:

而已! 現在從終端運行:

npm start

Parcel will handle the rest, and you'll have a fully-functional React app.

包裹將處理其余部分,您將擁有一個功能齊全的React應用程序。

結論 (Conclusion)

If you're interested, take some time to peruse the Parcel documentation to better understand all the awesomeness that comes with using Parcel, without requiring any configuration on your end.

如果您有興趣,請花一些時間仔細閱讀Parcel文檔,以更好地了解使用Parcel所帶來的所有出色功能,而無需進行任何配置。

Out of the box, Parcel comes with support for all kinds of common web development extensions, transpilers, syntaxes, and so on.

開箱即用,Parcel支持各種常見的Web開發擴展,編譯器,語法等。

Although it's not tiny, the node_modules from a Parcel app take up 50% less space on your computer:

盡管不 ,但Parcel應用程序中的node_modules占用的計算機空間減少了50%:

Thanks, Parcel!

謝謝,包裹!

翻譯自: https://www.freecodecamp.org/news/how-to-up-a-react-app-with-parcel/

parcel react

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390129.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390129.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390129.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

1117. H2O 生成

1117. H2O 生成 現在有兩種線程&#xff0c;氧 oxygen 和氫 hydrogen&#xff0c;你的目標是組織這兩種線程來產生水分子。 存在一個屏障&#xff08;barrier&#xff09;使得每個線程必須等候直到一個完整水分子能夠被產生出來。 氫和氧線程會被分別給予 releaseHydrogen 和…

pdf 字體和圖片抽取

2019獨角獸企業重金招聘Python工程師標準>>> #安裝mutoos sudo apt-get install mupdf-tools #抽取字體 mutool extract LTN20180531052_C.pdf 轉載于:https://my.oschina.net/colin86/blog/1842412

推箱子2-向右推!_保持冷靜,砍箱子-銀行

推箱子2-向右推!Hack The Box (HTB) is an online platform allowing you to test your penetration testing skills. It contains several challenges that are constantly updated. Some of them are simulating real world scenarios and some of them lean more towards a …

611. 有效三角形的個數

611. 有效三角形的個數 給定一個包含非負整數的數組&#xff0c;你的任務是統計其中可以組成三角形三條邊的三元組個數。 示例 1: 輸入: [2,2,3,4] 輸出: 3 解釋: 有效的組合是: 2,3,4 (使用第一個 2) 2,3,4 (使用第二個 2) 2,2,3注意: 數組長度不超過1000。數組里整數的范…

python學習day04

一&#xff1a;今天是一個學習列表后的實踐訓練 購物小程序&#xff1a; #codeing:UTF-8 #__author__:Duke #date:2018/3/1/001product_list [(mac,7000),(bike,1000),(phone,2000),(kindle,800),(iwatch,3000), ]; shopping_car []; saving input("please input your …

mybatis多產數_freeCodeCamp杰出貢獻者–我們如何選擇,認可和獎勵多產的志愿者

mybatis多產數freeCodeCamp.org is only possible thanks to the thousands of contributors around the world who help expand and improve the community. They do this mainly through:感謝全球各地成千上萬的貢獻者&#xff0c;他們致力于擴大和改善社區&#xff0c;因此f…

502. IPO

502. IPO 假設 力扣&#xff08;LeetCode&#xff09;即將開始 IPO 。為了以更高的價格將股票賣給風險投資公司&#xff0c;力扣 希望在 IPO 之前開展一些項目以增加其資本。 由于資源有限&#xff0c;它只能在 IPO 之前完成最多 k 個不同的項目。幫助 力扣 設計完成最多 k 個…

記一次打包的詭異現象

一、前情提要&#xff1a; 今天線上打包&#xff0c;發現啟動正常&#xff0c;但是訪問異常&#xff0c;看日志也沒有打印出什么異常信息。 更新的微服務包訪問的時候一直報出【403】&#xff0c;訪問被拒 項目架構&#xff1a;springBoot maven 二、機緣巧合&#xff1a; 上午…

轉載:mysql存儲過程講解

記錄MYSQL存儲過程中的關鍵語法&#xff1a; DELIMITER // 聲明語句結束符&#xff0c;用于區分; CEATE PROCEDURE demo_in_parameter(IN p_in int) 聲明存儲過程 BEGIN …. END 存儲過程開始和結束符號 SET p_in1 變量賦值 DECLARE l_int int unsigned default 4000000; 變…

Diffie-Hellman:安全網絡通信背后的天才算法

Lets start with a quick thought experiment.讓我們從快速思考實驗開始。 You have a network of 3 computers, used by Alice, Bob, and Charlie. All 3 participants can send messages, but just in a way that all other clients who connected to the network can read …

掃盲丨關于區塊鏈你需要了解的所有概念

掃盲丨關于區塊鏈你需要了解的所有概念 如今存儲信息的方式有什么問題&#xff1f; 目前&#xff0c;支配我們生活的數據大部分都儲存在一個地方&#xff0c;不論是在私人服務器、云、圖書館或檔案館的紙上。大多數情況下這很好&#xff0c;但這也容易受到攻擊。 最近有消息稱&…

SpringBoot環境切換

2019獨角獸企業重金招聘Python工程師標準>>> 1.在application.yml中配置&#xff0c;如果java -jar banke-boot-bd-api-0.0.1-SNAPSHOT.jar&#xff0c;那么就是已application-test作為啟動的配置文件啟動 spring: profiles: active: test 2.如果java -jar banke-bo…

linux tar cvf_Linux中的Tar命令:Tar CVF和Tar XVF通過示例命令進行了解釋

linux tar cvfThe name tar is, by most accounts, short for tape archive. The "tapes" in question would be all those magnetic storage drives that were popular all the way back in the 1950s. 在大多數情況下&#xff0c; tar是磁帶歸檔的縮寫。 有問題的“…

1894. 找到需要補充粉筆的學生編號

1894. 找到需要補充粉筆的學生編號 一個班級里有 n 個學生&#xff0c;編號為 0 到 n - 1 。每個學生會依次回答問題&#xff0c;編號為 0 的學生先回答&#xff0c;然后是編號為 1 的學生&#xff0c;以此類推&#xff0c;直到編號為 n - 1 的學生&#xff0c;然后老師會重復…

[No0000B0]ReSharper操作指南1/16-入門與簡介

安裝指南 在安裝之前&#xff0c;您可能需要檢查系統要求。 ReSharper是一個VisualStudio擴展。它支持VisualStudio2010,2012,2013,2015和2017.安裝完成后&#xff0c;您將在VisualStudio的主菜單中找到新的ReSharper條目。大多數ReSharper命令都可以在這個菜單中找到。但是&a…

更改H2元素的顏色

In coding there are often many different solutions to a given problem. This is especially true when it comes to styling an HTML element.在編碼中&#xff0c;對于給定問題通常有許多不同的解決方案。 在樣式化HTML元素時&#xff0c;尤其如此。 One of the easiest …

[CTSC2008]圖騰totem

&#xff08;圖騰這題做的我頭疼 233&#xff09; 記 f(xxxx) 為 xxxx 出現的次數&#xff0c;那么題目就是要求 f(1324) - f(1243) - f(1432) 最有難度的是把上面的式子轉化一下&#xff0c;變成 f(1x2x) - f(14xx) - f(12xx) f(1234) 這點除非對 f 的求法能一眼看出來&#…

Box Shadow CSS教程–如何向任何HTML元素添加投影

We can add a drop shadow to any HTML element using the CSS property box-shadow. Heres how. 我們可以使用CSS屬性box-shadow將陰影添加到任何HTML元素。 這是如何做。 添加基本??投影 (Adding a Basic Drop Shadow) Lets first set up some basic HTML elements to add…

數據結構學習筆記(一)——《大話數據結構》

第一章 數據結構緒論 基本概念和術語 數據 描述客觀事物的符號&#xff0c;計算機中可以操作的對象&#xff0c;能被計算機識別并輸入給計算機處理的符號的集合。包括整型、實型等數值類型和字符、聲音、圖像、視頻等非數值類型。 數據元素 組成數據的、有一定意義的基本單位&a…

6. Z 字形變換

6. Z 字形變換 將一個給定字符串 s 根據給定的行數 numRows &#xff0c;以從上往下、從左到右進行 Z 字形排列。 比如輸入字符串為 “PAYPALISHIRING” 行數為 3 時&#xff0c;排列如下&#xff1a; P A H N A P L S I I G Y I R之后&#xff0c;你的輸出需要從…