feat: implement iceberg development server

This commit is contained in:
2026-10-31 01:08:59 +01:00
parent 1651e4392f
commit 000baf912d
12 changed files with 347 additions and 22 deletions
+46 -1
View File
@@ -4,7 +4,7 @@ Iceberg is an early-stage, framework-independent JavaScript build tool for produ
## Current support
- `iceberg build`, `--help`, and `--version`
- `iceberg dev`, `iceberg build`, `--help`, and `--version`
- `index.html` with one local module script entry
- JavaScript, TypeScript, JSX/TSX syntax supported by Rolldown
- npm and relative ESM imports
@@ -13,6 +13,7 @@ Iceberg is an early-stage, framework-independent JavaScript build tool for produ
- hashed JavaScript, CSS, and emitted asset filenames
- minification, tree shaking, optional source maps, base paths, and a small `iceberg.config.js`
- programmatic `build()` and `defineConfig()` APIs
- development server with TypeScript transforms, public files, WebSocket reloads, and CSS hot updates
## Installation and quick start
@@ -20,12 +21,45 @@ Iceberg is an early-stage, framework-independent JavaScript build tool for produ
npm install -D @fretuks/iceberg
```
Run the locally installed CLI from PowerShell or another terminal with npm:
```bash
npm exec -- iceberg --help
npm exec -- iceberg --version
```
The bare `iceberg` command is available inside npm scripts; a local installation does not add it to your terminal's `PATH`.
```json
{ "scripts": { "build": "iceberg build" } }
```
Run `npm run build` from a project containing `index.html` and a module script such as `/src/main.js`. Iceberg writes production files to `dist/`.
## Development server
Add both scripts to a project package file:
```json
{ "scripts": { "dev": "iceberg dev", "build": "iceberg build" } }
```
Run `npm run dev` to serve the project at `http://localhost:3000/`. TypeScript and JavaScript modules are transformed on demand, CSS is processed with Lightning CSS, and npm dependencies resolve through the same Node package resolution rules used by production builds.
The server watches source files and uses a WebSocket client injected into development HTML. JavaScript and HTML changes reload the page; CSS changes replace stylesheets without a full reload. Use `iceberg dev --port 4000`, `iceberg dev --host 0.0.0.0`, or `iceberg dev --open` to override server settings. Network binding is intentionally opt-in and should only be used on trusted networks.
Configuration:
```js
import { defineConfig } from '@fretuks/iceberg';
export default defineConfig({
server: { host: 'localhost', port: 3000, strictPort: false, open: false }
});
```
Files in `public/` are served from the site root without bundling. State-preserving JavaScript HMR, framework integrations, SSR, and a preview server are not implemented yet.
## Configuration
Iceberg works without configuration. The optional `iceberg.config.js` file supports:
@@ -62,6 +96,17 @@ import { build, defineConfig } from '@fretuks/iceberg';
await build(defineConfig({ build: { outDir: 'dist', minify: true } }));
```
The development server uses the same implementation as the CLI:
```js
import { createServer } from '@fretuks/iceberg';
const server = await createServer({ server: { port: 3000 } });
await server.listen();
console.log(server.url);
// await server.close();
```
## Known limitations
Phase 1 intentionally has no development server, HMR, preview command, framework adapters, SSR, plugin API, or scaffolding. HTML currently supports one local module script entry. CSS asset URL rewriting beyond the standard relative output layout is still conservative; projects should keep CSS assets next to the stylesheet or use imported assets where possible.