Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: init cra-universal 5 #226

Merged
merged 4 commits into from
May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
}
"presets": [
"@babel/preset-env",
[
"@babel/preset-react",
{
"runtime": "automatic"
}
]
]
}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
node_modules
coverage
lib
lerna-debug.log
yarn-error.log
pnpm-lock.yaml
.pnpm-debug.log

.DS_Store

Expand Down
File renamed without changes.
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

22 changes: 16 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,38 @@ The following is a helpful information for contributors of CRA Universal and its

## Packages

This project consists of multiple packages. We use [Lerna](https://github.com/lerna/lerna) to manage them.
This project consists of multiple packages. We use [pnpm](https://pnpm.io/) to manage them.

### @cra-express/core
Core module where Express app with static and universal loaders gets created.

Core module where Express app with static and universal loaders gets created.

### @cra-express/static-loader

Sets up static files serving in Express app.

### @cra-express/universal-loader
Sets up universal middleware that is serving SSR in Express app.

### @cra-express/redux-prefetcher
Sets up universal middleware that is serving SSR in Express app.

### @cra-express/redux-prefetcher (deprecated)

Simple utility to map your routes and prefetch your data on a server using Redux as a store.

### @cra-express/router-prefetcher

Simple utility to map your routes and prefetch your data on a server.

### babel-preset-cra-universal

This package includes the Babel preset used by CRA Universal.

### cra-universal

Create React App Universal CLI.

### demo

Demo project using CRA-universal. It has symlinks to the above packages in node_modules. Doesn't get published.

### packages/cra-universal/templates
Expand All @@ -38,8 +46,8 @@ Since we need a way to test the cra-universal locally and seamlessly, we have a

Use `temp:start:client` to run client and server locally.

* Normal CRA starts at http://localhost:3000
* Server-rendered CRA Universal starts at http://localhost:3001
- Normal CRA starts at http://localhost:3000
- Server-rendered CRA Universal starts at http://localhost:3001

To run a production build of this app, preserving local CRA Universal, use these commands:

Expand All @@ -52,8 +60,10 @@ node --preserve-symlinks dist/server/bundle.js
### Webpack versions mismatch

An error may occur when running `temp:start:client`.

```
There might be a problem with the project dependency tree.
...
```

To fix it simply add `SKIP_PREFLIGHT_CHECK=true` to an .env file in project root directory.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Antony Budianto
Copyright (c) 2022 Antony Budianto

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
# cra-universal

### Create React App Universal CLI

[![Financial Contributors on Open Collective](https://opencollective.com/cra-universal/all/badge.svg?label=financial+contributors)](https://opencollective.com/cra-universal) [![npm version](https://badge.fury.io/js/cra-universal.svg)](https://badge.fury.io/js/cra-universal)
[![Build Status](https://travis-ci.org/antonybudianto/cra-universal.svg?branch=master)](https://travis-ci.org/antonybudianto/cra-universal) [![Greenkeeper badge](https://badges.greenkeeper.io/antonybudianto/cra-universal.svg)](https://greenkeeper.io/)
[![Financial Contributors on Open Collective](https://opencollective.com/cra-universal/all/badge.svg?label=financial+contributors)](https://opencollective.com/cra-universal) [![npm version](https://badge.fury.io/js/cra-universal.svg)](https://badge.fury.io/js/cra-universal))

<p align="center">
<img width="500" height="350" alt="zero" src="https://user-images.githubusercontent.com/7658554/42420108-261a1c5a-82eb-11e8-8ac0-ce2e0245e0ff.png">
</p>


Create React App companion for universal app. No eject, zero config with customization, supports string and node stream API

> [Live Demo](https://cra-universal.now.sh/) | [Official Doc](https://antonybudianto.github.io/cra-universal)

## Features

* **No [eject](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-eject)** needed!
* **Zero config** by default and **customizable**
* **Server-side rendering** for your SEO
* **Code-splitting** that works universally
* The core middleware is fully **unit-tested**
* Works alongside `react-scripts`, not as replacement
- **No [eject](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-eject)** needed!
- **Zero config** by default and **customizable**
- **Server-side rendering** for your SEO
- **Code-splitting** that works universally
- The core middleware is fully **unit-tested**
- Works alongside `react-scripts`, not as replacement

## Prerequisites

- Node >= 12.16.1 LTS recommended
- Node >= 14.17.5 LTS recommended
- npx is required

## Installation
Expand All @@ -38,8 +37,9 @@ cd myapp
yarn add -D cra-universal

# Install peer dependency
yarn add @cra-express/core
yarn add @cra-express/core express@4.18.1
```

## Existing Projects

```sh
Expand All @@ -48,7 +48,7 @@ yarn add @cra-express/core
yarn add -D cra-universal

# Install peer dependency
yarn add @cra-express/core
yarn add @cra-express/core express@4.18.1

# init
yarn run cra-universal init
Expand All @@ -63,10 +63,11 @@ Please update your render method on `src/index.js`

```js
// before
ReactDOM.render(...)
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);

// after
ReactDOM.hydrate(...)
ReactDOM.hydrateRoot(document.getElementById('root'), <App />);
```

## Development
Expand All @@ -87,8 +88,8 @@ npx cra-universal build

# This command will build both client and server and put them into `./dist`
# Run locally:
# $ node --preserve-symlinks dist/server/bundle.js
# You only need `--preserve-symlinks` on local, since we only do symlinks on development.
# $ cd dist && npm i
# $ npm run serve
```

## Deployment
Expand All @@ -99,8 +100,8 @@ npx cra-universal build

## Credit

* Create React App https://github.com/facebook/create-react-app
* Thanks for https://github.com/ayroblu/ssr-create-react-app-v2 for the base!
- Create React App https://github.com/facebook/create-react-app
- Thanks for https://github.com/ayroblu/ssr-create-react-app-v2 for the base!

## Support

Expand Down
19 changes: 0 additions & 19 deletions greenkeeper.json

This file was deleted.

10 changes: 0 additions & 10 deletions lerna.json

This file was deleted.

47 changes: 17 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,21 @@
"description": "CRA Universal Monorepo",
"private": true,
"scripts": {
"build": "lerna run build",
"crau:build": "lerna run crau:build",
"test": "lerna run test:ci",
"watch": "lerna run --parallel watch",
"bootstrap": "lerna bootstrap",
"clean": "lerna clean",
"clean:build": "lerna exec -- rimraf lib",
"build:lib": "npm run build -- --ignore={cra-universal-demo,cra-template}",
"test": "pnpm run test:ci --filter=@cra-express/*",
"bs": "pnpm recursive install && npm run build:lib",
"bootstrap": "pnpm recursive install",
"ls": "pnpm -r --filter=!cra-universal-monorepo exec pwd",
"clean": "npm run clean2 && npm run clean:lib && rimraf node_modules",
"clean2": "pnpm -r --filter=!cra-universal-monorepo exec rimraf node_modules",
"clean:lib": "pnpm -r --filter=@cra-express/* exec rimraf lib",
"build:lib": "pnpm run build --filter=@cra-express/*",
"prerelease": "npm run build:lib",
"release": "lerna publish",
"ls": "lerna ls",
"release:next": "npm run release -- --npm-tag=next",
"exec:rp": "lerna exec --scope @cra-express/redux-prefetcher --",
"exec:rr": "lerna exec --scope @cra-express/router-prefetcher --",
"exec:ul": "lerna exec --scope @cra-express/universal-loader --",
"release": "pnpm -r --filter=@cra-express/* --filter=cra-universal --filter=babel-preset-cra-universal exec npm publish",
"release:beta": "npm run release -- --npm-tag=beta",
"ul:test": "npm run exec:ul -- npm t --",
"temp:exec": "lerna exec --scope cra-template --",
"temp:start:client": "lerna exec --scope cra-template -- npm start",
"temp:start:server": "lerna exec --scope cra-template -- yarn crau:start",
"temp:build": "lerna exec --scope cra-template -- yarn crau:build",
"demo:start:client": "lerna exec --scope cra-universal-demo -- npm start",
"demo:start:server": "lerna exec --scope cra-universal-demo -- yarn crau:start",
"demo:build": "lerna exec --scope cra-universal-demo -- yarn crau:build"
"temp:start:client": "pnpm run start --filter=cra-template",
"temp:start:server": "pnpm run crau:start --filter=cra-template",
"temp:build": "pnpm run crau:build --filter=cra-template"
},
"repository": {
"type": "git",
Expand All @@ -43,17 +35,12 @@
"url": "https://github.com/antonybudianto/cra-universal/issues"
},
"homepage": "https://github.com/antonybudianto/cra-universal#readme",
"resolutions": {
"babel-core": "7.0.0-bridge.0"
},
"devDependencies": {
"@babel/cli": "7.6.0",
"@babel/core": "7.6.0",
"@babel/preset-env": "7.6.0",
"@babel/preset-react": "7.0.0",
"babel-core": "7.0.0-bridge.0",
"@babel/cli": "7.17.10",
"@babel/core": "7.17.10",
"@babel/preset-env": "7.17.10",
"@babel/preset-react": "7.16.7",
"jest": "24.9.0",
"lerna": "3.16.4",
"rimraf": "^3.0.0"
}
}
10 changes: 9 additions & 1 deletion packages/@cra-express/core/.babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{
"presets": ["@babel/preset-env", "@babel/preset-react"]
"presets": [
"@babel/preset-env",
[
"@babel/preset-react",
{
"runtime": "automatic"
}
]
]
}
12 changes: 6 additions & 6 deletions packages/@cra-express/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@cra-express/core",
"version": "4.3.2",
"description": "",
"version": "5.0.1",
"description": "Core module for cra-universal server",
"main": "lib/index.js",
"files": [
"lib"
Expand All @@ -16,12 +16,12 @@
},
"peerDependencies": {
"react": "*",
"react-dom": "*"
"react-dom": "*",
"express": "^4.18.1"
},
"dependencies": {
"@cra-express/static-loader": "^4.3.2",
"@cra-express/universal-loader": "^4.3.2",
"express": "4.17.1"
"@cra-express/static-loader": "^5",
"@cra-express/universal-loader": "^5"
},
"author": "Antony Budianto <antonybudianto@gmail.com>",
"license": "MIT"
Expand Down
8 changes: 4 additions & 4 deletions packages/@cra-express/core/src/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const express = require('express');
const staticLoader = require('@cra-express/static-loader').default;
const universalLoader = require('@cra-express/universal-loader').default;
import express from 'express';
import staticLoader from '@cra-express/static-loader';
import universalLoader from '@cra-express/universal-loader';

function createReactAppExpress (options) {
function createReactAppExpress(options) {
const app = express();
staticLoader(app, options);
universalLoader(app, options);
Expand Down