• Stars
    star
    298
  • Rank 139,311 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 3 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Electron Markdown editor tutorial

Markdown Editor Tutorial

screenshot

A tutorial for building a beautiful Markdown editor

Sponsor

Inkdrop
A cross-platform Markdown note-taking app

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

Get started

npm i
npm run watch

Project Structure

The structure of this project is very similar to the structure of a monorepo.

The entire source code of the program is divided into three modules (packages) that are bundled each independently:

Build web resources

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

The build of web resources is performed in the scripts/build.js. Its analogue is a sequential call to vite build for each package.

Compile App

Next step is run packaging and compilation a ready for distribution Electron app for macOS, Windows and Linux with "auto update" support out of the box.

To do this, using the electron-builder:

  • In npm script compile: This script is configured to compile the application as quickly as possible. It is not ready for distribution, is compiled only for the current platform and is used for debugging.
  • In GitHub Action: The application is compiled for any platform and ready-to-distribute files are automatically added to the draft GitHub release.

Using Node.js API in renderer

According to Electron's security guidelines, Node.js integration is disabled for remote content. This means that you cannot call any Node.js api in the packages/renderer directly. To do this, you must describe the interface in the packages/preload where Node.js api is allowed:

// packages/preload/src/index.ts
import {readFile} from 'fs/promises'

const api = {
  readConfig: () =>  readFile('/path/to/config.json', {encoding: 'utf-8'}),
}

contextBridge.exposeInMainWorld('electron', api)
// packages/renderer/src/App.vue
import {useElectron} from '/@/use/electron'

const {readConfig} = useElectron()

Read more about Security Considerations.

Note: Context isolation disabled for test environment. See #693.

Modes and Environment Variables

All environment variables set as part of the import.meta, so you can access them as follows: import.meta.env.

You can also build type definitions of your variables by running scripts/buildEnvTypes.js. This command will create types/env.d.ts file with describing all environment variables for all modes.

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

By default, there are two modes:

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

When running building, 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

Note: only variables prefixed with VITE_ are exposed to your code (e.g. VITE_SOME_KEY=123) and SOME_KEY=123 will not. you can access VITE_SOME_KEY using import.meta.env.VITE_SOME_KEY. This is because the .env files may be used by some users for server-side or build scripts and may contain sensitive information that should not be exposed in code shipped to browsers.

Author

Takuya Matsuyama (@craftzdog)

More Repositories

1

dotfiles-public

My personal dotfiles
Lua
6,132
star
2

craftzdog-homepage

My homepage
JavaScript
2,257
star
3

chat-bubbles-for-yt

Real-time recording for chat bubbles
TypeScript
658
star
4

solarized-osaka.nvim

🏯 A clean, dark Neovim theme written in Lua, with support for lsp, treesitter and lots of plugins.
Lua
595
star
5

react-native-animated-todo

Animated ToDo app built with React Native and Reanimated v2
TypeScript
444
star
6

react-native-sqlite-2

SQLite3 Native Plugin for React Native for iOS, Android, Windows and macOS.
TypeScript
376
star
7

react-native-quick-base64

A fast base64 module for React Native
TypeScript
354
star
8

craftzdog-uses

A curated list of the tech I use, built with Astro and Tailwind CSS
Astro
251
star
9

react-native-aes-gcm-crypto

AES-GCM encryption/decryption for React Native
Java
242
star
10

inkdrop-ui-mockup-react-native

A mockup for Inkdrop mobile inspired by Gmail
TypeScript
236
star
11

react-native-checkbox-reanimated

Animated checkbox built with Reanimated v2
TypeScript
165
star
12

link-in-bio

Link in bio page for my Instagram profile
HTML
165
star
13

ghibli-style-shader

Ghibli-styled Shader Example for Three.js
JavaScript
150
star
14

vlog-translator

A Personal Tool for Transcribing & Translating My Vlogs into Japanese
TypeScript
144
star
15

pouchdb-adapter-react-native-sqlite

PouchDB adapter using ReactNative SQLite as its backing store
JavaScript
116
star
16

react-native-quick-md5

Fast C++ implementation with JSI binding of MD5 for React Native
C++
106
star
17

caffe-ios-sample

An example of XCode project using Caffe: a fast open framework for deep learning
Objective-C++
98
star
18

ZenPlayer-for-iOS

ZenPlayer written with objective-c
Objective-C
91
star
19

hyper-holoplay

Holoplay integration for Hyper
JavaScript
82
star
20

cm6-themes

Themes for CodeMirror 6
TypeScript
80
star
21

voxel-dog

A cute 3D dog rendered with three.js
TypeScript
71
star
22

send-email-lambda

Simple email sender running on Lambda
JavaScript
69
star
23

react-native-three-column-layout

Three-column layout with animation support for tablet displays
TypeScript
48
star
24

react-native-quick-websql

Fast WebSQL-compatible SQLite driver for React Native
TypeScript
44
star
25

NRBlurryStepOutAnimatedTransitioning

tweetbot like modal view transitioning
Objective-C
42
star
26

react-native-skeuomorphism-ui-example

Neo-skeuomorphism style UI Example for React Native
JavaScript
38
star
27

p5-wave-visualization

p5 sketch visualizing the sound of waves of the sea recorded at Yuigahama in Kamakura, which is processed with FFT.
JavaScript
36
star
28

react-native-japanese-tokenizer

Async Japanese Tokenizer Native Plugin for React Native for iOS and Android
Java
34
star
29

smooth-toc-example

A demo project of a smoothly animated table of contents
CSS
30
star
30

react-codemirror-runmode

Syntax highlighting for react, utilizing CodeMirror's parser
TypeScript
27
star
31

presentation-themes

Presentation themes based on popular syntax themes
19
star
32

gatsby-starter-ionic

A Gatsby starter with Ionic added on top
CSS
17
star
33

atom-react-app

An empty React app based on Atom Editor
JavaScript
16
star
34

pouchdb-react-native-demo

A working demo for PouchDB on React Native with SQLite3 storage
JavaScript
15
star
35

extract-main-text-node

ExtractContent for node.js
JavaScript
15
star
36

react-native-native-ui-component-boilerplate

My boilerplate for building a native UI component for React Native
Java
13
star
37

remark-react-codemirror

Syntax highlighting for remark-react through CodeMirror
JavaScript
11
star
38

remark-strip-html

Remove html formatting from Markdown
JavaScript
11
star
39

anavi-phat-sensors-ui

Web interface for ANAVI pHAT & CO2 sensors
CSS
10
star
40

react-native-sqlite-2-demo

React Native SQLite 2 Demo
JavaScript
5
star
41

anavi-sensors-api

An API server to retrieve ANAVI sensor data from my Raspberry Pi
JavaScript
4
star
42

rn-tamagui-web-test

TypeScript
4
star
43

lunr-language-jp

A Japanese tokenizer and stopwords for Lunr JavaScript library
JavaScript
3
star
44

frosted-top-bar-example

an example of iOS like frosted blurry-styled top-bar on the web
HTML
3
star
45

raspcon

A remote controller server for my room 🕹
JavaScript
2
star
46

twit-promise

A wrapper for the Twit module that its get/post methods return the native promise
JavaScript
2
star
47

NRJSONHelpers

Handy categories for encoding/decoding JSON in Objective-C
Objective-C
1
star
48

codemirror.next-markdown

Markdown test
1
star
49

electron-acrylic-window-drag-issue-reproduction

JavaScript
1
star
50

react-native-pouchdb-md5

PouchDB utilities for calculating MD5 checksums for React Native
Java
1
star