parcel react_如何使用Parcel捆绑React.js应用程序
parcel react
by Michael Ozoemena
迈克尔·奥索埃梅纳(Michael Ozoemena)
如何使用Parcel捆绑React.js应用程序 (How to use Parcel to bundle your React.js application)
什么是包裹? (What’s Parcel?)
Parcel is a web application bundler which offers a blazingly fast performance utilizing multicore processing and requires zero configuration.
Parcel是一个Web应用程序捆绑程序,它利用多核处理提供了极快的性能,并且需要零配置。
So like Webpack? Yes, like Webpack, but lighter and with no configuration required.
像Webpack一样? 是的,像Webpack一样,但重量更轻且不需要任何配置。
本文提供的内容。 (What this article offers.)
In this article, I’ll show you how you can make use of Parcel to bundle your basic React.js app built with JavaScript (ES6), HTML, and CSS. We will be creating a React.js app from “scratch” without using tools like create-react-app
or anything like that.
在本文中,我将向您展示如何利用Parcel捆绑使用JavaScript(ES6),HTML和CSS构建的基本React.js应用程序。 我们将从头开始创建一个React.js应用程序,而无需使用诸如create-react-app
类的工具。
入门。 (Getting started.)
The first thing we need to do is set up our project. I have created some starter files on GitHub, and you can see them here. When you have the project cloned on your computer, run git checkout beginning
and npm install
to put things in a “starter” position (note that at this point, the project doesn’t really work because we don’t have any bundled files yet).
我们需要做的第一件事是设置我们的项目。 我已经在GitHub上创建了一些入门文件,您可以在此处看到它们。 当您将项目克隆到计算机上时,请运行git checkout beginning
npm install
和npm install
将其置于“起始”位置(请注意,由于我们还没有捆绑的文件,因此该项目目前还无法正常工作)。
捆绑文件。 (Bundling the files.)
Now, we have a simple express
server set up to serve files from the dist/
folder. The reason you see cannot GET /
when you run npm start
and go to localhost:5000/
is because no build has happened yet. As such, the dist/
folder is empty/non-existent.
现在,我们已经建立了一个简单的express
服务器,可以从dist/
文件夹提供文件。 当您运行npm start
并转到localhost:5000/
时,看到cannot GET /
的原因是尚未发生任何构建。 因此, dist/
文件夹为空/不存在。
In order to start bundling our files and have something show up when you go to localhost:5000/
, we need to do a few things:
为了开始捆绑文件并在您进入localhost:5000/
时显示一些内容,我们需要做一些事情:
Install Parcel by running
npm install parcel-bundler --save
.通过运行
npm install parcel-bundler --save
安装Parcel。- Create build scripts.创建构建脚本。
- Run the build scripts and start our server.运行构建脚本并启动我们的服务器。
Load up
localhost:5000/
in the browser.在浏览器中加载
localhost:5000/
。
创建构建脚本和捆绑文件。 (Creating build scripts and bundling files.)
Before we move into actually creating the build scripts and adding it to our package.json
file, let’s learn a bit more about bundling files.
在我们开始实际创建构建脚本并将其添加到package.json
文件之前,让我们进一步了解如何捆绑文件。
Note that the parcel
command will not work if you only have parcel
installed in your project’s node_modules
folder and not globally using the -g
flag.
请注意 , parcel
命令将不会工作,如果你只有parcel
在项目中安装的node_modules
文件夹,而不是全局使用-g
标志。
A nice feature that comes with Parcel (aside from other amazing stuff) is the in-built dev-server
with hot module replacement. You can simply make use of this dev-server
by running parcel index.html
where index.html
is your entry HTML file.
Parcel附带的一个不错的功能(除了其他出色的功能)是带有热模块替换功能的内置dev-server
。 您可以通过运行宗地parcel index.html
来简单地使用此dev-server
,其中index.html
是您的输入HTML文件。
Unfortunately, we won’t be utilizing the dev-server
feature in our demo project, because we’ve built our own little express
server, but this doesn’t mean we won’t still have hot module replacement
. Feel free to give the dev-server
a spin on your own time.
不幸的是,我们不会在演示项目中使用dev-server
功能,因为我们已经构建了自己的小型express
服务器,但这并不意味着我们仍不会进行hot module replacement
。 随意让自己的时间dev-server
。
The commands we want to use instead are:
我们要使用的命令是:
parcel watch index.html
to build our files intodist/
folder and to “watch” for changes to our files during development mode, andparcel watch index.html
,将我们的文件构建到dist/
文件夹中,并在开发模式下“监视”我们文件的更改,以及parcel build index.html
to just build our files and dump them intodist/
folder (useful for production mode).parcel build index.html
即可构建我们的文件并将其转储到dist/
文件夹(对于生产模式有用)。
If we had run npm install parcel-bundler -g
instead of npm install parcel-bundler --save
, then the commands in the previous paragraphs will run smoothly — but we didn’t. We installed Parcel into our local node_modules
folder, so instead of running parcel index.html
, we’ll run ./node_modules/.bin/parcel index.html
to get our files bundled.
如果我们运行了npm install parcel-bundler -g
而不是npm install parcel-bundler --save
,那么前几段中的命令将运行得很顺利,但事实并非如此。 我们将Parcel安装到本地的node_modules
文件夹中,因此,我们将运行./node_modules/.bin/parcel index.html
来捆绑文件,而不是运行parcel index.html
。
Now that we’ve learned all that, we can proceed to editing our package.json
file and adding our build scripts into it.
现在,我们已经了解了所有这些内容,我们可以继续编辑package.json
文件,并将构建脚本添加到其中。
As you can see, I have created three npm scripts
. Now, when we run npm run parcel:watch
we will have our files built into the dist/
folder. We’ll also have Parcel watching out for the changes we make as we edit our CSS, HTML, and JavaScript files so it’ll hot-reload the page for us.
如您所见,我创建了三个npm scripts
。 现在,当我们运行npm run parcel:watch
我们会将文件内置到dist/
文件夹中。 我们还将让Parcel在编辑CSS,HTML和JavaScript文件时注意所做的更改,以便为我们重新加载页面。
查看结果。 (Viewing the results.)
In order to view our simple React.js app in the browser, we can run npm start
(an already existing script) to start our express
server, which should then be listening to localhost:5000/
.
为了在浏览器中查看我们简单的React.js应用程序,我们可以运行npm start
(一个已经存在的脚本)来启动我们的express
服务器,然后该express
服务器应侦听localhost:5000/
。
要拿走的关键东西。 (Key things to take away.)
- You can get up and running with Parcel with absolutely zero configurations. All you have to do is install it and run the commands.您可以使用绝对零配置的Parcel来启动并运行。 您所要做的就是安装它并运行命令。
- Parcel is suitable for both development and production modes.包裹适用于开发和生产模式。
Parcel has an in-built
dev-server
andhot module replacement
to help you quickly get moving.Parcel具有内置的
dev-server
和hot module replacement
,可帮助您快速迁移。There’s more to Parcel than what’s in this article, so be sure to look at the documentation to get more in-depth.
除了本文中介绍的内容外,Parcel还包含更多内容,因此请务必查看文档以进行更深入的了解。
I hope you enjoyed it. If you did, don’t forget to leave a comment and a few claps.
我希望你喜欢它。 如果您这样做了,别忘了发表评论和鼓掌。
翻译自: https://www.freecodecamp.org/news/how-to-use-parcel-to-bundle-your-react-js-application-d023979e9fe4/
parcel react
相关文章:

SparkSQL 与 Spark Core的关系
不多说,直接上干货! SparkSQL 与 Spark Core的关系 Spark SQL构建在Spark Core之上,专门用来处理结构化数据(不仅仅是SQL)。 Spark SQL在Spark Core的基础上针对结构化数据处理进行很多优化和改进, 简单来讲: Spark SQ…

linux操作系统-设置静态ip
在使用linux虚拟机的时候因为经常有关机的需求,然后重新开机后可能面临这上一次获取的ip被改变,在这里我分享一下在linux 下设置静态ip的经验 1.查看路由状态 [rootlocalhost ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Met…

判断数组里面的下标是否等于一个字符串
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 使用includes() 1、判断字符串里面是否包含一个字符串 示例: var a aaaaaaaavconsole.log(a.includes(v)); //truevar a aaaaaaaavconsole.log(a.includes(c)); //falsevar a aa…

如何获得更多的自由开发者客户
by Jad Joubran通过贾德乔布兰(Jad Joubran) 如何获得更多的自由开发者客户 (How to get more clients as a freelance developer) 我希望几年前知道的实用技巧 (Practical tips I wish I knew a few years ago) Whenever a conversation about freelancing kicks off with fe…

2017.6.4 入门组 NO.2——睡眠
其实这题就是将第二个时间-第一个时间,小于0的补全就A了代码如下: var x,y,k:string;l1,l2,x1,x2,x3,y1,y2,y3:longint; beginreadln(x);readln(y);l1:pos(:,x);l2:pos(:,y);k:copy(x,1,2); val(k,x1);k:copy(x,l11,2); val(k,y1);k:copy(y,1,2); val(k…

微信小程序获取用户收货地址 完整代码
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 获取用户收货地址需要用户点击授权,所以有两种情况,确认授权、取消授权。 情况一,用户第一次访问用户地址授权,并且点击确定授权。 情况二,用…

easyui的combobox下拉框初始化默认值以及保持该值一直显示的方法
easyui的combobox下拉框默认初始值是空,下面是实现从远程加载数据之后初始化默认值,以及让该值一直排在下拉框的最顶部的方式。 目前的需求是需要在初始化的时候添加"全部数据库"字段,并且在下拉的时候,"全部数据库"一直排在最顶部。 初始化效果…

关系数据库非关系数据库_如何与关系数据库最佳配合
关系数据库非关系数据库Relational databases handle data smoothly, whether working with small volumes or processing millions of rows. We will be looking at how we can use relational databases according to our needs, and get the most out of them.关系数据库无论…

看过的bootstrap书籍(附下载地址)
http://yun.baidu.com/share/link?shareid3820784617&uk1008683945 以下书籍下载地址。 《BootStrap入门教程》 就是网上的常规教程,过了一遍,不是很重要。 《Bootstrap实战_第一章》 没找到其余的章节,不过这本书不如直接看网上的boots…

Sql的连接表补充
连接条件可在FROM或WHERE子句中指定,建议在FROM子句中指定连接条件。WHERE和HAVING子句也可以包含搜索条件,以进一步筛选连接条件所选的行。 连接可分为以下几类: 内连接。(典型的连接运算,使用像 或 <…

js正则验证身份证号是否正确
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 封装js公共方法 //验证身份证格式 const IdentityCodeValid sId > {const aCity { 11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古…

jupyter笔记本_如何为Jupyter笔记本电脑设置PySpark
jupyter笔记本by Tirthajyoti Sarkar由Tirthajyoti Sarkar 如何为Jupyter笔记本电脑设置PySpark (How to set up PySpark for your Jupyter notebook) Apache Spark is one of the hottest frameworks in data science. It realizes the potential of bringing together both …

php 判断是否有相同的ID,如果有就修改数据库字段,没有就插入数据库字段
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 php代码 <?phpheader("Content-Type:text/html;charsetutf8"); header("Access-Control-Allow-Origin: *"); //解决跨域header(Access-Control-Allow-Methods:POST);// 响应类…

MySql存储引擎特性对比
下表显示了各种存储引擎的特性: 其中最常见的两种存储引擎是MyISAM和InnoDB 刚接触MySQL的时候可能会有些惊讶,竟然有不支持事务的存储引擎,学过关系型数据库理论的人都知道,事务是关系型数据库的核心。但是在现实应用中ÿ…

如何使用React提前三天计划
by Mohit Jain由Mohit Jain 如何使用React提前三天计划 (How you can plan three days ahead with React) Today we’ll be making a ‘to-do’ website… with some different features.今天,我们将建立一个具有一些不同功能的“待办事项”网站。 You can check …

ajax 基础
ajax基础模式 url : "Handler.ashx", -- 提交到哪个服务端 data: { "uname": s }, -- 提交的数据,以键值对的方式传字符串,只能是字符串,可以传多个。 type: "post", …

wamp配置虚拟域名
1、打开apache下httpd.conf 我的目录是在F:\wamp\bin\apache\apache2.2.22\conf\httpd.conf 2、去掉这两行前面的#注释 LoadModule rewrite_module modules/mod_rewrite.so Include conf/extra/httpd-vhosts.conf 这两个注释 3、配置httpd-vhosts.conf <VirtualHost *:80>…

VUE 事件获取当前组件的属性
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 for循环把当前的item传递给绑定事件: <block v-for"(item, index) in data_list"><div v-on:clickchangeType(item) class"ci "><div class"cib&q…

javascript计时器_JavaScript计时器:您需要了解的一切
javascript计时器by Samer Buna通过Samer Buna JavaScript计时器:您需要了解的一切 (JavaScript Timers: Everything you need to know) A few weeks ago, I tweeted this interview question:几周前,我在推特上发布了这个面试问题: *** An…
软考总结——虚存管理
存储管理是操作系统的重要职能之中的一个,主要任务是对内存空间进行分配与回收。因为计算机内存容量有限(如今一般都是32位或64位系统),而外存储设备的容量增长速度很快,比如移动硬盘已经到了…

微信小程序与H5相互跳转和传递数据
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 这是小程序和web-vew的H5相互传参,H5使用小程序的微信支付的代码 H5部分 <!DOCTYPE html> <html><head><meta charset"utf-8" /><!--<meta name&…

【算法】弗洛伊德(Floyd)算法
这个算法主要要弄懂三个循环的顺序关系。 弗洛伊德(Floyd)算法过程:1、用D[v][w]记录每一对顶点的最短距离。2、依次扫描每一个点,并以其为基点再遍历所有每一对顶点D[][]的值,看看是否可用过该…

二次开发photoshop_Photoshop 101:Web开发人员简介
二次开发photoshop介绍 (Introduction) Often, when working as web developer, we need to integrate templates. They can be from Photoshop or other software. In this article, we will have a look at the basics of Photoshop for web developers.通常,在作…

html 提交表单,图片和文字一起提交,图片存入服务器,图片地址和表单信息存入数据库,带后端php代码
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 html <!DOCTYPE html> <html><head><meta name"viewport" content"widthdevice-width, initial-scale1.0, user-scalableno, minimum-scale1.0, maximum-scale1.0…

mysql-理想的索引
1.查询频繁 2.区分度高 例如:数据库表字段:sex 存储:男女,区分度就不高。 3.长度小 索引的长度直接影响索引文件的大小,影响增删改的速度,并间接影响查询速度。 4.尽可能覆盖常用字段 转载于:https://www.c…

使用java的Calendar对象获得当前日期的上几个度开始、结束时间
思路: 先获得当前季度的开始和结束日期,在当前日期的基础上往前推3个月即上个季度的开始和结束日期 /*** param flag true:开始日期;false:结束日期* return*/public static String getLastQuarterTime(boolean flag){…

快速 开发平台 架构_快速介绍清洁架构
快速 开发平台 架构by Daniel Deutsch由Daniel Deutsch 快速介绍清洁架构 (A quick introduction to clean architecture) In an open source project I started to contribute to, the concept of “clean architecture” was brought to me.在一个我开始参与的开源项目中 &a…

linux uart m200平台波特率500kbps乱码问题和输入不响应问题
[问题] linux uart m200平台波特率500kbps乱码问题 [解答] [问题] linux uart m200平台波特率500kbps输入不响应问题 [解答]转载于:https://www.cnblogs.com/harvis/p/6972196.html

VS2013中, 无法嵌入互操作类型“……”,请改用适用的接口的解决方法
使用VS2013,在引用COM组件的时候,出现了无法嵌入互操作类型“……”,请改用适用的接口的错误提示。 查阅资料,找到解决方案,记录如下: 选中项目中引入的dll,鼠标右键,选择属性&#…

JS根据两点的经纬度坐标得到驾车行驶距离
微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 html <!DOCTYPE html> <html><head><meta http-equiv"Content-Type" content"text/html; charsetutf-8"><meta name"viewport" content&quo…