robuild 0.0.2 → 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
- # tsbuild
1
+ <div align="center">
2
+ <img src="./docs/public/logo.png" alt="robuild" width="30%" />
3
+ </div>
2
4
 
3
- ⚡️ Bundle your TypeScript library with no config, powered by esbuild、swc、rollup ...
5
+ # 📦 robuild 😯 [![npm](https://img.shields.io/npm/v/robuild.svg)](https://npmjs.com/package/robuild)
4
6
 
5
- ## 特点
7
+ English | <a href="./README-zh.md">简体中文</a>
6
8
 
7
- 1. 基于 esbuild 开发:无需关心内部构建逻辑,一键式构建
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
- - 包管理工具:pnpm;
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
- ```bash
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
- ```bash
45
- tsbuild src/index.ts src/cli.ts
31
+ # transform
32
+ npx robuild ./src/runtime/:./dist/runtime
46
33
  ```
47
34
 
48
- 会在`dist`目录下产出`index.js`与`cli.js`。
35
+ You can use `--dir` to set the working directory.
49
36
 
50
- 也可以使用`CLI`的指令执行相同的功能
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
- ```bash
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
- ```bash
60
- # 构建结果为 dist/foo.js dist/bar.js
61
- tsbuild --entry.foo src/index.ts --entry.bar src/cli.ts
62
- ```
41
+ ```js
42
+ import { build } from 'robuild'
63
43
 
64
- 也可以在 `encode-config.ts` 中配置:
65
-
66
- ```typescript
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
- ## 设置 exclude
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
- 对应地,如果想关闭代码分隔,请使用`--no-splitting`。
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
- async onSuccess() {
230
- const server = http.createServer((req, res) => {
231
- res.end('Encode Studio!')
232
- })
233
- server.listen(3000)
234
- return () => {
235
- server.close()
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
- 可以使用`--minify`来压缩代码
90
+ When working on a package locally, it can be tedious to rebuild or run the watch command every time.
244
91
 
245
- ```bash
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
- 或者使用`terser`而不是 esbuild 来压缩代码,前提条件是要先安装`terser`
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
- ```bash
252
- tsbuild src/index.ts --minify
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
- ## tree shaking
103
+ (1) For Node.js, you have several options:
256
104
 
257
- `esbuild`默认开启`tree shaking`,但是特殊情况下(如:[external 模块](https://github.com/evanw/esbuild/issues/1794)或者[未使用的引用](https://github.com/evanw/esbuild/issues/1435))等情况还是有些问题。
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
- 提供`--treeshake`指令来启用`rollup`的`tree shaking`。
110
+ ## Prior Arts
260
111
 
261
- 针对更多帮助,请使用`tsbuild --help`。
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
- ## how-a-package-is-resolved
115
+ ## License
264
116
 
265
- <img src="./assets/how-a-package-is-resolved.jpeg">
117
+ 💛 Released under the [MIT](./LICENSE) license.
@@ -0,0 +1,7 @@
1
+ //#region src/config.ts
2
+ function defineConfig(config) {
3
+ return config;
4
+ }
5
+
6
+ //#endregion
7
+ export { defineConfig };
@@ -93,4 +93,7 @@ interface BuildConfig {
93
93
  hooks?: BuildHooks;
94
94
  }
95
95
  //#endregion
96
- export { BuildConfig, BuildEntry, BundleEntry, TransformEntry };
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 { BuildConfig } from "./_chunks/types-1AA9vjTS.mjs";
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
@@ -1,7 +1,3 @@
1
- //#region src/config.ts
2
- function defineBuildConfig(config) {
3
- return config;
4
- }
1
+ import { defineConfig } from "./_chunks/config-B_2eqpNJ.mjs";
5
2
 
6
- //#endregion
7
- export { defineBuildConfig };
3
+ export { defineConfig };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { BuildConfig, BuildEntry, BundleEntry, TransformEntry } from "./_chunks/types-1AA9vjTS.mjs";
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
@@ -1,3 +1,4 @@
1
1
  import { build } from "./_chunks/build-Dn4aJvxA.mjs";
2
+ import { defineConfig } from "./_chunks/config-B_2eqpNJ.mjs";
2
3
 
3
- export { build };
4
+ export { build, defineConfig };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "robuild",
3
3
  "type": "module",
4
- "version": "0.0.2",
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 lint && pnpm test:types",
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",
@@ -39,7 +42,8 @@
39
42
  "pretty-bytes": "^7.0.0",
40
43
  "rolldown": "1.0.0-beta.12",
41
44
  "rolldown-plugin-dts": "^0.13.8",
42
- "tinyglobby": "^0.2.14"
45
+ "tinyglobby": "^0.2.14",
46
+ "typescript": "^5.8.3"
43
47
  },
44
48
  "devDependencies": {
45
49
  "@antfu/eslint-config": "^4.17.0",
@@ -50,7 +54,7 @@
50
54
  "eslint": "^9.28.0",
51
55
  "esno": "^4.8.0",
52
56
  "prettier": "^3.5.3",
53
- "typescript": "^5.8.3",
57
+ "vitepress": "^1.6.3",
54
58
  "vitest": "^3.2.2"
55
59
  }
56
60
  }