unplugin-cloudflare-tunnel 0.1.0 → 0.1.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.
@@ -1,23 +1,21 @@
1
1
  # unplugin-cloudflare-tunnel
2
2
 
3
- [![NPM version](https://img.shields.io/npm/v/unplugin-cloudflare-tunnel?color=a1b858&label=)](https://npm.im/unplugin-cloudflare-tunnel)
4
- [![pkg.pr.new](https://pkg.pr.new/badge/o-az/unplugin-cloudflare-tunnel)](https://pkg.pr.new/~/o-az/unplugin-cloudflare-tunnel)
3
+ [![Open on npmx.dev](https://npmx.dev/api/registry/badge/version/unplugin-cloudflare-tunnel)](https://npmx.dev/package/unplugin-cloudflare-tunnel) [![pkg.pr.new](https://pkg.pr.new/badge/o-az/unplugin-cloudflare-tunnel)](https://pkg.pr.new/~/o-az/unplugin-cloudflare-tunnel)
5
4
 
6
- A plugin that automatically creates and manages Cloudflare tunnels for local development.
7
- Available for:
5
+ A plugin that automatically creates and manages Cloudflare tunnels for local development. Available for:
8
6
 
9
- - [Vite](https://vite.dev),
7
+ - [Vite](https://vite.dev)
10
8
  - [Rspack](https://rspack.rs)
11
9
  - [Webpack](https://webpack.js.org)
10
+ - [esbuild](https://esbuild.github.io)
11
+ - [Rollup](https://rollupjs.org)
12
+ - [Rolldown](https://rolldown.rs)
12
13
  - [Astro](https://astro.build) <sup>soon</sup>
13
14
  - [Farm](https://farmfe.org) <sup>soon</sup>
14
- - [esbuild](https://esbuild.github.io) <sup>soon</sup>
15
- - [Rollup](https://rollupjs.org) <sup>soon</sup>
16
- - [Rolldown](https://rolldown.rs) <sup>soon</sup>
17
15
 
18
16
  > [!NOTE]
19
- > This is under active development.
20
- > If you have any suggestions, I'm all ears, please open an issue.
17
+ >
18
+ > This is under active development. If you have any suggestions, I'm all ears, please open an issue.
21
19
 
22
20
  ## Install
23
21
 
@@ -54,6 +52,10 @@ Mode selection rules:
54
52
  - `debug?: boolean`
55
53
  - `enabled?: boolean`
56
54
 
55
+ > [!TIP]
56
+ >
57
+ > For esbuild, Rollup, and Rolldown dev usage, set `port` explicitly so the tunnel can target the local dev server.
58
+
57
59
  ### Quick mode example
58
60
 
59
61
  ```ts
@@ -65,9 +67,9 @@ export default defineConfig({
65
67
  plugins: [
66
68
  CloudflareTunnel({
67
69
  mode: 'quick',
68
- protocol: 'http2',
69
- }),
70
- ],
70
+ protocol: 'http2'
71
+ })
72
+ ]
71
73
  })
72
74
  ```
73
75
 
@@ -84,9 +86,9 @@ export default defineConfig({
84
86
  mode: 'named',
85
87
  hostname: 'dev.example.com',
86
88
  apiToken: process.env.CLOUDFLARE_API_TOKEN,
87
- protocol: 'http2',
88
- }),
89
- ],
89
+ protocol: 'http2'
90
+ })
91
+ ]
90
92
  })
91
93
  ```
92
94
 
@@ -101,13 +103,13 @@ import CloudflareTunnel from 'unplugin-cloudflare-tunnel/vite'
101
103
  export default defineConfig({
102
104
  plugins: [
103
105
  CloudflareTunnel({
104
- mode: 'quick',
105
- }),
106
- ],
106
+ mode: 'quick'
107
+ })
108
+ ]
107
109
  })
108
110
  ```
109
111
 
110
- Example in [./example/vite.config.ts](../example/vite.config.ts): `bun --filter example dev:vite`
112
+ Example in [./example/vite.config.ts](../example/vite.config.ts): `cd example && bun run dev:vite`
111
113
 
112
114
  <br></details>
113
115
 
@@ -120,13 +122,11 @@ import CloudflareTunnel from 'unplugin-cloudflare-tunnel/rspack'
120
122
 
121
123
  export default {
122
124
  /* ... */
123
- plugins: [
124
- CloudflareTunnel(),
125
- ]
125
+ plugins: [CloudflareTunnel()]
126
126
  }
127
127
  ```
128
128
 
129
- Example in [./example/rspack.config.ts](../example/rspack.config.ts): `bun --filter example dev:rspack`
129
+ Example in [./example/rspack.config.ts](../example/rspack.config.ts): `cd example && bun run dev:rspack`
130
130
 
131
131
  <br></details>
132
132
 
@@ -135,23 +135,116 @@ Example in [./example/rspack.config.ts](../example/rspack.config.ts): `bun --fil
135
135
 
136
136
  ```ts
137
137
  // webpack.config.js
138
+ const CloudflareTunnel = require('unplugin-cloudflare-tunnel/webpack')
139
+
138
140
  module.exports = {
139
141
  /* ... */
142
+ plugins: [CloudflareTunnel()]
143
+ }
144
+ ```
145
+
146
+ Example in [./example/webpack.config.ts](../example/webpack.config.ts): `cd example && bun run dev:webpack`
147
+
148
+ <br></details>
149
+
150
+ <details>
151
+ <summary>esbuild</summary><br>
152
+
153
+ ```ts
154
+ // esbuild.config.ts
155
+ import { context } from 'esbuild'
156
+ import CloudflareTunnel from 'unplugin-cloudflare-tunnel/esbuild'
157
+
158
+ const ctx = await context({
159
+ entryPoints: ['./main.mjs'],
160
+ bundle: true,
161
+ outdir: './dist',
162
+ outExtension: { '.js': '.mjs' },
163
+ define: {
164
+ __VIA_TOOL__: JSON.stringify('esbuild')
165
+ },
140
166
  plugins: [
141
- require('unplugin-cloudflare-tunnel/webpack')({
142
- CloudflareTunnel(),
167
+ CloudflareTunnel({
168
+ hostname: 'dev.example.com',
169
+ apiToken: process.env.CLOUDFLARE_API_TOKEN,
170
+ port: 6420
171
+ })
143
172
  ]
144
- }
173
+ })
174
+
175
+ await ctx.watch()
176
+ await ctx.serve({ port: 6420, servedir: './dist' })
177
+ ```
178
+
179
+ Example in [./example/esbuild.config.ts](../example/esbuild.config.ts): `cd example && bun run esbuild.config.ts`
180
+
181
+ > [!NOTE]
182
+ >
183
+ > esbuild dev usage requires an explicit `port` option.
184
+
185
+ <br></details>
186
+
187
+ <details>
188
+ <summary>Rollup</summary><br>
189
+
190
+ ```ts
191
+ // rollup.config.ts
192
+ import { defineConfig } from 'rollup'
193
+ import CloudflareTunnel from 'unplugin-cloudflare-tunnel/rollup'
194
+
195
+ export default defineConfig({
196
+ /* ... */
197
+ plugins: [
198
+ CloudflareTunnel({
199
+ hostname: 'dev.example.com',
200
+ apiToken: process.env.CLOUDFLARE_API_TOKEN,
201
+ port: 6421
202
+ })
203
+ ]
204
+ })
145
205
  ```
146
206
 
147
- Example in [./example/webpack.config.ts](../example/webpack.config.ts): `bun --filter example dev:webpack`
207
+ Example in [./example/rollup.config.ts](../example/rollup.config.ts): `cd example && bun run dev:rollup`
208
+
209
+ > [!NOTE]
210
+ >
211
+ > Rollup dev usage requires an explicit `port` option.
212
+
213
+ <br></details>
214
+
215
+ <details>
216
+ <summary>Rolldown</summary><br>
217
+
218
+ ```ts
219
+ // rolldown.config.ts
220
+ import { defineConfig } from 'rolldown'
221
+ import CloudflareTunnel from 'unplugin-cloudflare-tunnel/rolldown'
222
+
223
+ export default defineConfig({
224
+ /* ... */
225
+ plugins: [
226
+ CloudflareTunnel({
227
+ hostname: 'dev.example.com',
228
+ apiToken: process.env.CLOUDFLARE_API_TOKEN,
229
+ port: 6422
230
+ })
231
+ ]
232
+ })
233
+ ```
234
+
235
+ Example in [./example/rolldown.config.ts](../example/rolldown.config.ts): `cd example && bun run dev:rolldown`
236
+
237
+ > [!NOTE]
238
+ >
239
+ > Rolldown dev usage requires an explicit `port` option.
148
240
 
149
241
  <br></details>
150
242
 
151
243
  ## Virtual Module: Access Tunnel URL
152
244
 
153
245
  > [!NOTE]
154
- > This feature is only available in Vite and Vite-based frameworks (i.e., Astro)
246
+ >
247
+ > This feature is available in supported dev integrations, including Vite, Webpack, Rspack, esbuild, Rollup, and Rolldown.
155
248
 
156
249
  The plugin provides a virtual module that allows you to access the tunnel URL in your application code during development. This is useful for:
157
250
 
@@ -162,7 +255,7 @@ The plugin provides a virtual module that allows you to access the tunnel URL in
162
255
 
163
256
  ### Usage
164
257
 
165
- ```typescript
258
+ ```ts
166
259
  import { getTunnelUrl } from 'virtual:unplugin-cloudflare-tunnel'
167
260
 
168
261
  // Get the current tunnel URL
@@ -181,14 +274,14 @@ shareButton.onclick = () => {
181
274
 
182
275
  To get TypeScript support for the virtual module, add a reference to the types:
183
276
 
184
- ```typescript
277
+ ```ts
185
278
  // In your tsconfig.json or a .d.ts file
186
279
  /// <reference types="unplugin-cloudflare-tunnel/virtual" />
187
280
  ```
188
281
 
189
282
  Or create a `virtual.d.ts` file in your project:
190
283
 
191
- ```typescript
284
+ ```ts
192
285
  /// <reference types="unplugin-cloudflare-tunnel/virtual" />
193
286
  ```
194
287
 
package/dist/astro.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { CloudflareTunnelOptions } from "./index.mjs";
1
+ import { t as CloudflareTunnelOptions } from "./options-DI3sWmXl.mjs";
2
2
 
3
3
  //#region src/astro.d.ts
4
4
  declare const _default: (options: CloudflareTunnelOptions) => any;
package/dist/astro.mjs CHANGED
@@ -1,8 +1,9 @@
1
- import { CloudflareTunnel } from "./index.mjs";
1
+ import { t as CloudflareTunnel } from "./src-D0eR3kCb.mjs";
2
2
  //#region src/astro.ts
3
3
  var astro_default = (options) => ({
4
4
  name: "unplugin-cloudflare-tunnel",
5
5
  hooks: { "astro:config:setup": async (astro) => {
6
+ astro.config.vite ||= {};
6
7
  astro.config.vite.plugins ||= [];
7
8
  astro.config.vite.plugins.push(CloudflareTunnel.vite(options));
8
9
  } }
@@ -1,4 +1,4 @@
1
- import { CloudflareTunnelOptions } from "./index.mjs";
1
+ import { t as CloudflareTunnelOptions } from "./options-DI3sWmXl.mjs";
2
2
  import * as _$esbuild from "esbuild";
3
3
 
4
4
  //#region src/esbuild.d.ts
package/dist/esbuild.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { CloudflareTunnel } from "./index.mjs";
1
+ import { t as CloudflareTunnel } from "./src-D0eR3kCb.mjs";
2
2
  //#region src/esbuild.ts
3
3
  /**
4
4
  * This entry file is for esbuild plugin.
package/dist/farm.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { CloudflareTunnelOptions } from "./index.mjs";
1
+ import { t as CloudflareTunnelOptions } from "./options-DI3sWmXl.mjs";
2
2
 
3
3
  //#region src/farm.d.ts
4
4
  /**
package/dist/farm.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { CloudflareTunnel } from "./index.mjs";
1
+ import { t as CloudflareTunnel } from "./src-D0eR3kCb.mjs";
2
2
  //#region src/farm.ts
3
3
  /**
4
4
  * This entry file is for Farm plugin.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as ZodMiniObject, c as ZodMiniUnknown, i as ZodMiniNumber, l as output, n as ZodMiniBoolean, o as ZodMiniOptional, r as ZodMiniNullable, s as ZodMiniString, t as ZodMiniArray, u as $strip } from "./schemas-DKJtFAG_.mjs";
1
+ import { t as CloudflareTunnelOptions } from "./options-DI3sWmXl.mjs";
2
2
  import { UnpluginInstance } from "unplugin";
3
3
 
4
4
  //#region src/index.d.ts
@@ -13,176 +13,6 @@ import { UnpluginInstance } from "unplugin";
13
13
  * @version 1.0.0
14
14
  * @license MIT
15
15
  */
16
- declare const CloudflareApiResponseSchema: ZodMiniObject<{
17
- success: ZodMiniBoolean<boolean>;
18
- errors: ZodMiniOptional<ZodMiniArray<ZodMiniObject<{
19
- code: ZodMiniNumber<number>;
20
- message: ZodMiniString<string>;
21
- }, $strip>>>;
22
- messages: ZodMiniOptional<ZodMiniArray<ZodMiniString<string>>>;
23
- result: ZodMiniUnknown;
24
- }, $strip>;
25
- declare const AccountSchema: ZodMiniObject<{
26
- id: ZodMiniString<string>;
27
- name: ZodMiniString<string>;
28
- }, $strip>;
29
- declare const ZoneSchema: ZodMiniObject<{
30
- id: ZodMiniString<string>;
31
- name: ZodMiniString<string>;
32
- account: ZodMiniOptional<ZodMiniObject<{
33
- id: ZodMiniString<string>;
34
- }, $strip>>;
35
- }, $strip>;
36
- declare const TunnelSchema: ZodMiniObject<{
37
- id: ZodMiniString<string>;
38
- name: ZodMiniString<string>;
39
- account_tag: ZodMiniString<string>;
40
- created_at: ZodMiniString<string>;
41
- connections: ZodMiniOptional<ZodMiniArray<ZodMiniUnknown>>;
42
- }, $strip>;
43
- declare const DNSRecordSchema: ZodMiniObject<{
44
- id: ZodMiniString<string>;
45
- type: ZodMiniString<string>;
46
- name: ZodMiniString<string>;
47
- content: ZodMiniString<string>;
48
- proxied: ZodMiniBoolean<boolean>;
49
- comment: ZodMiniOptional<ZodMiniNullable<ZodMiniString<string>>>;
50
- }, $strip>;
51
- type CloudflareApiResponse<T = unknown> = output<typeof CloudflareApiResponseSchema> & {
52
- result: T;
53
- };
54
- type Account = output<typeof AccountSchema>;
55
- type Zone = output<typeof ZoneSchema>;
56
- type Tunnel = output<typeof TunnelSchema>;
57
- type DNSRecord = output<typeof DNSRecordSchema>;
58
- /**
59
- * Base configuration options shared between named and quick tunnel modes
60
- */
61
- interface BaseTunnelOptions {
62
- /**
63
- * Tunnel mode.
64
- * - `quick`: temporary `trycloudflare.com` URL, no hostname required
65
- * - `named`: persistent tunnel using your configured hostname
66
- *
67
- * When omitted, the plugin uses named mode if `hostname` is provided,
68
- * otherwise it uses quick mode.
69
- */
70
- mode?: 'quick' | 'named';
71
- /**
72
- * Local port your dev server listens on
73
- * If not specified, will automatically use the bundler's configured port
74
- * @default undefined (auto-detect from bundler config)
75
- */
76
- port?: number;
77
- /**
78
- * Path to write cloudflared logs to a file
79
- * Useful for debugging tunnel issues
80
- */
81
- logFile?: string;
82
- /**
83
- * Log level for cloudflared output shown by the plugin.
84
- * The plugin still runs cloudflared with at least `info` internally so it can
85
- * detect tunnel readiness and print the tunnel URL.
86
- * @default undefined
87
- */
88
- logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'fatal';
89
- /**
90
- * Transport protocol used by cloudflared.
91
- * `http2` is the default because it is more reliable for local development
92
- * networks than QUIC.
93
- * @default 'http2'
94
- */
95
- protocol?: 'http2' | 'quic';
96
- /**
97
- * Enable additional verbose logging for easier debugging.
98
- * When true, the plugin will output extra information prefixed with
99
- * `[cloudflare-tunnel:debug]`.
100
- * @default false
101
- */
102
- debug?: boolean;
103
- /**
104
- * Enable or disable the tunnel plugin. When set to `false` the plugin is
105
- * completely disabled — cloudflared will NOT be downloaded or started.
106
- * @default true
107
- */
108
- enabled?: boolean;
109
- }
110
- /**
111
- * Configuration options for named tunnel mode (requires hostname and API token)
112
- */
113
- interface NamedTunnelOptions extends BaseTunnelOptions {
114
- /**
115
- * Public hostname for the tunnel (e.g., "dev.example.com")
116
- * Must be a domain in your Cloudflare account
117
- */
118
- hostname: string;
119
- /**
120
- * Cloudflare API token with required permissions:
121
- * - Zone:Zone:Read
122
- * - Zone:DNS:Edit
123
- * - Account:Cloudflare Tunnel:Edit
124
- *
125
- * Fallback priority:
126
- * 1. Provided apiToken option
127
- * 2. CLOUDFLARE_API_TOKEN environment variable
128
- */
129
- apiToken?: string;
130
- /**
131
- * Cloudflare account ID
132
- * If omitted, uses the first account associated with the API token
133
- */
134
- accountId?: string;
135
- /**
136
- * Cloudflare zone ID
137
- * If omitted, automatically resolved from the hostname
138
- */
139
- zoneId?: string;
140
- /**
141
- * Name for the tunnel in your Cloudflare dashboard
142
- * Must contain only letters, numbers, and hyphens. Cannot start or end with a hyphen.
143
- * @default "dev-tunnel"
144
- */
145
- tunnelName?: string;
146
- /**
147
- * Wildcard DNS domain to ensure exists (e.g., "*.example.com").
148
- * When provided the plugin will ensure both A and AAAA records exist.
149
- */
150
- dns?: string;
151
- /**
152
- * Wildcard SSL domain to ensure exists (e.g., "*.example.com").
153
- * When provided the plugin will request/ensure a wildcard edge certificate.
154
- * If omitted the plugin will attempt to detect an existing wildcard certificate
155
- * or Total TLS; otherwise it will request a regular certificate for the provided hostname.
156
- */
157
- ssl?: string;
158
- /**
159
- * Cleanup configuration for managing orphaned resources
160
- */
161
- cleanup?: {
162
- /**
163
- * Whether to automatically clean up orphaned DNS records on startup
164
- * @default true
165
- */
166
- autoCleanup?: boolean;
167
- /**
168
- * Array of tunnel names to preserve during cleanup (in addition to current tunnel)
169
- * @default []
170
- */
171
- preserveTunnels?: Array<string>;
172
- };
173
- }
174
- /**
175
- * Configuration options for quick tunnel mode (no hostname required, generates random URL)
176
- */
177
- interface QuickTunnelOptions extends BaseTunnelOptions {}
178
- /**
179
- * Configuration options for the Cloudflare Tunnel plugin
180
- *
181
- * Two modes are supported:
182
- * - Named tunnel mode: set `mode: 'named'` or provide `hostname`
183
- * - Quick tunnel mode: set `mode: 'quick'` or omit `hostname`
184
- */
185
- type CloudflareTunnelOptions = NamedTunnelOptions | QuickTunnelOptions;
186
16
  declare const CloudflareTunnel: UnpluginInstance<CloudflareTunnelOptions | undefined, false>;
187
17
  //#endregion
188
- export { Account, CloudflareApiResponse, CloudflareTunnel, CloudflareTunnel as default, CloudflareTunnelOptions, DNSRecord, Tunnel, Zone };
18
+ export { CloudflareTunnel, CloudflareTunnel as default };