narraleaf
Version:
Create your visual novel with Electron and React
175 lines (136 loc) β’ 5.81 kB
Markdown
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/NarraLeaf/.github/refs/heads/master/doc/banner-md-transparent.png">
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/NarraLeaf/.github/refs/heads/master/doc/banner-md-light.png">
<img alt="narraleaf banner" src="https://raw.githubusercontent.com/NarraLeaf/.github/refs/heads/master/doc/banner-md-light.png">
</picture>
A new definition of Visual Novel Engine.
NarraLeaf is a lightweight, [React](https://react.dev/)/[Electron](https://electronjs.org/)-based visual novel engine built for speed and developer control. Build and package cross-platform VNs with minimal code and maximum flexibility.
- β‘Lighter β A zero-rendering engine with minimal overhead, optimized to run smoothly on most low-end devices.
- π§Faster - Customizable apps and built-in automation like CI and linting help you build faster with less hassle.
- π»More Developer Friendly - Standardized front-end development experience with strict typing and no language dependencies
- β€οΈTypeScript - Using TypeScript as the main language with full support for type checking and auto-completion.
```bash
$ npm install -g narraleaf
```
1. Create a new project using the CLI command `narraleaf init <PROJECT_NAME>`.
2. Navigate to the project directory: `cd <PROJECT_NAME>`.
3. Run the development server: `narraleaf dev`.
4. Wait for the miriacle to happen!
1. Navigate to the project directory: `cd <PROJECT_PATH>`.
2. Run the build command: `narraleaf build`.
3. Wait for the build process to complete.
4. Find the packaged app in the `dist` directory.
Below is an example of the `narraleaf.config.js` file. This file is used to configure the project and packaing behavior.
```javascript
const {BuildTarget, WindowsBuildTarget} = require("narraleaf");
module.exports = {
renderer: {
baseDir: "./renderer"
},
main: "./main/index.ts",
build: {
appId: "com.example.app",
targets: [
BuildTarget.Windows({
target: WindowsBuildTarget.dir,
icon: "main/assets/app-icon.ico",
})
]
},
resources: "main/assets"
};
```
```
NarraLeaf-Skeleton
βββ package-js.json
βββ narraleaf.config.js
βββ README.md
βββ .gitignore
βββ (tsconfig.json)
βββ /main/
βββ βββ /assets/
βββ β βββ app-icon.ico
β βββ index.(ts|js)
βββ /renderer/
βββ app.(tsx|jsx)
βββ /src/
β βββ story.(ts|js)
β βββ base.css
βββ /public/
β βββ placeholder.png
βββ /pages/
βββ home.(tsx|jsx)
```
By default, the main process is located in the `main` directory. The main process is responsible for managing the app lifecycle and creating the renderer process.
The main entry file is defined in the `narraleaf.config.js` file.
```typescript
module.exports = {
main: "./main/index.ts"
};
```
The renderer process is responsible for rendering the front-end of the app. The renderer process is a react app with a router. The base dir is defined in the `narraleaf.config.js` file.
```typescript
module.exports = {
renderer: {
baseDir: "./renderer",
},
};
```
The structure of the renderer directory cannot be changed. The renderer directory must contain the following files and directories:
- `app.(tsx|jsx)`: The main entry file for the renderer process. This file is used to render the app and manage the router.
- `/public/`: The public directory for the renderer process. This directory is used to store the static assets and resources. You can access these assets directly from the renderer process using relative URL. Example: `src="/images/img1.png"`.
- `/pages/`: The pages directory for the renderer process. This directory is used to store the pages of the app.
- `/pages/home.tsx`: The home page of the app. This is the default page that will be shown when the app is opened.
Below is an example of the renderer directory structure:
```
$root
βββ /renderer/
βββ app.tsx
βββ /src/
β βββ story.ts
βββ /public/
β βββ /images/
β βββ img1.png
βββ /pages/
βββ settings.tsx
βββ home.tsx
```
By default, the renderer process does not allow HTTP requests. This is to prevent security issues. If you need to allow HTTP requests, you can set the `allowHTTP` option to `true` in the `narraleaf.config.js` file.
```typescript
module.exports = {
renderer: {
baseDir: "./renderer",
allowHTTP: true,
},
};
```
The resources directory is used to store app icons and other resources. These resources are used by the main process and are not directly accessible from the renderer process.
The resources directory is defined in the `narraleaf.config.js` file.
```typescript
module.exports = {
resources: "main/assets"
};
```
You can specify a temporary directory for the build process. The default value is `./temp`. You can change this value in the `narraleaf.config.js` file.
```typescript
module.exports = {
temp: "./temp"
};
```
> **Note:** The temporary directory is used to store the build artifacts. This directory should not be used for anything else. The directory will be deleted anytime the build process is run.
Still in progress.