Skip to Content
Docs@utoo/packConfiguration

Configuration

@utoo/pack can be configured via utoopack.json, utoopack.config.mjs, or through the programmatic 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 }, "sourceMaps": true }

Core Options

mode

Build mode, affects optimizations and defaults.

ValueDescription
developmentFaster builds, better debugging, HMR enabled
productionOptimized output, minification, tree shaking

entry

Define application entry points.

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

output

Configure output settings.

{ "output": { "path": "./dist", "filename": "[name].[contenthash:8].js", "chunkFilename": "[name].[contenthash:8].js", "publicPath": "/", "clean": true, "copy": ["public"], "type": "standalone", "chunkLoadingGlobal": "TURBOPACK", "entryRootExport": "MyApp" } }
OptionDescription
pathOutput directory
filenameEntry chunk filename template
chunkFilenameNon-entry chunk filename template
cssFilenameCSS filename template
cssChunkFilenameNon-entry CSS chunk filename template
assetModuleFilenameAsset module filename template
publicPathPublic URL path for assets
cleanClean output directory before build
copyCopy static files (string paths or { from, to } objects)
typeOutput type: standalone or export
chunkLoadingGlobalGlobal variable name for loading chunks
entryRootExportExpose entry exports to global scope

target

Target environment string (e.g., "web", "node").

define

Build-time variable replacement.

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

externals

Exclude dependencies from the bundle.

{ "externals": { "react": "React", "react-dom": "ReactDOM" } }

Externals support simple string globals, UMD configuration, and advanced subpath configuration.

resolve

Module resolution configuration.

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

module

Module rules and conditions for custom loaders.

{ "module": { "rules": { "*.svg": "svgr-loader", "*.mdx": [ { "loader": "mdx-loader", "options": {} } ] }, "conditions": { "*.js": { "path": { "type": "glob", "value": "**/node_modules/**" } } } } }
OptionDescription
rulesMap glob patterns to loaders
conditionsConfigure loader conditions by path (glob or regex)

provider

Auto-provide modules (similar to webpack ProvidePlugin).

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

Optimization

{ "optimization": { "minify": true, "treeShaking": true, "concatenateModules": true, "moduleIds": "deterministic", "removeConsole": true, "removeUnusedExports": true, "removeUnusedImports": true, "splitChunks": { "js": { "minChunkSize": 50000, "maxChunkCountPerGroup": 40, "maxMergeChunkSize": 200000 } }, "modularizeImports": { "lodash": { "transform": "lodash/{{member}}", "preventFullImport": true } }, "packageImports": ["antd", "lodash-es"], "transpilePackages": ["my-local-package"], "nestedAsyncChunking": true, "wasmAsAsset": false } }
OptionDescription
minifyEnable code minification
treeShakingRemove unused code
concatenateModulesModule concatenation (scope hoisting)
moduleIdsID strategy: named or deterministic
noManglingDisable name mangling
removeConsoleRemove console statements (true or { exclude: ["error"] })
removeUnusedExportsRemove unused exports
removeUnusedImportsRemove unused imports
splitChunksChunk splitting configuration
modularizeImportsTransform barrel imports (like babel-plugin-import)
packageImportsPackages to optimize imports for
transpilePackagesTranspile specific packages
nestedAsyncChunkingEnable nested async chunking
wasmAsAssetBundle WASM as asset

Styles

{ "styles": { "autoCssModules": true, "emotion": true, "styledComponents": true, "styledJsx": true, "less": { "implementation": "less" }, "sass": { "implementation": "sass" }, "inlineCss": { "injectType": "styleTag" } } }
OptionDescription
autoCssModulesAuto-detect and apply CSS Modules
emotionEnable @emotion/react transform
styledComponentsEnable styled-components transform (true or config object )
styledJsxEnable styled-jsx transform (true or { useLightningcss: true })
lessLess preprocessor config (implementation, plus Less options)
sassSass/SCSS preprocessor config (implementation, plus Sass options)
inlineCssCSS injection via style tags (insert, injectType)

Images

{ "images": { "inlineLimit": 10000 } }
OptionDescription
inlineLimitInline images smaller than this size (bytes) as base64

Development Server

{ "devServer": { "hot": true, "port": 3000, "host": "localhost", "https": false } }
OptionDescription
hotEnable Hot Module Replacement
portPort to listen on
hostHost to bind
httpsUse HTTPS

React

{ "react": { "runtime": "automatic", "importSource": "react" } }
OptionDescription
runtimeJSX runtime: automatic or classic
importSourceSource for JSX imports (default: react)

Advanced Options

OptionTypeDescription
sourceMapsbooleanEnable source maps
statsbooleanEnable build statistics output
nodePolyfillbooleanPolyfill Node.js built-ins for browser
persistentCachingbooleanEnable persistent build cache
pluginRuntimeStrategystringPlugin execution: workerThreads or childProcesses

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