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.mzph.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;你的输出需要从…