This guide walks you through the complete steps to:
β
 Create a React app with TypeScript
β
 Set up Capacitor
β
 Load an external web URL (like a live panel) inside your Android/iOS app
β
 Optionally preview it during development
π§± Step 1: Create React App with TypeScript
npx create-react-app my-app
cd my-app
(Replace
my-appwith your desired project name.)
π οΈ Step 2: Convert Project to TypeScript
π¦ Install TypeScript & React Types
npm install --save typescript @types/react @types/react-dom
π Rename Files
- 
.jsβ.ts(for non-JSX files)
- 
.jsxβ.tsx(for component files)
π οΈ Create tsconfig.json
npx tsc --init
npm install --save-dev @types/jest
π§© Modify index.tsx
const root = ReactDOM.createRoot(document.getElementById('root')!);
π§ͺ Update reportWebVitals.tsx
import { ReportHandler } from 'web-vitals';
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
  if (onPerfEntry && onPerfEntry instanceof Function) {
    import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
      getCLS(onPerfEntry);
      getFID(onPerfEntry);
      getFCP(onPerfEntry);
      getLCP(onPerfEntry);
      getTTFB(onPerfEntry);
    });
  }
};
export default reportWebVitals;
π§Ύ Replace tsconfig.json
{
  "compilerOptions": {
    "module": "ESNext",
    "target": "ESNext",
    "moduleResolution": "Node",
    "verbatimModuleSyntax": false,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "jsx": "react-jsx",
    "resolveJsonModule": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "isolatedModules": true,
    "noEmit": true
  },
  "include": ["src"]
}
β Your project is now TypeScript ready!
βοΈ Step 3: Set Up Capacitor
π¦ Install Capacitor Core and CLI
npm install @capacitor/core @capacitor/cli --force
π§ Initialize Capacitor
npx cap init
ποΈ Build Your React App
npm run build
β Add Android Platform
npx cap add android
npm install @capacitor/android --force
π Sync Capacitor Config
npx cap sync
π± Open Android Project in Android Studio
npx cap open android
π οΈ Every time you update the React app:
npm run build
npx cap sync
π Step 4: Load External Web URL in Capacitor
Update your capacitor.config.ts or capacitor.config.json:
const config: CapacitorConfig = {
  appId: 'com.yourcompany.app',
  appName: 'app',
  webDir: 'build',
  server: {
    url: '{Your Web Url}',
    cleartext: true
  }
};
export default config;
π (Optional) Show Web App in iFrame for Local Preview
Example App.tsx
import './App.css';
function App() {
  return (
    <div className="App" style={{ height: '100vh', margin: 0, padding: 0 }}>
      <iframe
        src="{Your Web Url}"
        title="Admin"
        width="100%"
        height="100%"
        style={{ border: 'none' }}
      />
    </div>
  );
}
export default App;
β οΈ Notes
π¦ FlatDir Warning (Android)
Check your android/build.gradle:
allprojects {
    repositories {
        google()
        mavenCentral()
        flatDir {
            dirs project(':capacitor-android').file('libs')
        }
    }
}
Leave it as-is, unless you're troubleshooting plugin issues.
β You're Done!
You've successfully:
π Created a React + TypeScript app
π Integrated Capacitor
π Configured it to load a live web app
π§ͺ Built and previewed the app locally and on Android
 
 
              
 
    
Top comments (0)