Configuration
@utoo/pack can be configured via utoopack.json file or through the programmatic API.
Configuration File
Create a utoopack.json in your project root:
utoopack.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.
{
"mode": "production" // or "development"
}| Value | Description |
|---|---|
development | Faster builds, better debugging, HMR enabled |
production | Optimized output, minification, tree shaking |
entry
Define application entry points.
{
"entry": [
{
"name": "main",
"import": "./src/index.ts",
"html": {
"template": "./index.html",
"filename": "index.html"
}
}
]
}output
Configure output settings.
{
"output": {
"path": "./dist",
"filename": "[name].[contenthash:8].js",
"chunkFilename": "[name].[contenthash:8].js",
"publicPath": "/",
"clean": true
}
}| Option | Description |
|---|---|
path | Output directory |
filename | Entry chunk filename template |
chunkFilename | Non-entry chunk filename template |
publicPath | Public URL path for assets |
clean | Clean output directory before build |
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"
}
}resolve
Module resolution configuration.
{
"resolve": {
"alias": {
"@": "./src",
"@components": "./src/components"
},
"extensions": [".ts", ".tsx", ".js", ".jsx"]
}
}Programmatic API
build()
const { build } = require('@utoo/pack');
await build({
mode: "production",
entry: [{ import: "./src/index.ts" }],
output: { path: "./dist" }
});For the full configuration schema, see config_schema.json .
Last updated on