Automatically generate the .htaccess file for you each time you export your Expo web app.
Modify package.json
Source code viewer
"scripts": { "build": "expo export -p web && node post-build.js" }Programming Language: JSON
Create post-build.js in the root of your project
This script will create the .htaccess file inside the dist/ folder.Source code viewer
const fs = require("fs"); const path = require("path"); const htaccessContent = ` RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.html [L] `; fs.writeFileSync(path.join(__dirname, "dist", ".htaccess"), htaccessContent, "utf8"); console.log(".htaccess added successfully!");Programming Language: ECMAScript
Run the build
Source code viewer
npm run exportProgramming Language: Bash