Quick Start
Utoopack currently supports multiple usage modes:
- Standalone CLI mode
- Webpack compatibility mode for Webpack projects
- Direct usage in Ant open source frameworks such as
umi,dumi, andfather
Standalone Usage
mkdir utoo-demo && cd utoo-demo
ut init@utoo/pack provides a standalone build CLI:
ut i @utoo/pack @utoo/pack-cli react react-dom -S
ut i @types/react @types/react-dom -DCreate a utoopack build configuration file named utoopack.config.mjs in your project:
import { defineConfig } from '@utoo/pack';
export default defineConfig({
entry: [{
import: './src/index.tsx',
html: { template: 'index.html' }
}]
})Create the template HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Utoopack Example</title>
</head>
<body>
<div id="root"></div>
</body>
</html>Then create a src/index.tsx file:
import ReactDOM from "react-dom/client";
ReactDOM.createRoot(document.getElementById("root")!).render(
<div>Hello, Utoo</div>,
);Webpack Compatibility Mode
@utoo/pack currently provides a mode for migrating existing Webpack projects directly. You can move an existing Webpack project to utoopack with a simple setup:
Install the related @utoo/pack dependencies:
ut i @utoo/pack @utoo/pack-cli -SUpdate the dev and build scripts:
{
"scripts": {
"build": "up build --webpack",
"dev": "up dev --webpack"
}
}@utoo/pack automatically reads the local Webpack build configuration file webpack.config.js and converts it into utoopack build configuration.
Node API Usage
@utoo/pack also provides a standalone Node API. Use it as follows:
Production Build
const { build } = require('@utoo/pack');
async function runBuild() {
await build({
config: {
entry: [
{
import: "./src/index.ts",
html: {
template: "./index.html"
}
}
],
output: {
clean: true
},
sourceMaps: true
}
});
}
runBuild();Usage in More Frameworks
Utoopack is already integrated into multiple Ant open source frameworks and can be enabled directly in each framework:
- umi: https://umijs.org/docs/api/config#utoopack
- dumi: https://d.umijs.org/config#utoopack
- father: https://github.com/umijs/father/blob/master/docs/config.md#bundler
The Ant Design Pro v6 template project also uses utoopack as its default bundler. See: https://github.com/ant-design/ant-design-pro