Skip to Content
Docs@utoo/packConfiguration

Configuration

@utoo/pack can be configured with utoopack.json, utoopack.config.mjs, or the Node API.

Configuration Files

utoopack.json
{ "$schema": "@utoo/pack/config_schema.json", "mode": "production", "entry": [ { "import": "./src/index.ts", "html": { "template": "./index.html" } } ], "output": { "path": "./dist", "filename": "[name].[contenthash:8].js", "chunkFilename": "[name].[contenthash:8].js", "clean": true } }

Use utoopack.json when your config is fully JSON-serializable. Use utoopack.config.* when you want type inference or JS-based composition. The config-file form can also carry runtime-only UserConfig fields such as processEnv, watch, dev, buildId, tracing, projectPath, and rootPath.

Top-level Options

OptionDescription
modeBuild mode: development or production
targetTarget environment
entryEntry points, HTML generation, and library output
outputOutput path, filename templates, public path, asset copying
resolveAliases and extension resolution
defineBuild-time constant replacement
providerAuto-provide modules, similar to Webpack ProvidePlugin
externalsKeep dependencies out of the bundle
moduleCustom module rules and loaders
stylesCSS Modules, Less, Sass, PostCSS, Emotion, styled-components, styled-jsx
imagesAsset inlining behavior
reactJSX runtime and React transform options
optimizationMinification, tree shaking, split chunks, import transforms
devServerHost, port, HTTPS, HMR, proxy
sourceMapsEnable source maps
statsEmit build stats
persistentCachingReuse cache across runs
nodePolyfillPolyfill Node.js built-ins for browser builds
experimentalExperimental flags exposed by the package

Core Configuration

mode and target

Build mode affects optimizations and defaults. target selects the output runtime.

{ "mode": "production", "target": "browser" }
ValueDescription
developmentFaster builds, better debugging, HMR enabled
productionOptimized output, minification, tree shaking

entry

Define application entry points, HTML generation, and library output.

{ "entry": [ { "name": "main", "import": "./src/index.ts", "library": { "name": "MyBundle", "export": ["default"] }, "html": { "template": "./index.html", "filename": "index.html", "title": "My App", "inject": "body", "scriptLoading": "module" } } ] }

output

Configure output path, file naming, static copying, and runtime asset URLs.

{ "output": { "path": "./dist", "type": "standalone", "filename": "[name].[contenthash:8].js", "chunkFilename": "[name].[contenthash:8].js", "cssFilename": "[name].[contenthash:8].css", "cssChunkFilename": "[name].[contenthash:8].css", "assetModuleFilename": "assets/[name].[contenthash:8][ext]", "publicPath": "/", "crossOriginLoading": "anonymous", "copy": ["./public"], "chunkLoadingGlobal": "TURBOPACK", "clean": true, "entryRootExport": "AppExports" } }
OptionDescription
pathOutput directory
typeOutput type: standalone or export
filenameEntry chunk filename template
chunkFilenameNon-entry chunk filename template
cssFilenameMain CSS filename template
cssChunkFilenameCSS chunk filename template
assetModuleFilenameAsset filename template
publicPathPublic URL path for assets
crossOriginLoadingCross-origin attribute for lazy chunks
copyCopy static files into the output directory
chunkLoadingGlobalGlobal variable used by the runtime to load chunks
cleanClean output directory before build
entryRootExportExpose entry exports on window / globalThis

define

Build-time variable replacement.

{ "define": { "process.env.NODE_ENV": "\"production\"", "__VERSION__": "\"1.0.0\"" } }

provider

Automatically inject modules, similar to Webpack ProvidePlugin.

{ "provider": { "$": "jquery", "Buffer": ["buffer", "Buffer"] } }

externals

Exclude dependencies from the bundle.

{ "externals": { "react": "React", "react-dom": "ReactDOM", "lodash-es": { "root": "_", "type": "global" } } }

Externals support simple string globals, script/commonjs/esm/global forms, and more advanced subpath configuration.

resolve

Module resolution configuration.

{ "resolve": { "alias": { "@": "./src", "@components": "./src/components" }, "extensions": [".ts", ".tsx", ".js", ".jsx"] } }

module

Define loader-based module rules. Rule objects can include loaders, condition, and type.

{ "module": { "rules": { "*.md": ["raw-loader"], "*.svg": [ { "loaders": [ { "loader": "@svgr/webpack", "options": { "icon": true } } ] } ] } } }

styles

Configure built-in style processing.

{ "styles": { "autoCssModules": true, "postcss": {}, "less": { "implementation": "less" }, "sass": { "implementation": "sass" }, "inlineCss": { "injectType": "styleTag" }, "emotion": { "autoLabel": "dev-only" }, "styledComponents": { "displayName": true, "ssr": true }, "styledJsx": { "useLightningcss": true } } }

images

Configure image inlining.

{ "images": { "inlineLimit": 8192 } }

react

React transform options.

{ "react": { "runtime": "automatic", "importSource": "react", "absoluteSourceFilename": false } }

optimization

{ "optimization": { "minify": true, "treeShaking": true, "moduleIds": "deterministic", "splitChunks": { "js": { "minChunkSize": 50000, "maxChunkCountPerGroup": 40, "maxMergeChunkSize": 200000 } }, "modularizeImports": { "lodash": { "transform": "lodash/{{member}}", "preventFullImport": true } }, "packageImports": ["lodash-es"], "transpilePackages": ["shared-ui"], "removeConsole": { "exclude": ["error"] }, "concatenateModules": true, "removeUnusedExports": true, "removeUnusedImports": true } }

Common optimization fields exposed by the current package also include compress, noMangling, nestedAsyncChunking, and wasmAsAsset.

devServer

The local repo currently supports hot, host, port, https, and proxy here.

{ "devServer": { "hot": true, "host": "0.0.0.0", "port": 3000, "https": false, "proxy": [ { "context": ["/api"], "target": "http://localhost:7001", "changeOrigin": true, "pathRewrite": { "^/api": "" } } ] } }

Advanced Options

OptionTypeDescription
sourceMapsbooleanEnable source maps
statsbooleanEnable build statistics output
nodePolyfillbooleanPolyfill Node.js built-ins for browser
persistentCachingbooleanEnable persistent build cache
experimentalobjectExperimental package options

Programmatic API

const { build } = require('@utoo/pack'); await build({ config: { mode: "production", entry: [{ import: "./src/index.ts" }], output: { path: "./dist" } } });

For the full configuration schema, see config_schema.json .

Last updated on