{"id":16579109,"url":"https://github.com/craftzdog/electron-markdown-editor-tutorial","last_synced_at":"2025-04-09T10:10:11.658Z","repository":{"id":40760841,"uuid":"395242742","full_name":"craftzdog/electron-markdown-editor-tutorial","owner":"craftzdog","description":"Electron Markdown editor tutorial","archived":false,"fork":false,"pushed_at":"2022-02-14T16:31:54.000Z","size":3851,"stargazers_count":316,"open_issues_count":0,"forks_count":58,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-02T03:47:27.041Z","etag":null,"topics":["codemirror","codemirror6","electron","markdown","remark","typescript","vite"],"latest_commit_sha":null,"homepage":"https://www.youtube.com/watch?v=gxBis8EgoAg","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/craftzdog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-12T08:05:00.000Z","updated_at":"2025-03-31T01:46:24.000Z","dependencies_parsed_at":"2022-07-13T17:20:42.610Z","dependency_job_id":null,"html_url":"https://github.com/craftzdog/electron-markdown-editor-tutorial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"cawa-93/vite-electron-builder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craftzdog%2Felectron-markdown-editor-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craftzdog%2Felectron-markdown-editor-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craftzdog%2Felectron-markdown-editor-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/craftzdog%2Felectron-markdown-editor-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/craftzdog","download_url":"https://codeload.github.com/craftzdog/electron-markdown-editor-tutorial/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248018061,"owners_count":21034048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codemirror","codemirror6","electron","markdown","remark","typescript","vite"],"created_at":"2024-10-11T22:16:58.342Z","updated_at":"2025-04-09T10:10:11.634Z","avatar_url":"https://github.com/craftzdog.png","language":"JavaScript","funding_links":["https://www.patreon.com/Kozack/"],"categories":[],"sub_categories":[],"readme":"# Markdown Editor Tutorial\n\n![screenshot](./doc/screenshot.png)\n\nA tutorial for building a beautiful Markdown editor\n\n## Sponsor\n\n[![Inkdrop](./doc/inkdrop-logo.png)](https://www.inkdrop.app/)  \nA cross-platform Markdown note-taking app\n\n## Stack\n\n- [Electron](https://www.electronjs.org/) - A framework for building cross-platform desktop apps using HTML, JS, and CSS\n- [Vite](https://vitejs.dev/) - A fast build tool\n- React - A library for building UI\n- TypeScript - A typed JavaScript\n- [CodeMirror 6](https://codemirror.net/6/) - An extensible code editor for the web\n- [Remark](https://remark.js.org/) - An extensible Markdown processor\n\n## Get started\n\n```sh\nnpm i\nnpm run watch\n```\n\n## Project Structure\n\nThe structure of this project is very similar to the structure of a monorepo.\n\nThe entire source code of the program is divided into three modules (packages) that are bundled each independently:\n- [`packages/main`](packages/main)\nElectron [**main script**](https://www.electronjs.org/docs/tutorial/quick-start#create-the-main-script-file).\n- [`packages/preload`](packages/preload)\nUsed in `BrowserWindow.webPreferences.preload`. See [Checklist: Security Recommendations](https://www.electronjs.org/docs/tutorial/security#2-do-not-enable-nodejs-integration-for-remote-content).\n- [`packages/renderer`](packages/renderer)\nElectron [**web page**](https://www.electronjs.org/docs/tutorial/quick-start#create-a-web-page).\n\n### Build web resources\n\nPackages `main` and `preload` are built in [library mode](https://vitejs.dev/guide/build.html#library-mode) as it is a simple javascript.\n`renderer` package build as regular web app.\n\nThe build of web resources is performed in the [`scripts/build.js`](scripts/build.js). Its analogue is a sequential call to `vite build` for each package.\n\n### Compile App\nNext 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. \n\nTo do this, using the [electron-builder]:\n- 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.\n- In GitHub Action: The application is compiled for any platform and ready-to-distribute files are automatically added to the draft GitHub release. \n\n\n### Using Node.js API in renderer\nAccording to [Electron's security guidelines](https://www.electronjs.org/docs/tutorial/security#2-do-not-enable-nodejs-integration-for-remote-content), 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:\n```ts\n// packages/preload/src/index.ts\nimport {readFile} from 'fs/promises'\n\nconst api = {\n  readConfig: () =\u003e  readFile('/path/to/config.json', {encoding: 'utf-8'}),\n}\n\ncontextBridge.exposeInMainWorld('electron', api)\n```\n\n```ts\n// packages/renderer/src/App.vue\nimport {useElectron} from '/@/use/electron'\n\nconst {readConfig} = useElectron()\n```\n\n[Read more about Security Considerations](https://www.electronjs.org/docs/tutorial/context-isolation#security-considerations).\n\n**Note**: Context isolation disabled for `test` environment. See [#693](https://github.com/electron-userland/spectron/issues/693#issuecomment-747872160).\n\n\n\n### Modes and Environment Variables\nAll environment variables set as part of the `import.meta`, so you can access them as follows: `import.meta.env`. \n\nYou 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.\n\nThe mode option is used to specify the value of `import.meta.env.MODE` and the corresponding environment variables files that needs to be loaded.\n\nBy default, there are two modes:\n  - `production` is used by default\n  - `development` is used by `npm run watch` script\n  - `test` is used by `npm test` script\n\nWhen running building, environment variables are loaded from the following files in your project root:\n\n```\n.env                # loaded in all cases\n.env.local          # loaded in all cases, ignored by git\n.env.[mode]         # only loaded in specified env mode\n.env.[mode].local   # only loaded in specified env mode, ignored by git\n```\n\n**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.\n\n## Author\n\nTakuya Matsuyama ([@craftzdog](https://github.com/craftzdog))\n\n\n[vite]: https://github.com/vitejs/vite/\n[electron]: https://github.com/electron/electron\n[electron-builder]: https://github.com/electron-userland/electron-builder\n[vue]: https://github.com/vuejs/vue-next\n[vue-router]: https://github.com/vuejs/vue-router-next/\n[typescript]: https://github.com/microsoft/TypeScript/\n[spectron]: https://github.com/electron-userland/spectron\n[vue-tsc]: https://github.com/johnsoncodehk/vue-tsc\n[eslint-plugin-vue]: https://github.com/vuejs/eslint-plugin-vue\n[cawa-93-github]: https://github.com/cawa-93/\n[cawa-93-sponsor]: https://www.patreon.com/Kozack/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcraftzdog%2Felectron-markdown-editor-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcraftzdog%2Felectron-markdown-editor-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcraftzdog%2Felectron-markdown-editor-tutorial/lists"}