$ npm install @utoo/pack
🌖 High-performance bundler core for the Utoo toolchain, powered by Turbopack.
@utoo/pack is the engine behind the Utoo build system. It leverages the incremental computation power of Turbopack and the performance of Rust to provide a lightning-fast development and build experience.
webpack.config.js to simplify migration from Webpack.@utoo/pack aims for high compatibility with the Webpack ecosystem while providing superior performance.
name, import, and filename templates.loader-runner.alias and extensions.styled-jsx, styled-components).[!TIP] For a detailed status of all features, see the Features List.
ut install @utoo/pack --save-dev
You can use @utoo/pack directly in your Node.js scripts:
const { build, serve } = require('@utoo/pack');
// Production build
async function runBuild() {
await build({
config: {
entry: [
{
import: "./src/index.ts",
html: {
template: "./index.html"
}
}
],
output: {
path: "./dist",
filename: "[name].[contenthash:8].js",
chunkFilename: "[name].[contenthash:8].js",
clean: true
},
sourceMaps: true
}
});
}
// Development mode with HMR
async function startDev() {
const server = await serve({
config: {
entry: [
{
import: "./src/index.ts",
html: {
template: "./index.html"
}
}
],
output: {
path: "./dist",
filename: "[name].[contenthash:8].js",
chunkFilename: "[name].[contenthash:8].js",
clean: true
},
sourceMaps: true
}
}, undefined, undefined, { port: 3000, returnHandle: true });
return server;
}
serve() resolves after the initial build and HTTP startup. By default its result
remains void. Pass { port: 3000, returnHandle: true } as the fourth argument
to receive a handle containing
port, hostname, writeAllEntrypointsToDisk() and close(). Integrations can
await writeAllEntrypointsToDisk() before publishing build results: it checks
compilation diagnostics and regenerates HTML with the current asset paths before
resolving. Compilation and HTML generation errors reject the call. Await
close() to release the HTTP server, HMR connections and project resources.
Calling close() does not exit the process. To manage the surrounding process
yourself, pass { port: 3000, returnHandle: true, handleSignals: false } as the fourth argument.
Pass onClientBuild({ clientPaths, isRebuild }) in the fourth argument to publish
framework HTML after successful client builds. It runs after assets, enabled
stats and built-in HTML are written, even without a connected browser. The first
call has isRebuild: false and precedes onReady; subsequent calls have
isRebuild: true. Its returned promise is awaited before the next output write.
Do not call writeAllEntrypointsToDisk() or await close() inside this callback.
Startup callback failures reject serve(); background failures are logged and
later builds can retry. Failed compilations do not invoke the callback.
@utoo/pack provides a partial compatibility layer for Webpack.
const { build } = require('@utoo/pack');
const webpackConfig = require('./webpack.config.js');
async function run() {
await build({ ...webpackConfig, webpackMode: true });
}
[!NOTE] Not all Webpack features and plugins are supported. Check the Features List for details on supported configuration options.
The bundler can be configured via a utoopack.json or through the programmatic API. Key configuration areas include:
entry: Define your application entry points.define: Build-time variable replacement.externals: Exclude specific dependencies from the bundle.server.externals: Replace top-level externals for server entries and Server Functions. If
omitted, server builds continue to use top-level externals.devServer.browserToTerminal: Forward browser console output to the development terminal.
Use "error", "warn", true, or false; standalone Utoopack defaults to false.mode: development or production.For a full list of options, see the Configuration Schema.
Production client builds default to short content-hashed JS and CSS chunk names,
using Turbopack's 13-character base38 hash (for example, <hash>.js or
turbopack-<hash>.js for entry runtimes). Development builds retain readable names.
Explicit output.filename, output.chunkFilename, and output.cssFilename
templates take precedence; use filename: "[name].js" when consumers require
stable entry filenames. Static assets, copied files, server builds, and library
builds keep their existing naming rules. A deployment's complete URL also includes
its public path and any query parameters, so short chunk names alone do not
guarantee a particular URL length limit.
Set optimization.sharedRuntime: true to emit one browser runtime asset shared
across production application entries. This reduces duplicated runtime code in
multi-entry builds and lets pages reuse the cached runtime. Each entry keeps its
own small bootstrap script. The option defaults to false because separating the
runtime adds a request for a single entry; it does not apply to development,
Node.js, or library builds.
{
"mode": "production",
"optimization": {
"sharedRuntime": true
}
}
Set UTOO_ROOT_PATH to a common parent containing the project and the real paths
of linked dependencies when debugging worktrees or symlinks:
UTOO_ROOT_PATH=/path/to/common-parent utx up dev
# Relative paths resolve from the current working directory:
UTOO_ROOT_PATH=.. utx up build
Precedence is UTOO_ROOT_PATH > explicit rootPath > automatic detection. Empty
values are ignored. This applies to build, serve, and direct project creation,
where rootPath can be omitted. Updates that omit it retain the existing root.
findRootDir() and the project directory stay unchanged, preserving framework
plugin lookup and generated file locations.
# Build Rust bindings and TypeScript modules
npm run build
© 2010 - cnpmjs.org x YWFE | Home | YWFE