Everything you love about Create React App plus server-side code support (SSR, GraphQL API, etc) and config overrides (Babel, Webpack, etc.). See the demo project.
React App SDK is intended to be used as a drop-in replacement for react-scripts NPM module.
If you want to add server-side code into your application built with Create React App, all you have
to do is to replace react-scripts dev dependency with react-app-tools plus provide one more
entry point for Node.js as demonstrated below:
.
βββ build/ # Compiled output
βββ src/ # Universal application source code
β βββ components/ # Shared React.js components
β β βββ /App/ # - The top-level React component
β β βββ /Button/ # - Some other UI element
β β βββ ... # - etc.
β βββ server/ # Node.js app
β β βββ ssr.js # - Server-side rendering, e.g. ReactDOMServer.renderToString(<App />)
β β βββ api.js # - GraphQL API endpoint
β β βββ index.js # - Node.js app entry point
β βββ index.js # Client-side app entry point, e.g. ReactDOM.hydrate(<App />, container)
βββ package.json # List of project dependencies and NPM scripts{
"main": "build/server.js",
"engines": {
"node": ">=8.10"
},
"dependencies": {
+ "express": "^4.6.14",
"react": "^16.8.4",
"react-dom": "^16.8.4"
},
"devDependencies": {
- "react-scripts": "^1.1.1"
+ "react-app-tools": "^3.1.0-preview.7"
},
"scripts": {
- "start": "react-scripts start",
+ "start": "react-app start",
- "build": "react-scripts build",
+ "build": "react-app build",
- "test": "react-scripts test"
+ "test": "react-app test"
}
}import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App';
ReactDOM.hydrate(<App />, document.getElementById('root'));const path = require('path');
const express = require('express');
const React = require('react');
const ReactDOMServer = require('react-dom/server');
const App = require('../components/App');
const stats = require('./stats.json');
const app = express();
app.get('*', (req, res) => {
res.send(`
<html>
<body>
<div id="root">${ReactDOMServer.renderToString(<App />)}</div>
${stats.entrypoints.main.assets.map(
src => `<script src="${src}"></script>`
)}
</body>
</html>
`);
});
if (process.env.NODE_ENV === 'production') {
app.listen(process.env.PORT || 8080);
} else {
module.exports.default = app;
}You can launch the app in development mode by running:
$ npm install
$ npm startThen open http://localhost:3000/ to see your app.
When youβre ready to deploy to production, create a minified bundle with npm run build.
For more information refer to Create React App documentation:
- Getting Started β How to create a new app.
- User Guide β How to develop apps bootstrapped with Create React App.
Join our Telegram chat for support and feature requests - https://t.me/reactapp
Create webpack.config.js file in the root of your project that extends the
default Webpack configuration. For example:
module.exports = () => {
const [
browserConfig,
serverConfig,
] = require('react-app-tools/config/webpack');
return [
browserConfig,
{
...serverConfig,
plugins: {
...serverConfig.plugins.concat(
new LimitChunkCountPlugin({ maxChunks: 1 })
),
},
},
];
};Love React App SDK? Help us keep it alive by donating funds to cover project expenses!
Help shape the future of React App SDK by joining our community today, check out the open issues, submit new feature ideas and bug reports, send us pull requests!
MIT Β© 2016-present Facebook, Kriasoft.
