Skip to content

xenongospel/example-electron-markdown-editor

 
 

Repository files navigation

Electron Markdown Editor - example

Desktop app Screenshot 2022-10-08 at 15 22 27 App Screenshot Screenshot 2022-10-08 at 09 12 14 Codebase Screenshot 2022-10-08 at 09 03 33

Tech Stack

  • Electron: A framework for building cross-platform desktop apps using HTML, JS, and CSS
  • Vite: A fast build tool
  • React: A library for building UI
  • TypeScript: A typed JavaScript
  • CodeMirror 6: An extensible code editor for the web
  • Remark: An extensible Markdown processor
  • React-Markdown: React component to render markdown.
  • react-syntax-highlighter: Syntax highlighting component for react with prismjs or highlightjs using inline styles

Get started

npm i 
npm run watch

How it works

Project Structure

The structure of this template is very similar to the structure of a monorepo.
packages/main: Electron main script.
packages/preload: Used in BrowserWindow.webPreferences.preload.
packages/renderer: Electron web page.

Build web resources

The main and preload packages are built in library mode as it is simple javascript. The renderer package builds as a regular web app.

Compile App

The next step is to package a ready to distribute Electron app for macOS, Windows and Linux with "auto update" support out of the box.

  • Using the npm script compile: This script is configured to compile the application as quickly as possible. It is not ready for distribution, it is compiled only for the current platform and is used for debugging.
  • Using GitHub Actions: The application is compiled for any platform and ready-to-distribute files are automatically added as a draft to the GitHub releases page.
npm run compile
# for mac user:
open dist/mac/your-app-name.app

Modes and Environment Variables

All environment variables are set as part of the import.meta, so you can access them vie the following way: import.meta.env.

If you are using TypeScript and want to get code completion you must add all the environment variables to the ImportMetaEnv in types/env.d.ts.

The mode option is used to specify the value of import.meta.env.MODE and the corresponding environment variables files that need to be loaded.

By default, there are two modes:

  • production is used by default
  • development is used by npm run watch script

When running the build script, the environment variables are loaded from the following files in your project root:

.env                # loaded in all cases
.env.local          # loaded in all cases, ignored by git
.env.[mode]         # only loaded in specified env mode
.env.[mode].local   # only loaded in specified env mode, ignored by git

To prevent accidentally leaking env variables to the client, only variables prefixed with VITE_ are exposed to your Vite-processed code.

For example let's take the following .env file:

DB_PASSWORD=foobar
VITE_SOME_KEY=123

Only VITE_SOME_KEY will be exposed as import.meta.env.VITE_SOME_KEY to your client source code, but DB_PASSWORD will not.

Relevant articles

About me

About

Built with Electron, Typescript, React, Vite, and Remark.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 72.7%
  • JavaScript 21.0%
  • CSS 4.9%
  • HTML 1.4%