Start a new projectThis article mainly records the process of working on a new project from 0 to 1, mainly recording three nodes: selection, runtime, and launch. Project SelectionReact scaffolding initialization, the more popular ones in the community are cra (create-react-app) and umi. After comparing the following points, we finally chose umi which is more suitable for the project.
Finally, considering that a project needs to be built quickly and requires the support of many mature plug-ins, umi was adopted. antd is so good! ! ! @umijs/plugin-model, I recommend this plugin. If you understand the internal practices, you will basically master data management. RuntimeUmi provides app.ts, a runtime configuration file, which can expand the capabilities of the runtime. In simple terms, all the pre-operations for rendering your page can be placed here. This concept can be classified into Compared with storybook (preview.js), if you want to implement it yourself, you can insert the script in the corresponding HTML. There will be some project-related content involved here. Because the project needs to be embedded in an existing project, we adopt the iframe approach. Inevitably, we need communication and iframe size adaptation. For iframe communication, because the domains are different, window.postmessage is used. In order to maintain data readability, it is recommended to define the corresponding event transmission content to avoid increased difficulty in later maintenance. If frequent communication is required, it is recommended to adopt a micro-frontend solution. Iframe adaptation, the iframe-resizer plug-in helps us solve it. Remember that both the embedding and the embedded need to be installed, otherwise they will not be able to communicate and adapt. There is a problem here. When the page is embedded, the body node cannot be expanded from the inside, so it is necessary to use the custom calculation method provided by iframe-resizer to provide the corresponding method in the child page. The code is as follows: Subsystem import 'iframe-resizer/js/iframeResizer.contentWindow.js'; // If embedded, open the listener at runtime const iframeInit = () => { if (parent !== window) { (window as any).iFrameResizer = { heightCalculationMethod: () => { return document.body.children[0].clientHeight; }, }; window.onmessage = (event: any) => { if (Array.isArray(event.data)) { if (event.data[0] === 'event name') { console.log(event.data[1]) // event parameters} } }; parent.postMessage({ msg: 'MessageFromIframePage' }, '*'); } }; iframeInit(); Go Live After a round of packaging, it is finally launched. Here we mainly talk about how to configure nginx to forward requests. During development, if interfaces to multiple different domains are needed, the first reaction of the front end is to configure a proxy. I was a bit confused when I went online. proxy: { '/api': { target: 'http://aaa.com', changeOrigin: true, pathRewrite: { '^/api': '' }, }, '/b-api': { target: 'http://bbb.com/', changeOrigin: true, pathRewrite: { '^/b-api': '' }, }, }, The nginx configuration is as follows server { listen 80; server_name access address; set $rooturi "xxxx/dist"; location ~ .*\.(jpg|jpeg|gif|png|webp|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|svg|proto)$ { expires 365d; root $rooturi; } location ^~/api/ { rewrite ^/api/(.*)$ /$1 break; proxy_pass http://aaa.com; } location ^~/b-api/ { rewrite ^/b-api/(.*)$ /$1 break; proxy_pass http://bbb.com; } location / { root $rooturi; try_files $uri $uri/ /index.html =404; add_header Cache-Control "no-cache"; add_header Access-Control-Allow-Origin *; } } This is the end of this article about the implementation example of react project from creation to deployment. For more relevant react project from creation to deployment, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to manually deploy war packages through tomcat9 on windows and linux
>>: Summary of Binlog usage of MySQL database (must read)
To put it simply, the IP of the virtual machine u...
<br />I'm basically going crazy with thi...
1. Disk partition: 2. fdisk partition If the disk...
Compared with other large databases such as Oracl...
Ubuntu 16.04 builds FTP server Install ftp Instal...
With the right settings, you can force Linux user...
MySQL allows you to create multiple indexes on a ...
Problem Description As we all know, when writing ...
Table of contents 1. Introduction 2. Composition ...
1. Server setup The remote repository is actually...
Table of contents background CommonsChunkPlugin s...
Table of contents 1. Shallow cloning 2. Deep clon...
1. First, create the corresponding folder accordi...
MySQL is a very powerful relational database. How...
As a front-end monkey, whether it is during an in...