RepositoryJavaScript
SI

sindresorhus/electron-serve

Static file serving for Electron apps

486sao
35fork
0issue
0lượt xem

Thành tựu nổi bật

Những danh hiệu mới nhất của dự án

1
TINIX TRENDING·Chủ đề: static-file-server

#1 Repository Của Tháng

1
TINIX TRENDING·Chủ đề: electron-module

#1 Repository Của Tháng

1
TINIX TRENDING·Chủ đề: npm-package

#1 Repository Của Tháng

🖥️ Phục vụ file tĩnh cho Electron app không cần file://

win.loadURL('file://…') không hoạt động với SPA. electron-serve giải quyết bằng custom protocol + fallback tự động.

electron-serve là một npm package nhẹ của sindresorhus, giải quyết vấn đề kinh điển khi build Electron app dạng single-page: history.pushState() tạo URL không tồn tại trên filesystem, nên win.loadURL('file://…') fail. Thư viện cài đặt một custom protocol server, phục vụ file thật nếu có, fallback về index.html nếu không — cho phép react-router, vue-router hoạt động bình thường.

✨ Điểm nổi bật

  • SPA routing hỗ trợ: Fallback tự động về index.html khi URL không tìm thấy trên disk, tương thích với mọi router module
  • Custom protocol: Dùng app://- thay vì file://, configurable scheme và hostname cho nhiều window
  • ES modules out-of-the-box: Serve file JS với MIME type text/javascript đúng chuẩn, hỗ trợ import/export
  • Source maps: File .map phục vụ đúng MIME type, Chrome DevTools load được cho debugging minified code
  • Multiple windows: Dùng unique scheme cho mỗi window, mỗi window phục vụ directory hoặc file khác nhau
  • Search parameters: Truyền query params qua loadUrl(window, {id: 4, foo: 'bar'})
  • CORS toggle: isCorsEnabled mặc định true, tắt khi không cần cho production
  • Electron 37+: Yêu cầu phiên bản Electron mới nhất

💡 Vì sao đáng chú ý

Không có electron-serve, dev phải tự viết protocol handler hoặc dùng workaround rườm rà cho SPA routing trong Electron. Thư viện này rút gọn toàn bộ logic xuống một hàm serve() trả về loadUrl, gọi một lần là xong. Đặc biệt hữu ích khi cần nhiều window với nội dung khác nhau — chỉ cần khai báo thêm một serve({directory: '…', scheme: '…'}) riêng.

Yêu cầu Electron 37 trở lên. Kết hợp tốt với electron-util, electron-reloader, electron-debug trong cùng hệ sinh thái của sindresorhus.


#electron #electronjs #static-file-server #spa #javascript #TiniX

Dự án tương tự

Khám phá các dự án và mô hình AI khác có sự tương đồng.

RepositoryC++
electron/electron

:electron: Build cross-platform desktop apps with JavaScript, HTML, and CSS

123.5k
Oct 23, 2026
RepositoryTypeScript
freeCodeCamp/freeCodeCamp

freeCodeCamp.org's open-source codebase and curriculum. Learn math, programming, and computer science for free.

457.9k
Oct 25, 2026
RepositoryJavaScript
expressjs/express

Fast, unopinionated, minimalist web framework for node.

69.6k
Oct 26, 2026
RepositoryJavaScript
GitSquared/edex-ui

A cross-platform, customizable science fiction terminal emulator with advanced monitoring & touchscreen support.

45.0k
Oct 19, 2021
RepositoryJavaScript
sindresorhus/electron-store

Simple data persistence for your Electron app or module - Save and load user preferences, app state, cache, etc

5.0k
Oct 12, 2026
RepositoryJavaScript
Chalarangelo/30-seconds-of-code

Coding articles to level up your development skills

129.3k
Oct 20, 2026
RepositoryTypeScript
laurent22/joplin

Joplin - the privacy-focused note taking app with sync capabilities for Windows, macOS, Linux, Android and iOS.

56.9k
Oct 26, 2026
RepositoryTypeScript
nativefier/nativefier

Make any web page a desktop application

35.2k
Sep 29, 2023
RepositoryRust
svenstaro/miniserve

🌟 For when you really just want to serve some files over HTTP right now!

7.9k
Oct 1, 2026