score:1
I think you are looking for an automatic way of merging two outputs, one being your existing HTML with header and footer generated from your existing build process and triggered via a database.
The second being your react app which is a well finished final output that comes out of your create-react-app build infrastructure.
In such a case, I would recommend to use this very popular tool called gulp-inject. gulp-inject takes a stream of source files, transforms each file to a string and injects each transformed string into placeholders in the target stream files.
An example is given below:
Let's say your target file is called index.html like this
<!DOCTYPE html>
<html>
<head>
<title>My index</title>
<!-- inject:css -->
<!-- endinject -->
</head>
<body>
<!-- inject:js -->
<!-- endinject -->
</body>
</html>
Your gulpfile.js script would look like this to achieve a new index.html with new insertions automatically based on this script.
var gulp = require('gulp');
var inject = require('gulp-inject');
gulp.task('index', function () {
var target = gulp.src('./src/index.html');
// It's not necessary to read the files (will speed up things), we're only after their paths:
var sources = gulp.src(['./src/**/*.js', './src/**/*.css'], {read: false});
return target.pipe(inject(sources))
.pipe(gulp.dest('./src'));
});
Your final output of your index.html would look like this after running gulp index:
<!DOCTYPE html>
<html>
<head>
<title>My index</title>
<!-- inject:css -->
<link rel="stylesheet" href="/src/style1.css">
<link rel="stylesheet" href="/src/style2.css">
<!-- endinject -->
</head>
<body>
<!-- inject:js -->
<script src="/src/lib1.js"></script>
<script src="/src/lib2.js"></script>
<!-- endinject -->
</body>
</html>
The basics of converting an existing HTML file and inserting it with ReactJS code is given below. I think if you apply these principles and use the gulp-inject tool, you can achieve wonders.
https://reactjs.org/docs/add-react-to-a-website.html
Your exact build automation maybe driven by your own tool such as Jenkins or such similar tools where you could chain one event with the other. For example, you could check whenever a new HTML file is automatically generated by your Database Triggering on AWS and once that event is received, you could trigger either the Gulp-Inject script if you already have the React Component(s) ready or trigger the Create-React-App to freshly build the React Component and then apply the Gulp-Inject script to inject your React Component or React Code into the index.html or whatever the name of your html page.
The npm package for gulp-inject can be found here.
https://www.npmjs.com/package/gulp-inject
Hope this helps. Let me know.
If you like the answer, you can accept it.
score:1
To do this you need to host your js, css, and media files from your react build folder in an S3 bucket and add the following to the code.
<html>
..... your static html code
<div id="the id used to bootstrap your react app (from the index.html file in the public folder)"></div>
......
links to all the files in your JS, CSS And media files from the react build folder
</html>
I would suggest to use hosted images (you can host them on S3 as well) and assets as much as possible so you don't need to add the media file links on by one in the html file.
You may want to look at this link on how to bundle all files into one file when building your react app (I haven't tried this part).
Source: stackoverflow.com
Related Query
- How to Merge React App into existing Website with existing HTML structure
- How to embed React App into another website
- How to use Turborepo for an existing react app created with Create React App in order to make it a monorepo?
- How to structure a React App with several functional areas on different ports?
- Deploying React + Express App to Kubernetes. How to structure it with docker?
- How do I integrate React with a non-trivial AngularJS app and existing grunt configurations?
- How to insert (inject?) an existing React app (just a UI without a backend) into a SilverStripe page layout?
- How to use HTML with JS in React app to export component
- Merge the html website with react application
- How to Hide and show HTML based on a cookie existing or not in a React App
- how to integrate a wordpress blog into an existing react website ? (as a www.yyyx.com/blog)
- How can I inject a span into a string and have it printed in my react app as HTML
- How to append input values into HTML elements with React
- How to redirect react website into other website with image?
- How can I merge 2 modals into 1 using components with React / Redux?
- How to insert React state value into HTML Template with predefined value in Sun Editor?
- How to detect the device on React SSR App with Next.js?
- How to integrate azure ad into a react web app that consumes a REST API in azure too
- How to run production react app in local with local back-end
- How to include "leaflet.css" in a React app with webpack?
- How to export react app to pure static html
- How to extend HTML attributes in React with Typescript
- How to secure my react app api with csurf?
- How to replace %PUBLIC_URL% in react app on an azure website
- how to import HTML file into React component and use it as a component?
- How to bundle react app with rollup
- How to read console.log from a mounted component with Enzyme and Jest in Create React App
- How to import a file into a react app that uses create react app as raw text?
- How do I configure my Nginx server to work with a React app in a subfolder?
- How to solve TypeScript error with axios response in React app
More Query from same tag
- REACT Component not returning axios data
- FullCalendar (React) - getting dates of current week/month
- Custom Offline Fallback Page with create-react-app and workbox-webpack-plugin
- history.push() and <Redirect /> not working
- Installing react-redux in a Rails project
- Recursion not working properly (in React)
- TypeError: this.setState is not a function, inside Redux Actions file
- Mix HTML and {this.props.foo}
- toLocaleString() is not displaying 00 after decimal point
- TypeScript: Access specific key of excluded readonly object literal
- React/Redux mapStateToProps with nested JSON
- React js : Audio element's src is updating on setState but the audioRef is not
- Axios Interceptor Response Token Refresh API called but getting Token is expired regardless in refreshToken API & lator all APIs
- findDOMNode warnings with CSSTransition components
- Show different component when clicks the button in Reactjs
- multer: can do [req.file.filename] but need [req.files[0].filename] or [req.files.find({fieldname:"samplefield"})]
- What is the point of watchers in redux-saga?
- How to return an array from function react native?
- React.js throttle mousemove event keep throwing event.persist() error
- How to only give MUI Switch border style when it is checked?
- Create more Elements in React
- Using props.change to change the value of an input field in redux-form
- Uncaught TypeError: Cannot read property 'state' of undefined - React
- How to get line coverage on React.useEffect hook when using Jest and enzyme?
- WebStorm/PhpStorm warning for react attributes in jsx like className
- How to fetch and display image in ReactJS, that is returned from web API
- How to filter array with only purchases made by user
- Authenticated login for google enterprise account users
- Material Design React Responsive Cards
- problem with react slick: import { baseUrl } from "./config