@utoo/pack 1.1.1 → 1.1.2-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +126 -0
- package/cjs/types.d.ts +16 -0
- package/cjs/webpackCompat.js +26 -0
- package/esm/types.d.ts +16 -0
- package/esm/webpackCompat.js +26 -0
- package/package.json +14 -11
package/README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# @utoo/pack
|
|
2
|
+
|
|
3
|
+
> 🌖 High-performance bundler core for the Utoo toolchain, powered by [Turbopack](https://turbo.build/pack).
|
|
4
|
+
|
|
5
|
+
`@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.
|
|
6
|
+
|
|
7
|
+
## ✨ Key Features
|
|
8
|
+
|
|
9
|
+
- ⚡ **Extreme Performance**: Core bundling logic implemented in Rust via NAPI-RS.
|
|
10
|
+
- 🛠️ **Turbopack Powered**: Built on top of the same engine that powers Next.js Turbopack.
|
|
11
|
+
- 🔌 **Webpack Compatibility**: Support for consuming `webpack.config.js` to simplify migration from Webpack.
|
|
12
|
+
- 📦 **Modern Web Support**: Native support for TypeScript, JSX, CSS Modules, Less, Sass, and more.
|
|
13
|
+
- 🔧 **Extensible Architecture**: Support for custom loaders, plugins, and flexible configuration.
|
|
14
|
+
- 🔄 **Fast HMR**: Instant updates during development with optimized Hot Module Replacement.
|
|
15
|
+
|
|
16
|
+
## ✨ Supported Features
|
|
17
|
+
|
|
18
|
+
`@utoo/pack` aims for high compatibility with the Webpack ecosystem while providing superior performance.
|
|
19
|
+
|
|
20
|
+
- **Entry**: Supports `name`, `import`, and `filename` templates.
|
|
21
|
+
- **Module Rules**: Support for most mainstream Webpack loaders via `loader-runner`.
|
|
22
|
+
- **Resolve**: Full support for `alias` and `extensions`.
|
|
23
|
+
- **Styles**: Built-in support for Less, Sass, PostCSS, CSS Modules, and LightningCSS.
|
|
24
|
+
- **Optimization**: Minification, Tree Shaking, Module Concatenation, and more.
|
|
25
|
+
- **Frameworks**: Optimized for React (including `styled-jsx`, `emotion`, `styled-components`).
|
|
26
|
+
- **Tools**: Integrated Bundle Analyzer and Tracing Logs.
|
|
27
|
+
|
|
28
|
+
> [!TIP]
|
|
29
|
+
> For a detailed status of all features, see the [Features List](./docs/features-list.md).
|
|
30
|
+
|
|
31
|
+
## 📦 Installation
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install @utoo/pack
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 🚀 Quick Start
|
|
38
|
+
|
|
39
|
+
### Programmatic API
|
|
40
|
+
|
|
41
|
+
You can use `@utoo/pack` directly in your Node.js scripts:
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
const { build, dev } = require('@utoo/pack');
|
|
45
|
+
|
|
46
|
+
// Production build
|
|
47
|
+
async function runBuild() {
|
|
48
|
+
await build({
|
|
49
|
+
root: process.cwd(),
|
|
50
|
+
config: {
|
|
51
|
+
entry: [
|
|
52
|
+
{
|
|
53
|
+
key: 'main',
|
|
54
|
+
value: './src/index.ts'
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
mode: 'production'
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Development mode with HMR
|
|
63
|
+
async function startDev() {
|
|
64
|
+
const server = await dev({
|
|
65
|
+
root: process.cwd(),
|
|
66
|
+
config: {
|
|
67
|
+
mode: 'development'
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 🔌 Webpack Compatibility Mode
|
|
74
|
+
|
|
75
|
+
`@utoo/pack` provides a partial compatibility layer for Webpack. This allows you to use your existing `webpack.config.js` with minimal changes.
|
|
76
|
+
|
|
77
|
+
### Usage via CLI
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
utoo-pack build --webpack
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Programmatic Usage
|
|
84
|
+
|
|
85
|
+
```javascript
|
|
86
|
+
const { build } = require('@utoo/pack');
|
|
87
|
+
const { compatOptionsFromWebpack } = require('@utoo/pack/webpack-compat');
|
|
88
|
+
const webpackConfig = require('./webpack.config.js');
|
|
89
|
+
|
|
90
|
+
async function run() {
|
|
91
|
+
const options = compatOptionsFromWebpack(webpackConfig);
|
|
92
|
+
await build(options);
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
> [!NOTE]
|
|
97
|
+
> Not all Webpack features and plugins are supported. Check the [Features List](./docs/features-list.md) for details on supported configuration options.
|
|
98
|
+
|
|
99
|
+
## ⚙️ Configuration
|
|
100
|
+
|
|
101
|
+
The bundler can be configured via a `project_options.json` or through the programmatic API. Key configuration areas include:
|
|
102
|
+
|
|
103
|
+
- **`entry`**: Define your application entry points.
|
|
104
|
+
- **`define`**: Build-time variable replacement.
|
|
105
|
+
- **`externals`**: Exclude specific dependencies from the bundle.
|
|
106
|
+
- **`mode`**: `development` or `production`.
|
|
107
|
+
|
|
108
|
+
For a full list of options, see the [Configuration Schema](./config_schema.json).
|
|
109
|
+
|
|
110
|
+
## 🛠️ Development
|
|
111
|
+
|
|
112
|
+
### Prerequisites
|
|
113
|
+
|
|
114
|
+
- **Rust**: Nightly toolchain (see [rust-toolchain.toml](../../rust-toolchain.toml)).
|
|
115
|
+
- **Node.js**: Version 20 or higher.
|
|
116
|
+
|
|
117
|
+
### Building from Source
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
# Build Rust bindings and TypeScript modules
|
|
121
|
+
npm run build
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## 📄 License
|
|
125
|
+
|
|
126
|
+
[MIT](./LICENSE)
|
package/cjs/types.d.ts
CHANGED
|
@@ -98,6 +98,21 @@ export interface ExternalAdvanced {
|
|
|
98
98
|
script?: string;
|
|
99
99
|
}
|
|
100
100
|
export type ExternalConfig = string | ExternalAdvanced;
|
|
101
|
+
/**
|
|
102
|
+
* Provider configuration for automatic module imports.
|
|
103
|
+
* Similar to webpack's ProvidePlugin.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* provider: {
|
|
108
|
+
* // Provides `$` as `import $ from 'jquery'`
|
|
109
|
+
* $: 'jquery',
|
|
110
|
+
* // Provides `Buffer` as `import { Buffer } from 'buffer'`
|
|
111
|
+
* Buffer: ['buffer', 'Buffer'],
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export type ProviderConfig = Record<string, string | [string, string]>;
|
|
101
116
|
export interface ConfigComplete {
|
|
102
117
|
entry: EntryOptions[];
|
|
103
118
|
mode?: "production" | "development";
|
|
@@ -119,6 +134,7 @@ export interface ConfigComplete {
|
|
|
119
134
|
target?: string;
|
|
120
135
|
sourceMaps?: boolean;
|
|
121
136
|
define?: Record<string, string>;
|
|
137
|
+
provider?: ProviderConfig;
|
|
122
138
|
optimization?: {
|
|
123
139
|
moduleIds?: "named" | "deterministic";
|
|
124
140
|
minify?: boolean;
|
package/cjs/webpackCompat.js
CHANGED
|
@@ -29,6 +29,7 @@ function compatOptionsFromWebpack(webpackConfig, projectPath, rootPath) {
|
|
|
29
29
|
sourceMaps: compatSourceMaps(devtool),
|
|
30
30
|
optimization: compatOptimization(optimization),
|
|
31
31
|
define: compatFromWebpackPlugin(plugins, compatDefine),
|
|
32
|
+
provider: compatFromWebpackPlugin(plugins, compatProvider),
|
|
32
33
|
stats: compatStats(stats),
|
|
33
34
|
},
|
|
34
35
|
buildId: webpackConfig.name,
|
|
@@ -129,6 +130,31 @@ function compatDefine(maybeWebpackPluginInstance) {
|
|
|
129
130
|
}
|
|
130
131
|
return processedDefinitions;
|
|
131
132
|
}
|
|
133
|
+
compatProvider.pluginName = "ProvidePlugin";
|
|
134
|
+
function compatProvider(maybeWebpackPluginInstance) {
|
|
135
|
+
const definitions = maybeWebpackPluginInstance === null || maybeWebpackPluginInstance === void 0 ? void 0 : maybeWebpackPluginInstance.definitions;
|
|
136
|
+
if (!definitions || typeof definitions !== "object") {
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
139
|
+
const provider = {};
|
|
140
|
+
for (const [key, value] of Object.entries(definitions)) {
|
|
141
|
+
if (typeof value === "string") {
|
|
142
|
+
// Simple module import: { $: 'jquery' }
|
|
143
|
+
provider[key] = value;
|
|
144
|
+
}
|
|
145
|
+
else if (Array.isArray(value)) {
|
|
146
|
+
if (value.length === 1) {
|
|
147
|
+
// e.g. { process: ['process/browser'] } for default import
|
|
148
|
+
provider[key] = value[0];
|
|
149
|
+
}
|
|
150
|
+
else if (value.length >= 2) {
|
|
151
|
+
// Named export import: { Buffer: ['buffer', 'Buffer'] }
|
|
152
|
+
provider[key] = [value[0], value[1]];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return Object.keys(provider).length > 0 ? provider : undefined;
|
|
157
|
+
}
|
|
132
158
|
function compatExternals(webpackExternals) {
|
|
133
159
|
if (!webpackExternals) {
|
|
134
160
|
return undefined;
|
package/esm/types.d.ts
CHANGED
|
@@ -98,6 +98,21 @@ export interface ExternalAdvanced {
|
|
|
98
98
|
script?: string;
|
|
99
99
|
}
|
|
100
100
|
export type ExternalConfig = string | ExternalAdvanced;
|
|
101
|
+
/**
|
|
102
|
+
* Provider configuration for automatic module imports.
|
|
103
|
+
* Similar to webpack's ProvidePlugin.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* provider: {
|
|
108
|
+
* // Provides `$` as `import $ from 'jquery'`
|
|
109
|
+
* $: 'jquery',
|
|
110
|
+
* // Provides `Buffer` as `import { Buffer } from 'buffer'`
|
|
111
|
+
* Buffer: ['buffer', 'Buffer'],
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export type ProviderConfig = Record<string, string | [string, string]>;
|
|
101
116
|
export interface ConfigComplete {
|
|
102
117
|
entry: EntryOptions[];
|
|
103
118
|
mode?: "production" | "development";
|
|
@@ -119,6 +134,7 @@ export interface ConfigComplete {
|
|
|
119
134
|
target?: string;
|
|
120
135
|
sourceMaps?: boolean;
|
|
121
136
|
define?: Record<string, string>;
|
|
137
|
+
provider?: ProviderConfig;
|
|
122
138
|
optimization?: {
|
|
123
139
|
moduleIds?: "named" | "deterministic";
|
|
124
140
|
minify?: boolean;
|
package/esm/webpackCompat.js
CHANGED
|
@@ -22,6 +22,7 @@ export function compatOptionsFromWebpack(webpackConfig, projectPath, rootPath) {
|
|
|
22
22
|
sourceMaps: compatSourceMaps(devtool),
|
|
23
23
|
optimization: compatOptimization(optimization),
|
|
24
24
|
define: compatFromWebpackPlugin(plugins, compatDefine),
|
|
25
|
+
provider: compatFromWebpackPlugin(plugins, compatProvider),
|
|
25
26
|
stats: compatStats(stats),
|
|
26
27
|
},
|
|
27
28
|
buildId: webpackConfig.name,
|
|
@@ -122,6 +123,31 @@ function compatDefine(maybeWebpackPluginInstance) {
|
|
|
122
123
|
}
|
|
123
124
|
return processedDefinitions;
|
|
124
125
|
}
|
|
126
|
+
compatProvider.pluginName = "ProvidePlugin";
|
|
127
|
+
function compatProvider(maybeWebpackPluginInstance) {
|
|
128
|
+
const definitions = maybeWebpackPluginInstance === null || maybeWebpackPluginInstance === void 0 ? void 0 : maybeWebpackPluginInstance.definitions;
|
|
129
|
+
if (!definitions || typeof definitions !== "object") {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
const provider = {};
|
|
133
|
+
for (const [key, value] of Object.entries(definitions)) {
|
|
134
|
+
if (typeof value === "string") {
|
|
135
|
+
// Simple module import: { $: 'jquery' }
|
|
136
|
+
provider[key] = value;
|
|
137
|
+
}
|
|
138
|
+
else if (Array.isArray(value)) {
|
|
139
|
+
if (value.length === 1) {
|
|
140
|
+
// e.g. { process: ['process/browser'] } for default import
|
|
141
|
+
provider[key] = value[0];
|
|
142
|
+
}
|
|
143
|
+
else if (value.length >= 2) {
|
|
144
|
+
// Named export import: { Buffer: ['buffer', 'Buffer'] }
|
|
145
|
+
provider[key] = [value[0], value[1]];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return Object.keys(provider).length > 0 ? provider : undefined;
|
|
150
|
+
}
|
|
125
151
|
function compatExternals(webpackExternals) {
|
|
126
152
|
if (!webpackExternals) {
|
|
127
153
|
return undefined;
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@utoo/pack",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2-alpha.2",
|
|
4
4
|
"main": "cjs/index.js",
|
|
5
5
|
"module": "esm/index.js",
|
|
6
|
+
"types": "esm/index.d.ts",
|
|
6
7
|
"exports": {
|
|
7
8
|
".": {
|
|
9
|
+
"types": "./esm/index.d.ts",
|
|
8
10
|
"import": "./esm/index.js",
|
|
9
11
|
"require": "./cjs/index.js"
|
|
10
12
|
},
|
|
@@ -72,25 +74,26 @@
|
|
|
72
74
|
"node": ">= 20"
|
|
73
75
|
},
|
|
74
76
|
"scripts": {
|
|
75
|
-
"
|
|
77
|
+
"build": "npm run build:binding && npm run build:cjs && npm run build:esm",
|
|
78
|
+
"build:js": "npm run build:cjs && npm run build:esm",
|
|
76
79
|
"build:cjs": "rm -rf cjs && tsc -p ./tsconfig.json --module commonjs --outDir cjs && cp src/*.d.ts cjs/",
|
|
77
80
|
"build:esm": "rm -rf esm && tsc -p ./tsconfig.json --module esnext --outDir esm && cp src/*.d.ts esm/",
|
|
78
|
-
"build:local": "npm run build:binding:local &&
|
|
81
|
+
"build:local": "npm run build:binding:local && npx turbo run build --filter=@utoo/pack-shared && npm run build:cjs && npm run build:esm && cp src/*.node cjs/ && cp src/*.node esm/",
|
|
79
82
|
"artifacts": "napi artifacts --dir ./src --dist npm",
|
|
80
83
|
"build:binding": "napi build src --platform --release -p pack-napi --cargo-cwd ../../ --cargo-name pack_napi --features plugin --js binding.js --dts binding.d.ts",
|
|
81
84
|
"build:binding:local": "napi build src --platform --profile release-local -p pack-napi --cargo-cwd ../../ --cargo-name pack_napi --features plugin --js binding.js --dts binding.d.ts",
|
|
82
|
-
"prepublishOnly": "
|
|
85
|
+
"prepublishOnly": "turbo run build:js --filter=@utoo/pack && napi prepublish -t npm --skip-gh-release",
|
|
83
86
|
"version": "napi version",
|
|
84
87
|
"generate-features-list": "node ./scripts/generate-feature-list.js"
|
|
85
88
|
},
|
|
86
89
|
"repository": "git@github.com:utooland/utoo.git",
|
|
87
90
|
"optionalDependencies": {
|
|
88
|
-
"@utoo/pack-darwin-arm64": "1.1.
|
|
89
|
-
"@utoo/pack-darwin-x64": "1.1.
|
|
90
|
-
"@utoo/pack-linux-arm64-gnu": "1.1.
|
|
91
|
-
"@utoo/pack-linux-arm64-musl": "1.1.
|
|
92
|
-
"@utoo/pack-linux-x64-gnu": "1.1.
|
|
93
|
-
"@utoo/pack-linux-x64-musl": "1.1.
|
|
94
|
-
"@utoo/pack-win32-x64-msvc": "1.1.
|
|
91
|
+
"@utoo/pack-darwin-arm64": "1.1.2-alpha.2",
|
|
92
|
+
"@utoo/pack-darwin-x64": "1.1.2-alpha.2",
|
|
93
|
+
"@utoo/pack-linux-arm64-gnu": "1.1.2-alpha.2",
|
|
94
|
+
"@utoo/pack-linux-arm64-musl": "1.1.2-alpha.2",
|
|
95
|
+
"@utoo/pack-linux-x64-gnu": "1.1.2-alpha.2",
|
|
96
|
+
"@utoo/pack-linux-x64-musl": "1.1.2-alpha.2",
|
|
97
|
+
"@utoo/pack-win32-x64-msvc": "1.1.2-alpha.2"
|
|
95
98
|
}
|
|
96
99
|
}
|