[MD]
### 📖 Project Introduction
LSE TypeScript Template is a modern TypeScript development template for creating LeviLamina LSE (LiteLoaderBDS Extension). It provides a complete development toolchain, supporting the latest TypeScript syntax and ES modules, enabling you to quickly develop high-performance Minecraft server plugins.
GitHub Repository: [[URL]https://github.com/dmblpck/lse-typescript-template](https://github.com/dmblpck/lse-typescript-template)[/URL]
### ✨ Features
- 🚀 **Modern Development Experience**: TypeScript 5.9+ and ES modules
- ⚡ **Fast Building**: High-performance build tool based on Rolldown
- 🔧 **Full Type Support**: Built-in `@levimc-lse/types` type definitions
- 📦 **Auto Packaging**: Automatically packages multiple modules into a single file
- 🔄 **Hot Reload Development**: File watching and auto-rebuild in development mode
- 🎯 **Code Intelligence**: Complete IntelliSense and auto-completion support
- 📁 **Modular Structure**: Clear directory structure and module separation
### 🚀 Quick Start
#### Prerequisites
- Node.js 18+ or higher
- pnpm 10.23.0+ (recommended) or npm / yarn
- LeviLamina server environment
#### Installation
1. **Clone the repository**
```bash
git clone [URL]https://github.com/dmblpck/lse-typescript-template.git[/URL]
cd lse-typescript-template
```
2. **Install dependencies**
```bash
pnpm install
```
or using npm:
```bash
npm install
```
3. **Development mode**
```bash
pnpm dev
```
This will start the development server, watching for file changes and auto-rebuilding.
4. **Build the project**
```bash
pnpm build
```
The build output will be in `dist/bundle.js`.
### 📚 Usage Tutorial
#### Project Structure
```
lse-typescript-template/
├── src/
│ ├── index.ts # Main entry file
│ └── config.ts # Configuration file (optional)
├── dist/ # Build output directory
├── rolldown.config.ts # Build configuration
├── tsconfig.json # TypeScript configuration
├── package.json # Project dependencies and scripts
└── README.md # Project documentation
```
#### Writing Code
In `src/index.ts`, you can directly use global modules like `mc`, `ll` with full TypeScript type hints:
```typescript
// Listen to player join event
mc.listen('onJoin', (player) => {
log(`${player.name} has joined the server!`)
player.sendToast(`Welcome to the server, ${player.name}!`, 'Enjoy playing!')
})
```
#### Importing Other Modules
You can use ES module syntax to import other files:
```typescript
import { config } from './config'
// Use imported configuration
log(`Server name: ${config.serverName}`)
```
#### Configuration Details
- **TypeScript Configuration** (`tsconfig.json`): Configured for LeviLamina LSE development, targeting ES2024, using CommonJS modules
- **Build Configuration** (`rolldown.config.ts`): Uses Rolldown bundler, input is `src/index.ts`, output is `dist/bundle.js` (CommonJS format)
- **Environment Variables**: Supports `.env` files (via dotenv dependency)
#### Development Workflow
1. **Start Development**: Run `pnpm dev` to enter development mode
2. **Write Code**: Create new TypeScript files in the `src/` directory
3. **Test Code**: Copy the built `dist/bundle.js` to your LeviLamina server's plugin directory
4. **Debugging**: Check server logs to debug your plugin
5. **Build for Release**: Run `pnpm build` to generate the final version
### 📦 Available Scripts
- `pnpm dev` - Start development mode with file watching and auto-rebuild
- `pnpm build` - Build production version to `dist/bundle.js`
- `pnpm install` - Install project dependencies
### 🛠️ Development Guide
#### Adding New Dependencies
```bash
pnpm add <package-name>
```
#### Type Definitions
The project includes `@levimc-lse/types`, providing complete Minecraft server API type definitions. You can use these types directly in your code for full code intelligence.
#### Customizing Build Configuration
If you need to modify the build configuration, edit the `rolldown.config.ts` file:
```typescript
import { defineConfig } from 'rolldown'
export default defineConfig({
input: 'src/index.ts',
output: {
file: 'dist/bundle.js',
format: 'cjs',
sourcemap: true, // Enable source maps for easier debugging
},
external: ['ll', 'mc'],
platform: 'node',
tsconfig: './tsconfig.json',
})
```
#### Environment Variables Configuration
Create a `.env` file to configure environment variables:
```env
SERVER_NAME=My Minecraft Server
DEBUG_MODE=true
```
Then use in your code:
```typescript
import 'dotenv/config'
[/MD]
console.log(process.env.SERVER_NAME)
```