|
1 | | -# template-electron |
| 1 | +# Template Electron |
| 2 | + |
| 3 | +A modern, production-ready Electron application template built with TypeScript, React, and TailwindCSS. |
| 4 | + |
| 5 | +## 🚀 Features |
| 6 | + |
| 7 | +- ⚡ **Vite** - Lightning fast HMR and build tool |
| 8 | +- ⚛️ **React 19** - Latest React with hooks |
| 9 | +- 🔷 **TypeScript** - Type safety and better DX |
| 10 | +- 🎨 **Tailwind CSS** - Utility-first CSS framework |
| 11 | +- 📦 **Electron Builder** - Package and distribute your app |
| 12 | +- 🔒 **Secure** - Context isolation and secure IPC |
| 13 | + |
| 14 | +## 📋 Prerequisites |
| 15 | + |
| 16 | +- Node.js 18+ and npm |
| 17 | + |
| 18 | +## 🛠️ Installation |
| 19 | + |
| 20 | +```bash |
| 21 | +# Clone the repository |
| 22 | +git clone https://github.com/pnstack/template-electron.git |
| 23 | + |
| 24 | +# Navigate to the project directory |
| 25 | +cd template-electron |
| 26 | + |
| 27 | +# Install dependencies |
| 28 | +npm install |
| 29 | +``` |
| 30 | + |
| 31 | +## 💻 Development |
| 32 | + |
| 33 | +```bash |
| 34 | +# Start the development server |
| 35 | +npm run dev |
| 36 | +``` |
| 37 | + |
| 38 | +This will start the Vite dev server and launch the Electron application with hot-reload enabled. |
| 39 | + |
| 40 | +## 🏗️ Building |
| 41 | + |
| 42 | +```bash |
| 43 | +# Build for production |
| 44 | +npm run build |
| 45 | + |
| 46 | +# Build and package for your current platform |
| 47 | +npm run electron:build |
| 48 | + |
| 49 | +# Build for specific platforms |
| 50 | +npm run electron:build:win # Windows |
| 51 | +npm run electron:build:mac # macOS |
| 52 | +npm run electron:build:linux # Linux |
| 53 | +``` |
| 54 | + |
| 55 | +The packaged application will be in the `release` directory. |
| 56 | + |
| 57 | +## 📁 Project Structure |
| 58 | + |
| 59 | +``` |
| 60 | +template-electron/ |
| 61 | +├── src/ |
| 62 | +│ ├── main/ # Electron main process |
| 63 | +│ │ └── main.ts # Main process entry |
| 64 | +│ ├── preload/ # Preload scripts |
| 65 | +│ │ └── preload.ts # Secure IPC bridge |
| 66 | +│ └── renderer/ # React application |
| 67 | +│ ├── App.tsx # Main React component |
| 68 | +│ ├── main.tsx # React entry point |
| 69 | +│ ├── index.css # Tailwind directives |
| 70 | +│ └── electron.d.ts # TypeScript definitions |
| 71 | +├── index.html # HTML template |
| 72 | +├── vite.config.ts # Vite configuration |
| 73 | +├── tailwind.config.js # Tailwind configuration |
| 74 | +├── tsconfig.json # TypeScript config (renderer) |
| 75 | +├── tsconfig.node.json # TypeScript config (main/preload) |
| 76 | +└── package.json # Project dependencies |
| 77 | +``` |
| 78 | + |
| 79 | +## 🔧 Configuration |
| 80 | + |
| 81 | +### Vite |
| 82 | +The Vite configuration (`vite.config.ts`) includes: |
| 83 | +- React plugin for JSX/TSX support |
| 84 | +- Electron plugin for main and preload scripts |
| 85 | +- Path aliases for cleaner imports |
| 86 | + |
| 87 | +### Electron |
| 88 | +The main process (`src/main/main.ts`) creates the browser window and handles: |
| 89 | +- Window creation and management |
| 90 | +- Loading the renderer in dev/prod mode |
| 91 | +- IPC communication with renderer |
| 92 | + |
| 93 | +### Tailwind CSS |
| 94 | +Configure Tailwind by editing `tailwind.config.js`. The template includes: |
| 95 | +- Configured content paths for tree-shaking |
| 96 | +- Ready for custom themes and plugins |
| 97 | + |
| 98 | +## 🔒 Security |
| 99 | + |
| 100 | +This template follows Electron security best practices: |
| 101 | +- Context isolation enabled |
| 102 | +- Node integration disabled |
| 103 | +- Secure IPC via preload script |
| 104 | +- No direct Node.js access in renderer |
| 105 | + |
| 106 | +## 🤝 Contributing |
| 107 | + |
| 108 | +Contributions are welcome! Please feel free to submit a Pull Request. |
| 109 | + |
| 110 | +## 📄 License |
| 111 | + |
| 112 | +MIT License - feel free to use this template for any project! |
| 113 | + |
| 114 | +## 🙏 Acknowledgments |
| 115 | + |
| 116 | +Built with: |
| 117 | +- [Electron](https://www.electronjs.org/) |
| 118 | +- [React](https://react.dev/) |
| 119 | +- [Vite](https://vitejs.dev/) |
| 120 | +- [Tailwind CSS](https://tailwindcss.com/) |
| 121 | +- [TypeScript](https://www.typescriptlang.org/) |
0 commit comments