npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@eduardoleolim/electron-esbuild

v3.0.0

Published

Use esbuild with electron

Downloads

30

Readme

Inspired by electron-esbuild of Kiyozz.

A package to build your electron app with esbuild.

✨ Features

  • Build your electron app with esbuild
  • Start a hot reload dev server for your renderer process
  • Copy static files to the output directory
  • Support to use vite for the renderer process
  • Support for preload scripts
  • Support for esbuild loaders and exclude options in each configuration
  • Support for multiple main, preload and renderer configurations.

📥 Installation

npm install @eduardoleolim/electron-esbuild --save-dev

🖥️ Usage

npx electron-esbuild <command> [options]

⌨️ Commands

🛠️ build

Builds your electron app.

Options:

  • --config or -c Config file path.
  • --vite Use vite for the renderer process. Default: false
npx electron-esbuild build [--config electron-esbuild.config.json] [--vite]

👨‍💻 dev

Builds your electron app and starts a dev server for your renderer process.

Options:

  • --config or -c Config file path.
  • --vite Use vite for the renderer process. Default: false
  • --clean Clean the output directory before building. Default: false
npx electron-esbuild dev [--config electron-esbuild.config.json] [--vite] [--clean]

⚙️ Configuration

You can configure the build with a json or yaml file in the root of your project. It looking for a config file named electron-esbuild.config.json or electron-esbuild.config.yaml.

Electron-esbuild will look for the config file in the following order:

  • The path specified in the --config option
  • The default yaml file
  • The default json file

Electron Config

The electron config has the following properties:

  • output - Optional. The output directory of your electron app, default: dist. It is relative to the root of your project
  • main - The main process config
  • preloads - Optional. A preload config can be an array of configs or a single config
  • renderers - The renderer process config can be an array of configs or a single config
  • resources - Optional. An array of files to copy to the output directory
{
  "output": "<rootProjectDir>/<outputDir>",
  "main": {
    ...
  },
  "preloads": [
    ...
  ],
  "renderers": [
    ...
  ],
  "resources": [
    ...
  ]
}

Main Config

The main config has the following properties:

  • entry - The entry file of your main process
  • args - Optional. The arguments to pass to the main process
  • output - The output configuration of bundle
    • directory - The output directory of your main process. It is relative to the output property of ElectronConfig
    • filename - The output filename of your main process
  • esbuild - Optional. Path to a javascript file exporting esbuild options
  • exclude - Optional. An array of libs that you don't want to bundle
  • loaders - Optional. An array of esbuild's loaders for specific files
{
  "entry": "<rootProjectDir>/main/file/directory",
  "args": [
    ...
  ],
  "output": {
    "directory": "<outputDir>/directory",
    "filename": "filename"
  },
  "esbuild": "<rootProjectDir>/esbuild/config/file",
  "exclude": [
    ...
  ],
  "loaders": [
    ...
  ]
}

Preload Config

The preload config is composed of the following properties:

  • entry - The entry file of your preload process
  • renderers - Optional. An array of indexes of renderer configs that will be used to reload the renderer process when the preload process is updated
  • output - The output configuration of bundle
    • directory - Optional. The output directory of your preload process. Default: same as output.directory of MainConfig
    • filename - The output filename of your preload process
  • esbuild - Optional. Path to a javascript file exporting esbuild options
  • exclude - Optional. An array of libs that you don't want to bundle
  • loaders - Optional. An array of esbuild's loaders for specific files
{
  "entry": "<rootProjectDir>/preload/file/directory",
  "renderers": [0, 1],
  "output": {
    "directory": "<outputDir>/directory",
    "filename": "filename"
  },
  "esbuild": "<rootProjectDir>/esbuild/config/file",
  "exclude": [
    ...
  ],
  "loaders": [
    ....
  ]
}

Renderer Config

The renderer config has the following properties:

  • entry - The entry file of your renderer process
  • html - The html file of your renderer process
  • devPort - Optional. The port of the dev server. If port is not available, it will try the next one
  • output - The output configuration of bundle
    • directory - Optional. The output directory of your renderer process. Default: same as output.directory of MainConfig
    • filename - The output filename of your renderer process
  • esbuild - Optional. Path to a javascript file exporting esbuild options
  • exclude - Optional. An array of libs that you don't want to bundle
  • loaders - Optional. An array of esbuild's loaders for specific files
{
  "entry": "<rootProjectDir>/renderer/file/directory",
  "html": "<rootProjectDir>/html/file/directory",
  "devPort": 8000,
  "output": {
    "directory": "<outputDir>/directory",
    "filename": "filename"
  },
  "esbuild": "<rootProjectDir>/esbuild/config/file",
  "exclude": [
    ...
  ],
  "loaders": [
    ...
  ]
}

Resources Config

The resources config could be a string or an object.

If it is a string, it will be copied to the output directory of ElectronConfig.

If it is an object, it is composed of the following properties:

  • from - The path of the file to copy
  • to - Optional. The path of the file in the output directory. Default: same as output.directory of ElectronConfig

The to property also can be and object with the following properties:

  • directory - The output directory of the file
  • filename - The output filename of the file
[
  "path/to/file",
  "path/to/directory",
  {
    "from": "path/to/file",
    "to": "<outputDir>/path/to/output/directory"
  }.
  {
    "from": "path/to/file",
    "to": {
      "directory": "<outputDir>/path/to/output/directory",
      "filename": "filename"
    }
  }
]

📄 Examples

There are some examples in the examples directory.

  • basic-js - A basic example with javascript using the basic configuration of electron-esbuild.
  • basic-ts - A basic example with typescript using the basic configuration of electron-esbuild.
  • svelte-ts - An example with svelte and typescript using the basic configuration of electron-esbuild. Also, it shows how to use an esbuild config file for the renderer process.