Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

Commit

Permalink
✖️ deprecate react-server-webpack-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
michenly committed Jun 3, 2020
1 parent 720d453 commit 6cc2c86
Show file tree
Hide file tree
Showing 24 changed files with 223 additions and 74 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ matrix:
name: 'Node - build, type-check, and end-to-end tests'
script:
- yarn build --verbose
- yarn test:ci --testPathPattern react-server-webpack-plugin address
- yarn test:ci --testPathPattern address
- <<: *node_container
name: 'Node - unit tests'
script:
- yarn test:ci --testPathIgnorePatterns react-server-webpack-plugin address
- yarn test:ci --testPathIgnorePatterns address
- yarn codecov
- <<: *node_container
name: 'Node - lint'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Each package has its own `README` and documentation describing usage.
| koa-shopify-graphql-proxy | [directory](packages/koa-shopify-graphql-proxy) | [![npm version](https://badge.fury.io/js/%40shopify%2Fkoa-shopify-graphql-proxy.svg)](https://badge.fury.io/js/%40shopify%2Fkoa-shopify-graphql-proxy) |
| koa-shopify-webhooks | [directory](packages/koa-shopify-webhooks) | [![npm version](https://badge.fury.io/js/%40shopify%2Fkoa-shopify-webhooks.svg)](https://badge.fury.io/js/%40shopify%2Fkoa-shopify-webhooks) |
| logger | [directory](packages/logger) | [![npm version](https://badge.fury.io/js/%40shopify%2Flogger.svg)](https://badge.fury.io/js/%40shopify%2Flogger) |
| magic-entries-webpack-plugin | [directory](packages/magic-entries-webpack-plugin) | [![npm version](https://badge.fury.io/js/%40shopify%2Fmagic-entries-webpack-plugin.svg)](https://badge.fury.io/js/%40shopify%2Fmagic-entries-webpack-plugin) |
| mime-types | [directory](packages/mime-types) | [![npm version](https://badge.fury.io/js/%40shopify%2Fmime-types.svg)](https://badge.fury.io/js/%40shopify%2Fmime-types) |
| network | [directory](packages/network) | [![npm version](https://badge.fury.io/js/%40shopify%2Fnetwork.svg)](https://badge.fury.io/js/%40shopify%2Fnetwork) |
| performance | [directory](packages/performance) | [![npm version](https://badge.fury.io/js/%40shopify%2Fperformance.svg)](https://badge.fury.io/js/%40shopify%2Fperformance) |
Expand Down Expand Up @@ -76,7 +77,6 @@ Each package has its own `README` and documentation describing usage.
| react-performance | [directory](packages/react-performance) | [![npm version](https://badge.fury.io/js/%40shopify%2Freact-performance.svg)](https://badge.fury.io/js/%40shopify%2Freact-performance) |
| react-router | [directory](packages/react-router) | [![npm version](https://badge.fury.io/js/%40shopify%2Freact-router.svg)](https://badge.fury.io/js/%40shopify%2Freact-router) |
| react-server | [directory](packages/react-server) | [![npm version](https://badge.fury.io/js/%40shopify%2Freact-server.svg)](https://badge.fury.io/js/%40shopify%2Freact-server) |
| react-server-webpack-plugin | [directory](packages/react-server-webpack-plugin) | [![npm version](https://badge.fury.io/js/%40shopify%2Freact-server-webpack-plugin.svg)](https://badge.fury.io/js/%40shopify%2Freact-server-webpack-plugin) |
| react-shortcuts | [directory](packages/react-shortcuts) | [![npm version](https://badge.fury.io/js/%40shopify%2Freact-shortcuts.svg)](https://badge.fury.io/js/%40shopify%2Freact-shortcuts) |
| react-testing | [directory](packages/react-testing) | [![npm version](https://badge.fury.io/js/%40shopify%2Freact-testing.svg)](https://badge.fury.io/js/%40shopify%2Freact-testing) |
| react-tracking-pixel | [directory](packages/react-tracking-pixel) | [![npm version](https://badge.fury.io/js/%40shopify%2Freact-tracking-pixel.svg)](https://badge.fury.io/js/%40shopify%2Freact-tracking-pixel) |
Expand Down
2 changes: 2 additions & 0 deletions gems/quilt_rails/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- Add: Expose a `data` argument on `render_react` to share data to the React server using the `X-Quilt-Data` header ([#1411](https://github.com/Shopify/quilt/pull/1411))

⚠️ this change has the minimal requirement of `@shopify/react-server` v0.12.0 and `@shopify/react-server-webpack-plugin` v3.0.0 (or `@shopify/sewing-kit` v0.128.0)

## [1.11.1] - 2020-03-24

- add `allowed_push_host` in gemspec that is required to publish
Expand Down
4 changes: 2 additions & 2 deletions gems/quilt_rails/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ A turn-key solution for integrating Quilt client-side libraries into your Rails

## Server-side-rendering

🗒 This guide is focused on internal Shopify developers with access to [`dev`](https://github.com/Shopify/dev) and [@shopify/sewing-kit](https://github.com/Shopify/sewing-kit). A similar setup can be achieved using the [manual installation](./docs/manual-installation) , and following the [react-server-webpack-plugin](../../packages/react-server-webpack-plugin/README.md) guide. Apps not running on Shopify infrastructure should [disable server-side GraphQL queries](./docs/FAQ.md) to avoid scalability issue.
🗒 This guide is focused on internal Shopify developers with access to [`dev`](https://github.com/Shopify/dev) and [@shopify/sewing-kit](https://github.com/Shopify/sewing-kit). A similar setup can be achieved using the [manual installation](./docs/manual-installation) , and following the [react-server webpack plugin](../../packages/react-server/README.md#webpack-plugin) guide. Apps not running on Shopify infrastructure should [disable server-side GraphQL queries](./docs/FAQ.md) to avoid scalability issue.

### Quick start

Expand Down Expand Up @@ -222,7 +222,7 @@ With SSR enabled React apps, state must be serialized on the server and deserial

#### Customizing the Node server

By default, sewing-kit bundles in [`@shopify/react-server-webpack-plugin`](../../packages/react-server-webpack-plugin/README.md) for `quilt_rails` applications to get apps up and running fast without needing to manually write any Node server code.
By default, sewing-kit bundles in [`@shopify/react-server/webpack`](../../packages/react-server/README.md#webpack-plugin) for `quilt_rails` applications to get apps up and running fast without needing to manually write any Node server code.

If what it provides is not sufficient, a completely custom server can be defined by adding a `server.js` or `server.ts` file to the `app/ui` folder. The simplest way to customize the server is to export the object created by [`@shopify/react-server`](../../packages/react-server/README.md#node-usage)'s `createServer` call in `server.ts` file.

Expand Down
2 changes: 1 addition & 1 deletion gems/quilt_rails/docs/manual-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ yarn add typescript @types/react @types/react-dom
```

🗒️ Ignore `sewing_kit` and `@shopify/sewing-kit` dependencies if you don't have access to it.
Instead, make sure to use [`react-server-webpack-plugin`](../../packages/react-server-webpack-plugin/README.md) with your webpack configuration.
Instead, make sure to use [`react-server webpack plugin`](../../../packages/react-server/README.md#webpack-plugin) with your webpack configuration.

##### Define typescript config

Expand Down
2 changes: 1 addition & 1 deletion packages/react-router/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Rendering the `Router` component at the top-level of your application will creat

This value should be derived from the server-side Node http request object. If you are rendering your app with a Node based web framework (such as [Koa](https://koajs.com/#request) or [Express](http://expressjs.com/en/5x/api.html#req)), there will be a standard convention for accessing this object within the lifecycle of each request to your server.

A typical application will have a middleware within their application chain that is responsible for rendering the React tree, and providing your main App component the `location` prop. It can then delegate this value to the `Router` on the `location` prop. We also provide a simple library, [`@shopify/react-server`](../packages/react-server), for React server-side rendering.
A typical application will have a middleware within their application chain that is responsible for rendering the React tree, and providing your main App component the `location` prop. It can then delegate this value to the `Router` on the `location` prop. We also provide a simple library, [`@shopify/react-server`](../react-server/README.md), for React server-side rendering.

```tsx
import React from 'react';
Expand Down
4 changes: 4 additions & 0 deletions packages/react-server-webpack-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## ❗️ Deprecated on version 3.1.0 ❗️

**Note**: This module is now deprecated and included as part of [`@shopify/react-server`](../react-server/README.md#webpack-plugin).

<!-- ## [Unreleased] -->

## [3.1.0] - 2020-05-29
Expand Down
4 changes: 4 additions & 0 deletions packages/react-server-webpack-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
[![Build Status](https://travis-ci.org/Shopify/quilt.svg?branch=master)](https://travis-ci.org/Shopify/quilt)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE.md) [![npm version](https://badge.fury.io/js/%40shopify%2Freact-server-webpack-plugin.svg)](https://badge.fury.io/js/%40shopify%2Freact-server-webpack-plugin.svg)

## ❗️ Deprecated on version 3.1.0 ❗️

**Note**: This module is now deprecated and included as part of [`@shopify/react-server`](../react-server/README.md#webpack-plugin).

A webpack plugin which generates "virtual" in-memory entrypoints for `@shopify/react-server` based applications. This plugin allows you to run a universal React application without needing any client/server-specific code.

## Installation
Expand Down
39 changes: 0 additions & 39 deletions packages/react-server-webpack-plugin/package.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/react-server-webpack-plugin/src/index.ts

This file was deleted.

16 changes: 0 additions & 16 deletions packages/react-server-webpack-plugin/tsconfig.json

This file was deleted.

8 changes: 7 additions & 1 deletion packages/react-server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

<!-- ## [Unreleased] -->
## [Unreleased]

## [0.13.0] - 2020-06-??

### Changed

- Move `react-server-webpack-plugin` into `react-server` and expose it from `@shopify/react-server/webpack` ([#1489](https://github.com/Shopify/quilt/pull/1489))

## [0.12.0] - 2020-05-12

Expand Down
2 changes: 1 addition & 1 deletion packages/react-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ If you already have an existing node server, you can opt in to using only the re

## Webpack Plugin

We also provide a [webpack plugin](https://github.com/Shopify/quilt/blob/master/packages/react-server-webpack-plugin) to automatically generate the server and client entries for an application.
We also provide a [webpack plugin](./docs/webpack-plugin) to automatically generate the server and client entries for an application.

### Deployment (Shopify specific)

Expand Down
179 changes: 179 additions & 0 deletions packages/react-server/docs/webpack-plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# React Server Webpack Plugin

A webpack plugin which generates "virtual" in-memory entrypoints for `@shopify/react-server` based applications. This plugin allows you to run a universal React application without needing any client/server-specific code.

## Usage

### With sewing-kit

As of version [0.102.0](https://github.com/Shopify/sewing-kit/blob/big-docs-update/CHANGELOG.md#L35) `sewing-kit` consumes this plugin by default if you have `@shopify/react-server` in your `package.json`.

For detailed instructions on usage with Rails and sewing-kit see the documentation for [quilt_rails](/gems/quilt_rails/README.md).

### Without sewing-kit

First you will need to install all of the dependencies you'll need for your application

```sh
yarn add react react-dom
yarn add webpack @shopify/react-server @shopify/webpack-asset-metadata-plugin --dev
```

Since `@shopify/react-server` relies on `@shopify/webpack-asset-metadata-plugin`, you will need to setup both plugins in your webpack configuration. A simple starter (not production optimized) webpack setup is as follows:

```tsx
// webpack.config.js

const {ReactServerPlugin} = require('@shopify/react-server/webpack');
const {AssetMetadataPlugin} = require('@shopify/webpack-asset-metadata-plugin');

const universal = {
mode: 'development',
optimization: {
minimize: false,
},
plugins: [new AssetMetadataPlugin(), new ReactServerPlugin()],
};

const server = {
...universal,
name: 'server',
target: 'node',
entry: './server',
externals: [
(context, request, callback) => {
if (/node_modules/.test(context)) {
return callback(null, `commonjs ${request}`);
}
callback();
},
],
};

const client = {
...universal,
name: 'client',
target: 'web',
entry: './client',
};

module.exports = [server, client];
```

By default, this plugin expects the entrypoint to your application to be in the root directory.

```jsx
// index.jsx
import React from 'react';

export default function App() {
return <div>I am an app</div>;
}
```

Next you can run `webpack && node dist/server.js`. When the server starts up you should see:

```sh
started react-server on localhost:PORT
```

If you point your browser at `localhost:PORT` you should see "I am an app". :)

### Automatic Props

The plugin passes some props to your application automatically.

```typescript
interface DefaultProps {
/*
The full WHATWG URL object for the initial request. On the client this will *not* update reactively. It is always the URL for the initial request.
*/
url: URL;

/*
An object containing any data sent via the `x-quilt-data` header.
This header is used by `quilt_rails` for sending data directly from ruby to React.
*/
data: Record<string, any>;
}
```

These props are provided during both server-side and client-side rendering, so they can be used without any special logic around what environment your app is in.

These props can be used to feed initial data into your application for use with libraries such as `react-router`, as well as for simple app logic.

```tsx
// index.jsx
import React from 'react';

export default function App({url, data}: {url: Url, data: Record<string, any>}) {
const {href} = url;
if (href.endsWith('/about')) {
return <div>this is an about page</div>;
}

return (
<div>
I am an app, here are some items:
<ul>
{data.items.forEach(({content, id}) => (
<li key={id}>{content}</li>;
))}
</ul>
</div>
);
}
```

### API

The plugin is exported as a named export.

```tsx
import {ReactServerPlugin} from '@shopify/react-server/webpack';
```

It accepts a configuration object with the following interface:

```tsx
interface Options {
/*
The base-path to use for the `client.js` and `server.js` virtual entry files,
this should also be where your index.tsx/jsx is.
default: '.'
*/

basePath: string;

/*
The host to use when calling `createServer` from `@shopify/react-server`,
this should also be where your index.tsx/jsx is.
default: process.env.REACT_SERVER_IP || "localhost"
*/
host: string;

/*
The port to use when calling `createServer` from `@shopify/react-server`
default: process.env.REACT_SERVER_PORT || 8081
*/
port: number;

/*
The assetPrefix to use when calling `createServer` from `@shopify/react-server`.
default: process.env.CDN_URL || "localhost:8080/assets/webpack"
*/
assetPrefix: string;
}
```

An example configuration for a `sewing-kit` app named `cool-app` might look like this:

```tsx
new ReactServerPlugin({
assetPrefix: process.env.CDN_URL || 'https://localhost:8080/webpack/assets/';
});
```
12 changes: 10 additions & 2 deletions packages/react-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,26 @@
"@shopify/with-env": "^1.1.8",
"@types/koa": "^2.0.0",
"@types/supertest": "^2.0.8",
"@types/webpack-virtual-modules": "^0.1.0",
"get-port": "^5.0.0",
"react": "^16.8.1",
"react-dom": "^16.8.1",
"supertest": "^4.0.2"
"supertest": "^4.0.2",
"webpack": ">4.25.1, <=4.5.0"
},
"peerDependencies": {
"isomorphic-fetch": ">=2.0.0",
"react": ">=16.8.0 <17.0.0",
"react-dom": ">=16.8.0 <17.0.0"
},
"optionalDependencies": {
"@babel/types": ">=7.0.0",
"webpack-virtual-modules": "^0.2.2"
},
"files": [
"dist/*",
"!tsconfig.tsbuildinfo"
"!tsconfig.tsbuildinfo",
"webpack.d.ts",
"webpack.js"
]
}
1 change: 1 addition & 0 deletions packages/react-server/src/webpack-plugin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {ReactServerPlugin} from './webpack-plugin';
Loading

0 comments on commit 6cc2c86

Please sign in to comment.