@shopify/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.
Installation
$ yarn add @shopify/react-server-webpack-plugin
Usage
With sewing-kit
As of version 0.102.0 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.
Without sewing-kit
First you will need to install all of the dependencies you'll need for your application
yarn add react react-domyarn add webpack @shopify/react-server @shopify/react-server-webpack-plugin @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:
// webpack.config.js ;; ; ; ; module.exports = ;
By default, this plugin expects the entrypoint to your application to be in the root directory.
// index.jsximport React from 'react'; { return <div>I am an app</div>;}
Next you can run webpack && node dist/server.js
. When the server starts up you should see:
started react-server on localhost:PORT
If you point your browser at localhost:PORT
you should see "I am an app". :)
API
The plugin is exported as a named export.
;
It accepts a configuration object with the following interface:
An example configuration for a sewing-kit
app named cool-app
might look like this:
new ReactServerPlugin;