Magento 2 – How Setup Magento 2 PWA?

Setup PWA (Linux os)

Step 1 : Install magento 2.3.1

Step 2 : Install/upgrade node

Use n module from npm in order to upgrade node

sudo npm install n -g

For the latest stable version:

sudo n stable

For the latest version:

sudo n latest

Step 3: Install/update yarn :

sudo npm install –global yarn

sudo npm upgrade –global yarn

Step 4 : Install node-gyp – Node.js native addon build tool

sudo npm install -g node-gyp

Step 5 : Clone the PWA Studio repository

Go to html root and run :

git clone https://github.com/magento-research/pwa-studio.git

After running this you will get pwa-studio folder

Step 6: Install PWA Studio dependencies

sudo yarn install

Step 7: Specify the Magento backend server

Under the packages/venia-concept directory, copy .env.dist into a new .env file:

Example command:

sudo cp packages/venia-concept/.env.dist packages/venia-concept/.env
change in .env file (this will be your magento URL, not admin url):

MAGENTO_BACKEND_URL=”https://release-dev-231-npzdaky-zddsyhrdimyra.us-4.magentosite.cloud/”

Step 8: Now create a build

sudo yarn run build

Step 9: Run the server

sudo yarn run watch:venia

Starts the Venia storefront development environment only.

sudo yarn run watch:all

Runs the full PWA Studio developer experience, which include Venia hot-reloading and concurrent Buildpack/Peregrine rebuilds.

sudo yarn run build && yarn run stage:venia

Generates build artifacts and runs the staging environment, which uses more compressed assets and more closely reflects production.

Once you run one of the above command you will get the virtul url created by PWA.

NOTE: if you are root user then use sudo.

Follow Magento 2 officical dev docs:

https://devdocs.magento.com/guides/v2.3/pwa/

https://magento.stackexchange.com/questions/276351/how-to-setup-pwa-in-magento-2-3-1/276353#276353