robuild 0.0.3 → 0.0.4
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
CHANGED
|
@@ -1,265 +1,117 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="./docs/public/logo.png" alt="robuild" width="30%" />
|
|
3
|
+
</div>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
# 📦 robuild 😯 [](https://npmjs.com/package/robuild)
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
English | <a href="./README-zh.md">简体中文</a>
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
2. 覆盖常用的构建能力:通过 Plugin 式开发,完美支持 esbuild 的构建功能
|
|
9
|
-
3. 支持 ES5:借助 SWC 能力,支持构建至 ES5 环境
|
|
9
|
+
⚡️ Zero-config ESM/TS package builder. Powered by [**oxc**](https://oxc.rs/), [**rolldown**](https://rolldown.rs/) and [**rolldown-plugin-dts**](https://github.com/sxzz/rolldown-plugin-dts).
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
- 👌 Focus on ESM compatibility.
|
|
12
|
+
- 🌱 Fresh rewrite with cleanups and removal of legacy features.
|
|
13
|
+
- 🚀 Using [**oxc**](https://oxc.rs/) (for transform) and [**rolldown**](https://rolldown.rs/) (for bundle) for much faster builds!
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
- 命令行交互:cac;
|
|
15
|
-
- 基础构建工具:esbuild、rollup、swc;
|
|
16
|
-
- 文件读取工具:JoyCon;
|
|
17
|
-
- 代码runtime 转换工具:sucrase;
|
|
18
|
-
- 代码语法检查工具:typescript;
|
|
19
|
-
- 代码压缩:terser;
|
|
20
|
-
- 代码文件监听:chokidar;
|
|
21
|
-
- 静态站点:docusaurus;
|
|
22
|
-
- 测试工具:vitest;
|
|
15
|
+
## Proof of concept
|
|
23
16
|
|
|
24
|
-
|
|
17
|
+
> [!IMPORTANT]
|
|
18
|
+
>
|
|
19
|
+
> Features are incomplete, and API and output behavior may change between 0.x versions.
|
|
20
|
+
>
|
|
21
|
+
> Feedback and contributions are very welcome! If you'd like to make changes with more than a few lines of code, please open an issue first to discuss.
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
# 建议当前项目中安装
|
|
28
|
-
pnpm i tsbuild -D
|
|
23
|
+
## Usage
|
|
29
24
|
|
|
30
|
-
|
|
31
|
-
pnpm i tsbuild -g
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## 基础使用
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
tsbuild [...files]
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
文件默认会构建至 `dist`目录下。
|
|
25
|
+
### CLI
|
|
41
26
|
|
|
42
|
-
|
|
27
|
+
```sh
|
|
28
|
+
# bundle
|
|
29
|
+
npx robuild ./src/index.ts
|
|
43
30
|
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
# transform
|
|
32
|
+
npx robuild ./src/runtime/:./dist/runtime
|
|
46
33
|
```
|
|
47
34
|
|
|
48
|
-
|
|
35
|
+
You can use `--dir` to set the working directory.
|
|
49
36
|
|
|
50
|
-
|
|
37
|
+
If paths end with `/`, robuild uses transpile mode using [oxc-transform](https://www.npmjs.com/package/oxc-transform) instead of bundle mode with [rolldown](https://rolldown.rs/).
|
|
51
38
|
|
|
52
|
-
|
|
53
|
-
# 构建结果为 dist/index.js dist/cli.js
|
|
54
|
-
tsbuild --entry src/index.ts --entry src/cli.ts
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
也可以指定构建后的文件名称
|
|
39
|
+
### Programmatic
|
|
58
40
|
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
tsbuild --entry.foo src/index.ts --entry.bar src/cli.ts
|
|
62
|
-
```
|
|
41
|
+
```js
|
|
42
|
+
import { build } from 'robuild'
|
|
63
43
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
export default defineConfig({
|
|
68
|
-
// 输出 dist/a.js 和 dist/b.js
|
|
69
|
-
entry: ['src/a.ts', 'src/b.ts'],
|
|
70
|
-
// 输出 dist/foo.js 和 dist/bar.js
|
|
71
|
-
entry: {
|
|
72
|
-
foo: 'src/a.ts',
|
|
73
|
-
bar: 'src/b.ts',
|
|
74
|
-
},
|
|
44
|
+
await build({
|
|
45
|
+
cwd: '.',
|
|
46
|
+
entries: ['./src/index.ts'],
|
|
75
47
|
})
|
|
76
48
|
```
|
|
77
49
|
|
|
78
|
-
##
|
|
79
|
-
|
|
80
|
-
默认情况下,除了生产环境下所依赖的模块(`peerDependencies`和`dependencies`)外,会自动构建其他的模块,如果不希望构建,可以使用`--external`避免构建。
|
|
81
|
-
|
|
82
|
-
## 自定义配置
|
|
83
|
-
|
|
84
|
-
可以使用如下配置
|
|
85
|
-
|
|
86
|
-
- `tsbuild.config.ts`
|
|
87
|
-
- `tsbuild.config.js`
|
|
88
|
-
- `tsbuild.config.cjs`
|
|
89
|
-
- `tsbuild.config.json`
|
|
90
|
-
- 在`package.json`中的`tsbuild`
|
|
91
|
-
|
|
92
|
-
也可以使用`defineConfig`来进行定制化配置。
|
|
93
|
-
|
|
94
|
-
```typescript
|
|
95
|
-
import { defineConfig } from 'tsbuild'
|
|
96
|
-
|
|
97
|
-
export default defineConfig({
|
|
98
|
-
entry: ['src/index.ts'],
|
|
99
|
-
splitting: false,
|
|
100
|
-
sourcemap: true,
|
|
101
|
-
clean: true,
|
|
102
|
-
})
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
也可以在`package.json`中进行配置。
|
|
106
|
-
|
|
107
|
-
```json
|
|
108
|
-
{
|
|
109
|
-
"tsbuild": {
|
|
110
|
-
"entry": ["src/index.ts"],
|
|
111
|
-
"splitting": false,
|
|
112
|
-
"sourcemap": true,
|
|
113
|
-
"clean": true
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
## 生成声明文件
|
|
119
|
-
|
|
120
|
-
```bash
|
|
121
|
-
tsbuild index.ts --dts
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
以上指令会导出`./dist/index.js`和`./dist/index.d.ts`,当导出多种构建格式时,每种构建格式都会生成一个声明文件。
|
|
125
|
-
|
|
126
|
-
如果有多个入口文件,每个入口文件都会生成一个对应的`.d.ts`文件。因此,如果想对单个入口文件生成声明文件时,请使用 ` --dts <entry>`` 格式,例如 `--dts src/index.ts`。
|
|
127
|
-
|
|
128
|
-
请注意,`--dts`不会解析 `.d.ts` 文件中使用的外部(比如`node_modules`)类型,如果这是某种要求,可以使用 `--dts-resolve`。
|
|
129
|
-
|
|
130
|
-
## 只导出声明文件
|
|
131
|
-
|
|
132
|
-
`--dts-only` 指令等同于`tsc`的`emitDeclarationOnly`。可以使用此指令只生成声明文件。
|
|
133
|
-
|
|
134
|
-
## 生成 sourcemap
|
|
135
|
-
|
|
136
|
-
```bash
|
|
137
|
-
tsbuild index.ts --sourcemap
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
会导出 `./dist/index.js` and `./dist/index.js.map`。
|
|
141
|
-
|
|
142
|
-
如果有多个入口文件,每个入口文件都会生成相对于的`.map`文件。
|
|
143
|
-
|
|
144
|
-
## 构建产物格式
|
|
145
|
-
|
|
146
|
-
支持`ESM`、`CJS`和`IIFE`。
|
|
147
|
-
|
|
148
|
-
可以一次性构建多种类型:
|
|
149
|
-
|
|
150
|
-
```bash
|
|
151
|
-
tsbuild src/index.ts --format esm,cjs,iife
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
将会生成以下文件结构:
|
|
155
|
-
|
|
156
|
-
```bash
|
|
157
|
-
dist
|
|
158
|
-
├── index.mjs # esm
|
|
159
|
-
├── index.global.js # iife
|
|
160
|
-
└── index.js # cjs
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
如果`package.json`中的`type`配置为`module`,产出结果会有所不同:
|
|
164
|
-
|
|
165
|
-
```bash
|
|
166
|
-
dist
|
|
167
|
-
├── index.js # esm
|
|
168
|
-
├── index.global.js # iife
|
|
169
|
-
└── index.cjs # cjs
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
如果不想使用诸如`.mjs`或者`.cjs`这类文件后缀,或者当前环境不支持此后缀,可以使用`--legacy-output`
|
|
173
|
-
|
|
174
|
-
```bash
|
|
175
|
-
tsbuild src/index.ts --format esm,cjs,iife --legacy-output
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
会构建成:
|
|
179
|
-
|
|
180
|
-
```bash
|
|
181
|
-
dist
|
|
182
|
-
├── esm
|
|
183
|
-
│ └── index.js
|
|
184
|
-
├── iife
|
|
185
|
-
│ └── index.js
|
|
186
|
-
└── index.js
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
## 代码分割
|
|
190
|
-
|
|
191
|
-
目前代码分隔只支持`ESM`的产物类型,并且默认是开启的,如果想针对`CJS`的文件类型设置代码分隔,请设置`--splitting`,会启用`esbuild`的代码分隔功能。
|
|
50
|
+
## Config
|
|
192
51
|
|
|
193
|
-
|
|
52
|
+
You can use `build.config.mjs` (or `.ts`) or pass config to `build()` function.
|
|
194
53
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
此处默认使用`tsconfig`中的`compilerOptions.target`,也可以使用`--target`来手动声明。
|
|
198
|
-
|
|
199
|
-
## 支持 ES5
|
|
200
|
-
|
|
201
|
-
可以使用`--target es5`指令来将代码编译构建至 ES5 版本,代码首先会构建成`ES2020`,然后借助 SWC 编译成`ES5`。
|
|
202
|
-
|
|
203
|
-
## watch 模式
|
|
204
|
-
|
|
205
|
-
```bash
|
|
206
|
-
tsbuild src/index.ts --watch
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
启动`watch`模式,这意味着在初始构建后,tsbuild 会监听文件变化。
|
|
210
|
-
|
|
211
|
-
可以使用`--ignore-watch`来取消指定文件的监听。
|
|
212
|
-
|
|
213
|
-
```bash
|
|
214
|
-
tsbuild src src/index.ts --watch --ignore-watch folder1 --ignore-watch folder2
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
## 成功回调
|
|
218
|
-
|
|
219
|
-
```bash
|
|
220
|
-
tsbuild src/index.ts --watch --onSuccess "node dist/index.js"
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
`--onSuccess`会返回`Promise`类型的函数,可以执行类似如下功能
|
|
224
|
-
|
|
225
|
-
```typescript
|
|
226
|
-
import { defineConfig } from 'tsbuild'
|
|
54
|
+
```js
|
|
55
|
+
import { defineConfig } from 'robuild'
|
|
227
56
|
|
|
228
57
|
export default defineConfig({
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
58
|
+
entries: [
|
|
59
|
+
{
|
|
60
|
+
type: 'bundle',
|
|
61
|
+
input: ['./src/index.ts', './src/cli.ts'],
|
|
62
|
+
// outDir: "./dist",
|
|
63
|
+
// minify: false,
|
|
64
|
+
// stub: false,
|
|
65
|
+
// rolldown: {}, // https://rolldown.rs/reference/config-options
|
|
66
|
+
// dts: {}, // https://github.com/sxzz/rolldown-plugin-dts#options
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
type: 'transform',
|
|
70
|
+
input: './src/runtime',
|
|
71
|
+
outDir: './dist/runtime',
|
|
72
|
+
// minify: false,
|
|
73
|
+
// stub: false,
|
|
74
|
+
// oxc: {},
|
|
75
|
+
// resolve: {}
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
hooks: {
|
|
79
|
+
// start: (ctx) => {},
|
|
80
|
+
// end: (ctx) => {},
|
|
81
|
+
// entries: (entries, ctx) => {},
|
|
82
|
+
// rolldownConfig: (config, ctx) => {},
|
|
83
|
+
// rolldownOutput: (output, res, ctx) => {},
|
|
237
84
|
},
|
|
238
85
|
})
|
|
239
86
|
```
|
|
240
87
|
|
|
241
|
-
##
|
|
88
|
+
## Stub Mode
|
|
242
89
|
|
|
243
|
-
|
|
90
|
+
When working on a package locally, it can be tedious to rebuild or run the watch command every time.
|
|
244
91
|
|
|
245
|
-
|
|
246
|
-
tsbuild src/index.ts --minify
|
|
247
|
-
```
|
|
92
|
+
You can use `stub: true` (per entry config) or the `--stub` CLI flag. In this mode, robuild skips the actual build and instead links the expected dist paths to the source files.
|
|
248
93
|
|
|
249
|
-
|
|
94
|
+
- For bundle entries, `.mjs` and `.d.mts` files re-export the source file.
|
|
95
|
+
- For transpile entries, src dir is symlinked to dist.
|
|
250
96
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
97
|
+
**Caveats:**
|
|
98
|
+
|
|
99
|
+
- You need a runtime that natively supports TypeScript. Deno, Bun, Vite, and Node.js (1)
|
|
100
|
+
- For transpile mode, you need to configure your bundler to resolve either `.ts` or `.mjs` extensions.
|
|
101
|
+
- For bundle mode, if you add a new entry or add/remove a `default` export, you need to run the stub build again.
|
|
254
102
|
|
|
255
|
-
|
|
103
|
+
(1) For Node.js, you have several options:
|
|
256
104
|
|
|
257
|
-
`
|
|
105
|
+
- Using `node --experimental-strip-types` (Available in [22.6](https://nodejs.org/en/blog/release/v22.6.0))
|
|
106
|
+
- Using [jiti](https://github.com/unjs/jiti) (`node --import jiti/register`)
|
|
107
|
+
- Using [oxc-node](https://github.com/oxc-project/oxc-node) (`node --import @oxc-node/core/register`)
|
|
108
|
+
- Using [unloader](https://github.com/sxzz/unloader) (`node --import unloader/register`)
|
|
258
109
|
|
|
259
|
-
|
|
110
|
+
## Prior Arts
|
|
260
111
|
|
|
261
|
-
|
|
112
|
+
- [unbuild](https://github.com/unjs/unbuild): Stable solution based on rollup and [mkdist](https://github.com/unjs/mkdist).
|
|
113
|
+
- [tsdown](https://tsdown.dev/): Alternative bundler based on rolldown.
|
|
262
114
|
|
|
263
|
-
##
|
|
115
|
+
## License
|
|
264
116
|
|
|
265
|
-
|
|
117
|
+
💛 Released under the [MIT](./LICENSE) license.
|
|
@@ -93,4 +93,7 @@ interface BuildConfig {
|
|
|
93
93
|
hooks?: BuildHooks;
|
|
94
94
|
}
|
|
95
95
|
//#endregion
|
|
96
|
-
|
|
96
|
+
//#region src/config.d.ts
|
|
97
|
+
declare function defineConfig(config: BuildConfig): BuildConfig;
|
|
98
|
+
//#endregion
|
|
99
|
+
export { BuildConfig, BuildEntry, BundleEntry, TransformEntry, defineConfig };
|
package/dist/config.d.mts
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/config.d.ts
|
|
4
|
-
declare function defineBuildConfig(config: BuildConfig): BuildConfig;
|
|
5
|
-
//#endregion
|
|
6
|
-
export { defineBuildConfig };
|
|
1
|
+
import { defineConfig } from "./_chunks/config-DxLkhDt6.mjs";
|
|
2
|
+
export { defineConfig };
|
package/dist/config.mjs
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BuildConfig, BuildEntry, BundleEntry, TransformEntry } from "./_chunks/
|
|
1
|
+
import { BuildConfig, BuildEntry, BundleEntry, TransformEntry, defineConfig } from "./_chunks/config-DxLkhDt6.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/build.d.ts
|
|
4
4
|
|
|
@@ -7,4 +7,4 @@ import { BuildConfig, BuildEntry, BundleEntry, TransformEntry } from "./_chunks/
|
|
|
7
7
|
*/
|
|
8
8
|
declare function build(config: BuildConfig): Promise<void>;
|
|
9
9
|
//#endregion
|
|
10
|
-
export { BuildConfig, BuildEntry, BundleEntry, TransformEntry, build };
|
|
10
|
+
export { BuildConfig, BuildEntry, BundleEntry, TransformEntry, build, defineConfig };
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "robuild",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"packageManager": "pnpm@10.11.1",
|
|
6
6
|
"description": "Zero-config ESM/TS package builder. Powered by Rolldown and Oxc",
|
|
7
7
|
"license": "MIT",
|
|
@@ -24,8 +24,11 @@
|
|
|
24
24
|
"robuild": "esno src/cli.ts",
|
|
25
25
|
"prepack": "pnpm build",
|
|
26
26
|
"release": "pnpm test && changelogen --release && npm publish && git push --follow-tags",
|
|
27
|
-
"test": "pnpm
|
|
28
|
-
"test:types": "tsc --noEmit --skipLibCheck"
|
|
27
|
+
"test": "pnpm test:types",
|
|
28
|
+
"test:types": "tsc --noEmit --skipLibCheck",
|
|
29
|
+
"docs:dev": "vitepress dev docs",
|
|
30
|
+
"docs:build": "vitepress build docs",
|
|
31
|
+
"docs:preview": "vitepress preview docs"
|
|
29
32
|
},
|
|
30
33
|
"dependencies": {
|
|
31
34
|
"c12": "^3.0.4",
|
|
@@ -51,6 +54,7 @@
|
|
|
51
54
|
"eslint": "^9.28.0",
|
|
52
55
|
"esno": "^4.8.0",
|
|
53
56
|
"prettier": "^3.5.3",
|
|
57
|
+
"vitepress": "^1.6.3",
|
|
54
58
|
"vitest": "^3.2.2"
|
|
55
59
|
}
|
|
56
60
|
}
|