Summary

These commands will create a new ScandiPWA app, start it up, and open it in your browser.

Creating a ScandiPWA App

You’ll need to have Node >= 12 on your local development machine (but it’s not required on the server). You can use n (macOS, Linux) or nvm-windows to switch Node versions between different projects.

To create a new app, you may choose one of the following methods:

NPX

npx create-scandipwa-app my-app

NPM

npm init scandipwa-app my-app

Yarn

yarn create scandipwa-app my-app

Output

Running any of these commands will create a directory called my-app inside the current folder. Inside that directory, it will generate the initial project structure and install the transitive dependencies. More details:

What is the directory structure?

Available Commands

Inside the newly created project, you can run some built-in commands:

npm run start or yarn start

Runs the app in development mode. Will open the http://localhost:3000 to preview changes in your default browser.

The page will automatically reload if you make changes to the code. You will see the build errors and lint warnings in the console.

npm run build or yarn build

Builds the app for production to the build folder. It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.Your app is ready to be deployed.

Proxying requests to the server

By default, your new application will be fetching data from a remote store. To tell the development server to proxy requests to your Magento 2 server, modify the proxy field of your package.json, for example:

"proxy": "<http://localhost:4000>",

Configuring the Magento server

<aside> ⚠️ If you are proxying requests to a Magento server that already has the ScandiPWA dependencies installed, this step is not required.

</aside>

If you want to use your own Magento instance, you can either create a new CMA (by following this guide) or set up a Magento instance manually.

To use Magento 2 as a data source for ScandiPWA, you are required to make sure that it is using the correct Composer dependencies. The list of your application Composer dependencies can be found in your ScandiPWA composer.json file.

You can copy the dependencies defined in the require field of your ScandiPWA composer.json file to your Magento server’s root composer.json and execute the composer update command.

Configuring proxy manually

If the proxy option is not flexible enough for you, you can get direct access to the Express app instance and hook up your own proxy middleware.

You can use this feature in conjunction with the proxy property in package.json, but it is recommended you consolidate all of your logic into src/setupProxy.js.

First, install http-proxy-middleware using npm or Yarn:

npm install http-proxy-middleware --save # for NPMyarn add http-proxy-middleware # for Yarn

Next, create src/setupProxy.js and place the following contents in it:

const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function(app) {
  // ...
};

You can now register proxies as you wish! Here’s an example using the above http-proxy-middleware:

const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function(app) {
  app.use(
    '/graphql',
    createProxyMiddleware({
      target: '<http://localhost:5000>',
      changeOrigin: true,
    })
  );
};

<aside> ⚠️ You do not need to import this file anywhere. It is automatically registered when you start the development server.

</aside>

Overriding the index.html

When working in storefront mode, ScandiPWA utilizes the public/index.html file. If you need to modify any of its values or import additional assets, you must override it.

Overriding index.html and index.php

magento-app my-app