简体   繁体   English

在没有 npm start 的情况下将 ReactJS 添加到项目中

[英]Adding ReactJS to a project without npm start

There is a ready-made project.有一个现成的项目。 Backend on Yii2, the frontend is written in it. Yii2 上的后端,前端写在里面。 Please tell me how to add a piece of the front on ReactJS to the finished page, so that, for example, in OpenServer, when you launch the site(my project), ReactJS is displayed correctly (without using npm in the console).请告诉我如何在完成的页面中添加一段ReactJS的前端,以便例如在OpenServer中,当您启动站点(我的项目)时,ReactJS可以正确显示(在控制台中不使用npm)。 In other words, how to connect ReactJS to a project?换句话说,如何将 ReactJS 连接到一个项目?

Add React in One Minute In this section, we will show how to add a React component to an existing HTML page.一分钟内添加 React在本节中,我们将展示如何将 React 组件添加到现有的 HTML 页面。 You can follow along with your own website, or create an empty HTML file to practice.您可以跟随自己的网站,或创建一个空的 HTML 文件来练习。

There will be no complicated tools or install requirements — to complete this section, you only need an internet connection, and a minute of your time.没有复杂的工具或安装要求 - 要完成本部分,您只需要一个互联网连接和一分钟的时间。

Step 1: Add a DOM Container to the HTML First, open the HTML page you want to edit.第 1 步:将 DOM 容器添加到 HTML首先,打开要编辑的 HTML 页面。 Add an empty tag to mark the spot where you want to display something with React.添加一个空标签来标记你想用 React 显示的地方。 For example:例如:

<!-- ... existing HTML ... -->

<div id="like_button_container"></div>

<!-- ... existing HTML ... -->

Step 2: Add the Script Tags Next, add three tags to the HTML page right before the closing tag:第 2 步:添加脚本标签接下来,在 HTML 页面的结束标签之前添加三个标签:

 <!-- ... other HTML ... -->

  <!-- Load React. -->
  <!-- Note: when deploying, replace "development.js" with "production.min.js". -->
  <script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
  <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>

  <!-- Load our React component. -->
  <script src="like_button.js"></script>

</body>

enter link description here在此处输入链接描述

You can make a build out of it using npm run build您可以使用npm run build对其进行npm run build

and then from it you can link index.html然后从它你可以链接 index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM