JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 19610
  • Score
    100M100P100Q132503F
  • License MIT

Static file serving for Electron apps

Package Exports

  • electron-serve

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (electron-serve) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

electron-serve Build Status

Static file serving for Electron apps

Normally you would just use win.loadURL('file://…'), but that doesn't work when you're making a single-page web app, which most Electron apps are today, as history.pushState()'ed URLs don't exist on disk. It serves files if they exist, and falls back to index.html if not, which means you can use router modules like react-router, vue-router, etc.

Install

$ npm install electron-serve

Usage

const {app, BrowserWindow} = require('electron');
const serve = require('electron-serve');

const loadURL = serve({directory: 'renderer'});

app.on('ready', () => {
    mainWindow = new BrowserWindow();

    loadURL(mainWindow);

    // The above is equivalent to this:
    mainWindow.loadURL('app://-');
    // The `-` is just the required hostname
});

API

serve(options)

directory

Required
Type: string

The directory to serve, relative to the app root directory.

scheme

Type: string
Default: app

Custom scheme. For example, foo results in your directory being available at foo://-.

License

MIT © Sindre Sorhus