@zntc/rspack-loader 0.1.2 → 0.1.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 +92 -77
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
# @zntc/rspack-loader
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
English · **[한국어](./README_KO.md)**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> TypeScript / JSX / Flow loader for Rspack and Webpack — a drop-in replacement for `swc-loader` / `esbuild-loader` / `babel-loader`, powered by ZNTC (a Zig-based native transpiler).
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@zntc/rspack-loader)
|
|
8
|
+
[](https://github.com/ohah/zntc/blob/main/LICENSE)
|
|
9
|
+
|
|
10
|
+
This loader hands TypeScript / JSX / Flow / decorator transforms to ZNTC, so you can drop it straight into the slot where `builtin:swc-loader`, `esbuild-loader`, or `babel-loader` used to live. The loader API is shared between Rspack and Webpack 5, so the same configuration works on both.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
6
13
|
|
|
7
14
|
```bash
|
|
8
15
|
bun add -D @zntc/rspack-loader @zntc/core
|
|
9
|
-
#
|
|
16
|
+
# or
|
|
10
17
|
npm i -D @zntc/rspack-loader @zntc/core
|
|
11
18
|
```
|
|
12
19
|
|
|
13
|
-
`@zntc/core`
|
|
20
|
+
`@zntc/core` (which ships the native NAPI binary) is pulled in as a dependency.
|
|
14
21
|
|
|
15
|
-
##
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Rspack
|
|
16
25
|
|
|
17
26
|
```js
|
|
18
27
|
// rspack.config.mjs
|
|
@@ -32,9 +41,9 @@ export default {
|
|
|
32
41
|
};
|
|
33
42
|
```
|
|
34
43
|
|
|
35
|
-
`builtin:swc-loader
|
|
44
|
+
Drops straight into the slot where you previously used `builtin:swc-loader`.
|
|
36
45
|
|
|
37
|
-
|
|
46
|
+
### Webpack 5
|
|
38
47
|
|
|
39
48
|
```js
|
|
40
49
|
// webpack.config.mjs
|
|
@@ -56,9 +65,9 @@ export default {
|
|
|
56
65
|
};
|
|
57
66
|
```
|
|
58
67
|
|
|
59
|
-
loader API
|
|
68
|
+
The loader API is shared across Webpack and Rspack, so the same code runs on both.
|
|
60
69
|
|
|
61
|
-
|
|
70
|
+
### Options
|
|
62
71
|
|
|
63
72
|
```ts
|
|
64
73
|
interface ZntcLoaderOptions {
|
|
@@ -67,78 +76,78 @@ interface ZntcLoaderOptions {
|
|
|
67
76
|
}
|
|
68
77
|
```
|
|
69
78
|
|
|
70
|
-
|
|
79
|
+
#### `tsconfigCache` (default: `true`)
|
|
71
80
|
|
|
72
|
-
tsconfig autodiscover walk
|
|
81
|
+
Caches the result of the tsconfig autodiscover walk per worker. In dev / watch sessions, files inside the same workspace are walked only once — saving 5–10 fs syscalls per file. Automatically ignored when `transpileOptions.tsconfigPath` / `tsconfigRaw` is set explicitly.
|
|
73
82
|
|
|
74
|
-
|
|
83
|
+
#### `transpileOptions`
|
|
75
84
|
|
|
76
|
-
`@zntc/core`
|
|
85
|
+
Identical to `TranspileOptions` from `@zntc/core` — only `filename` is filled in automatically by the loader from `this.resourcePath`.
|
|
77
86
|
|
|
78
|
-
|
|
87
|
+
**Target / module**
|
|
79
88
|
|
|
80
|
-
|
|
|
81
|
-
| -------------- | ---------------------------------------------------- |
|
|
82
|
-
| `target` | `'es5' \| 'es2015' \| ... \| 'es2024' \| 'esnext'` | ES
|
|
83
|
-
| `browserslist` | `string \| string[]` | browserslist
|
|
84
|
-
| `platform` | `'browser' \| 'node' \| 'neutral' \| 'react-native'` |
|
|
85
|
-
| `format` | `'esm' \| 'cjs'` |
|
|
89
|
+
| Option | Type | Description |
|
|
90
|
+
| -------------- | ---------------------------------------------------- | --------------------------------------------------- |
|
|
91
|
+
| `target` | `'es5' \| 'es2015' \| ... \| 'es2024' \| 'esnext'` | ES downlevel target |
|
|
92
|
+
| `browserslist` | `string \| string[]` | browserslist query (takes precedence over `target`) |
|
|
93
|
+
| `platform` | `'browser' \| 'node' \| 'neutral' \| 'react-native'` | Target platform |
|
|
94
|
+
| `format` | `'esm' \| 'cjs'` | Module format |
|
|
86
95
|
|
|
87
|
-
|
|
96
|
+
**JSX**
|
|
88
97
|
|
|
89
|
-
|
|
|
98
|
+
| Option | Type | Description |
|
|
90
99
|
| ----------------- | --------------------------------------------- | ----------------------------------------------- |
|
|
91
|
-
| `jsx` | `'classic' \| 'automatic' \| 'automatic-dev'` | JSX
|
|
100
|
+
| `jsx` | `'classic' \| 'automatic' \| 'automatic-dev'` | JSX runtime |
|
|
92
101
|
| `jsxFactory` | `string` | classic factory (default `React.createElement`) |
|
|
93
102
|
| `jsxFragment` | `string` | classic Fragment (default `React.Fragment`) |
|
|
94
103
|
| `jsxImportSource` | `string` | automatic import source (default `react`) |
|
|
95
|
-
| `jsxInJs` | `boolean` | `.js`
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
|
100
|
-
| ------------------------- | --------- |
|
|
101
|
-
| `tsconfigPath` | `string` | tsconfig.json
|
|
102
|
-
| `tsconfigRaw` | `string` |
|
|
103
|
-
| `verbatimModuleSyntax` | `boolean` | TS 5.0+:
|
|
104
|
-
| `useDefineForClassFields` | `boolean` | class
|
|
105
|
-
| `flow` | `boolean` | Flow
|
|
106
|
-
| `experimentalDecorators` | `boolean` |
|
|
107
|
-
| `emitDecoratorMetadata` | `boolean` | decorator metadata
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
|
112
|
-
| ------------------- | --------- |
|
|
113
|
-
| `sourcemap` | `boolean` |
|
|
114
|
-
| `sourcemapDebugIds` | `boolean` | Sentry
|
|
115
|
-
| `sourcesContent` | `boolean` |
|
|
116
|
-
| `sourceRoot` | `string` |
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
|
121
|
-
| ------------------- | --------- |
|
|
122
|
-
| `minify` | `boolean` | whitespace + identifiers + syntax
|
|
123
|
-
| `minifyWhitespace` | `boolean` |
|
|
124
|
-
| `minifyIdentifiers` | `boolean` |
|
|
125
|
-
| `minifySyntax` | `boolean` |
|
|
126
|
-
| `dropConsole` | `boolean` | `console.*`
|
|
127
|
-
| `dropDebugger` | `boolean` | `debugger`
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
|
132
|
-
| ------------- | ------------------------------------------------------------- |
|
|
133
|
-
| `define` | `Array<{ key: string; value: string }>` |
|
|
134
|
-
| `quotes` | `'double' \| 'single' \| 'preserve'` |
|
|
135
|
-
| `asciiOnly` | `boolean` | non-ASCII
|
|
136
|
-
| `charsetUtf8` | `boolean` | non-ASCII
|
|
137
|
-
| `stopAfter` | `'scan' \| 'parse' \| 'semantic' \| 'transform' \| 'codegen'` |
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
104
|
+
| `jsxInJs` | `boolean` | Allow JSX in `.js` files too |
|
|
105
|
+
|
|
106
|
+
**TypeScript / Flow / Decorator**
|
|
107
|
+
|
|
108
|
+
| Option | Type | Description |
|
|
109
|
+
| ------------------------- | --------- | ---------------------------------------------------------------------- |
|
|
110
|
+
| `tsconfigPath` | `string` | Path to tsconfig.json (file or directory); compilerOptions auto-merged |
|
|
111
|
+
| `tsconfigRaw` | `string` | Inline tsconfig JSON string (same semantics as esbuild) |
|
|
112
|
+
| `verbatimModuleSyntax` | `boolean` | TS 5.0+: do not elide unused imports |
|
|
113
|
+
| `useDefineForClassFields` | `boolean` | Transform class fields → constructor `this.x = v` (default: `true`) |
|
|
114
|
+
| `flow` | `boolean` | Flow type stripping |
|
|
115
|
+
| `experimentalDecorators` | `boolean` | Legacy decorator transform |
|
|
116
|
+
| `emitDecoratorMetadata` | `boolean` | Emit decorator metadata |
|
|
117
|
+
|
|
118
|
+
**Source maps**
|
|
119
|
+
|
|
120
|
+
| Option | Type | Description |
|
|
121
|
+
| ------------------- | --------- | ------------------------------------------ |
|
|
122
|
+
| `sourcemap` | `boolean` | Generate source maps |
|
|
123
|
+
| `sourcemapDebugIds` | `boolean` | Sentry-compatible Debug IDs |
|
|
124
|
+
| `sourcesContent` | `boolean` | Include original sources (default: `true`) |
|
|
125
|
+
| `sourceRoot` | `string` | source map `sourceRoot` field |
|
|
126
|
+
|
|
127
|
+
**Minify**
|
|
128
|
+
|
|
129
|
+
| Option | Type | Description |
|
|
130
|
+
| ------------------- | --------- | ---------------------------------------------- |
|
|
131
|
+
| `minify` | `boolean` | whitespace + identifiers + syntax (everything) |
|
|
132
|
+
| `minifyWhitespace` | `boolean` | whitespace only |
|
|
133
|
+
| `minifyIdentifiers` | `boolean` | identifiers only |
|
|
134
|
+
| `minifySyntax` | `boolean` | syntax only |
|
|
135
|
+
| `dropConsole` | `boolean` | Remove `console.*` calls |
|
|
136
|
+
| `dropDebugger` | `boolean` | Remove `debugger` statements |
|
|
137
|
+
|
|
138
|
+
**Other**
|
|
139
|
+
|
|
140
|
+
| Option | Type | Description |
|
|
141
|
+
| ------------- | ------------------------------------------------------------- | --------------------------------------------- |
|
|
142
|
+
| `define` | `Array<{ key: string; value: string }>` | Identifier substitution (`value` is raw JSON) |
|
|
143
|
+
| `quotes` | `'double' \| 'single' \| 'preserve'` | String quote style |
|
|
144
|
+
| `asciiOnly` | `boolean` | Escape non-ASCII as `\uXXXX` |
|
|
145
|
+
| `charsetUtf8` | `boolean` | Do not escape non-ASCII |
|
|
146
|
+
| `stopAfter` | `'scan' \| 'parse' \| 'semantic' \| 'transform' \| 'codegen'` | Debug / profile — skip after the given phase |
|
|
147
|
+
|
|
148
|
+
For the full option definitions, see [`@zntc/core` `TranspileOptions`](https://github.com/ohah/zntc/blob/main/packages/shared/index.ts).
|
|
149
|
+
|
|
150
|
+
### Example — environment variable substitution with `define`
|
|
142
151
|
|
|
143
152
|
```js
|
|
144
153
|
{
|
|
@@ -154,7 +163,7 @@ tsconfig autodiscover walk 결과를 worker 별로 캐시. dev/watch 세션에
|
|
|
154
163
|
}
|
|
155
164
|
```
|
|
156
165
|
|
|
157
|
-
|
|
166
|
+
### Example — Flow code
|
|
158
167
|
|
|
159
168
|
```js
|
|
160
169
|
{
|
|
@@ -164,7 +173,7 @@ tsconfig autodiscover walk 결과를 worker 별로 캐시. dev/watch 세션에
|
|
|
164
173
|
}
|
|
165
174
|
```
|
|
166
175
|
|
|
167
|
-
|
|
176
|
+
### Example — explicit tsconfig + decorators
|
|
168
177
|
|
|
169
178
|
```js
|
|
170
179
|
{
|
|
@@ -179,13 +188,19 @@ tsconfig autodiscover walk 결과를 worker 별로 캐시. dev/watch 세션에
|
|
|
179
188
|
}
|
|
180
189
|
```
|
|
181
190
|
|
|
182
|
-
|
|
191
|
+
### Peer dependencies
|
|
183
192
|
|
|
184
|
-
- `@rspack/core >= 1.0.0` (optional
|
|
193
|
+
- `@rspack/core >= 1.0.0` (optional — both Rspack 1.x and 2.x are supported)
|
|
185
194
|
- `webpack >= 5.0.0` (optional)
|
|
186
195
|
|
|
187
|
-
|
|
196
|
+
Installing either one is enough.
|
|
197
|
+
|
|
198
|
+
## Documentation
|
|
199
|
+
|
|
200
|
+
- Monorepo: <https://github.com/ohah/zntc>
|
|
201
|
+
- Docs site: <https://ohah.github.io/zntc>
|
|
202
|
+
- Rspack / Webpack integration guide: <https://ohah.github.io/zntc/guides/rspack-loader/>
|
|
188
203
|
|
|
189
|
-
##
|
|
204
|
+
## License
|
|
190
205
|
|
|
191
|
-
MIT
|
|
206
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zntc/rspack-loader",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Use ZNTC as the TypeScript/JSX/Flow transformer in Rspack and Webpack (drop-in alternative to swc-loader / esbuild-loader / babel-loader)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"babel-loader",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"prepublishOnly": "bun run build && bunx publint --strict --level error ."
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@zntc/core": "0.1.
|
|
60
|
+
"@zntc/core": "0.1.4"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@rspack/core": "^2.0.1",
|