Deployment
Atmosphere builds to a folder of static files. You can host it on any web server or static host, with one setting for page links.
#Build
npm run build
This checks the TypeScript types and then writes the site into dist/:
dist/
index.html
favicon.svg
assets/ # JavaScript and CSS files, with a hash in each name
Test the build on your computer before you upload it:
npm run preview
Upload the contents of dist/ to your server. You do not
upload src/, node_modules/ or any other folder.
#The one server setting
Atmosphere is a single-page app. A URL such as /energy/meters has no file
on the server, because the app draws that page in the browser. So the server must
answer every unknown path with index.html. Without this, opening a link directly or reloading a page shows a 404 error from
the server.
Choose your host below.
#Netlify
Create the file public/_redirects with one line. Vite copies it into
dist/ when you build.
/* /index.html 200
#Vercel
Create vercel.json in template/:
{ "rewrites": [{ "source": "/(.*)", "destination": "/index.html" }] }
Set the build command to npm run build and the output folder to
dist.
#Nginx
server {
root /var/www/atmosphere;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
#Apache
Create public/.htaccess. Vite copies it into dist/.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
Your server must have mod_rewrite turned on.
#Hosts without rewrites
Some hosts, such as GitHub Pages, cannot send every path to index.html.
Use hash URLs there, like /#/energy/meters. In src/App.tsx,
change BrowserRouter to HashRouter:
import { HashRouter, Route, Routes, useLocation } from 'react-router-dom';
// ...
<HashRouter>
<Routes>{/* unchanged */}</Routes>
</HashRouter>;
Remove the basename prop when you do this. Hash URLs do not need it.
#Host in a subfolder
To serve the app from a folder, such as https://example.com/admin/, build
with a base path:
npm run build -- --base=/admin/
The router reads the base path by itself, so no code changes are needed. Upload
dist/ into the admin/ folder, and point the server rule at
that folder's index.html.
Nginx:
location /admin/ {
try_files $uri $uri/ /admin/index.html;
}
Apache, in public/.htaccess:
RewriteEngine On
RewriteBase /admin/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /admin/index.html [L]
#Environment variables
Vite reads variables that start with VITE_ from .env files
when you build. For example, .env.production:
VITE_API_URL=https://api.example.com
Read them in code with import.meta.env.VITE_API_URL. The value is written
into the JavaScript files at build time, so you must build again after you change it.
Never put a secret in a VITE_ variable: anyone can read it in the
browser.
#Size and speed
- Every page is loaded only when someone opens it. The first download holds only the shell and the current page.
- The chart library is loaded only by pages that draw charts.
- Only the icons you import are in the build.
- There are no images to download. The logo, avatars, floor plan and camera frames are all drawn with code.
The first JavaScript download is about 135 KB after gzip compression. Your server should send files with gzip or Brotli compression. Most hosts do this by default.
#Browser support
The last two versions of:
- Chrome and Edge
- Firefox
- Safari on macOS and iOS
- Samsung Internet
Internet Explorer is not supported.