🎓 A1Learner
🔍
0 of 50 lessons completed

Deploying the Frontend

Deploying the frontend means turning the React code into static files. The build step makes those files, and a host serves them to browsers.

Building the frontend

The build script runs Vite and fills the dist folder.

npm run build

The build script

Preview serves the built files for a local check.

"scripts": {
  "build": "vite build",
  "preview": "vite preview"
}

Example

import fs from 'node:fs';

const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const scripts = pkg.scripts || {};

console.log('name = ' + pkg.name);
console.log('version = ' + pkg.version);
console.log('build script = ' + ('build' in scripts));
console.log('preview script = ' + ('preview' in scripts));
console.log('node modules installed = ' + fs.existsSync('node_modules'));

Key points

  • A static file is served as it is, with no server code behind it.
  • The build step bundles the React code into a few small files.
  • The built files land in a folder named dist.
  • The host serves the dist folder to every browser.

In this example, run this check inside your frontend folder. It reads that folder’s package.json file. It prints the name and version first. It then checks for the build and preview scripts. A frontend folder with those scripts prints true for both checks.

Note

The API address must point at the live API, not the local one.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

Where do the built frontend files land?