Files
Iceberg/README.md
T

156 lines
5.9 KiB
Markdown

# Iceberg
Iceberg is an early-stage, framework-independent JavaScript build tool for production frontend builds. It uses [Rolldown](https://rolldown.rs/) for JavaScript and TypeScript bundling and [Lightning CSS](https://lightningcss.dev/) for CSS processing.
## Current support
- `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
- CSS imported from JavaScript and linked from HTML, including CSS `@import`
- common image and font asset imports
- 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
```bash
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.
## Development proxy
The development server can proxy selected HTTP and WebSocket routes to an independently running backend. Production builds do not contain this proxy; production deployments must configure their own routing.
```js
import { defineConfig } from '@fretuks/iceberg';
export default defineConfig({
server: {
proxy: {
'/api': 'http://localhost:3001',
'/socket.io': { target: 'http://localhost:3001', ws: true },
'/socket': {
target: 'http://localhost:3001',
ws: true,
changeOrigin: true
}
}
}
});
```
String shorthand is equivalent to `{ target: '...' }`. Proxy paths match complete path segments, use the longest matching prefix, preserve query strings and request/response bodies, and stream HTTP and WebSocket traffic. `changeOrigin` changes the outgoing host/origin behavior; HTTPS certificate verification is enabled by default and can be disabled for one trusted local target with `secure: false`.
To rewrite a path while preserving its query string:
```js
proxy: {
'/api': {
target: 'http://localhost:3001',
rewrite: path => path.replace(/^\/api(?=\/|$)/, '') || '/'
}
}
```
Proxy failures return `502 Bad Gateway` (or `504 Gateway Timeout`) as JSON and are logged without stopping Iceberg. `/__iceberg_ws` is reserved for Iceberg's own live-reload connection and cannot be configured as a proxy route. Exposing the dev server with `--host 0.0.0.0` also exposes configured proxy routes, so only do this on a trusted network.
The complete frontend/backend example is in `examples/proxy`. Install dependencies in both `examples/proxy/frontend` and `examples/proxy/backend`, start the backend with `npm start`, then run `npm run dev` in the frontend directory.
## Configuration
Iceberg works without configuration. The optional `iceberg.config.js` file supports:
```js
import { defineConfig } from '@fretuks/iceberg';
export default defineConfig({
root: process.cwd(),
base: '/site/',
build: { outDir: 'build', minify: true, sourcemap: false, emptyOutDir: true }
});
```
## Frost CSS
Frost is supported through its normal npm export; Iceberg contains no Frost-specific logic:
```bash
npm install @fretuks/frost
```
```js
import '@fretuks/frost';
```
The inspected Frost package is `@fretuks/frost@0.3.0`. Its `.` and `./frost.css` exports point to precompiled `frost.css`, which imports the other CSS modules through ordinary CSS imports. The working example is in `examples/frost`.
## Programmatic API
```js
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.
## License
MIT. Iceberg is in early development; APIs may evolve before the 1.0 release.