unplugin-cloudflare-tunnel 0.0.5 → 0.1.1

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/.github/README.md CHANGED
@@ -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
 
@@ -29,21 +27,89 @@ npm add unplugin-cloudflare-tunnel
29
27
 
30
28
  ## Usage
31
29
 
30
+ ### Modes
31
+
32
+ The plugin supports two modes:
33
+
34
+ - **Quick mode**: temporary `trycloudflare.com` URL, no Cloudflare credentials required
35
+ - **Named mode**: persistent tunnel on your own hostname
36
+
37
+ Mode selection rules:
38
+
39
+ - `mode: 'quick'` → always quick mode
40
+ - `mode: 'named'` → always named mode, requires `hostname`
41
+ - if `mode` is omitted:
42
+ - `hostname` provided → named mode
43
+ - otherwise → quick mode
44
+
45
+ ### Common options
46
+
47
+ - `mode?: 'quick' | 'named'`
48
+ - `protocol?: 'http2' | 'quic'` — defaults to `http2` for better local dev reliability
49
+ - `logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'fatal'`
50
+ - `port?: number`
51
+ - `logFile?: string`
52
+ - `debug?: boolean`
53
+ - `enabled?: boolean`
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
+
59
+ ### Quick mode example
60
+
61
+ ```ts
62
+ // vite.config.ts
63
+ import { defineConfig } from 'vite'
64
+ import CloudflareTunnel from 'unplugin-cloudflare-tunnel/vite'
65
+
66
+ export default defineConfig({
67
+ plugins: [
68
+ CloudflareTunnel({
69
+ mode: 'quick',
70
+ protocol: 'http2'
71
+ })
72
+ ]
73
+ })
74
+ ```
75
+
76
+ ### Named mode example
77
+
78
+ ```ts
79
+ // vite.config.ts
80
+ import { defineConfig } from 'vite'
81
+ import CloudflareTunnel from 'unplugin-cloudflare-tunnel/vite'
82
+
83
+ export default defineConfig({
84
+ plugins: [
85
+ CloudflareTunnel({
86
+ mode: 'named',
87
+ hostname: 'dev.example.com',
88
+ apiToken: process.env.CLOUDFLARE_API_TOKEN,
89
+ protocol: 'http2'
90
+ })
91
+ ]
92
+ })
93
+ ```
94
+
32
95
  <details>
33
96
  <summary>Vite</summary><br>
34
97
 
35
98
  ```ts
36
99
  // vite.config.ts
100
+ import { defineConfig } from 'vite'
37
101
  import CloudflareTunnel from 'unplugin-cloudflare-tunnel/vite'
38
102
 
39
103
  export default defineConfig({
40
104
  plugins: [
41
- CloudflareTunnel(),
42
- ],
105
+ CloudflareTunnel({
106
+ mode: 'quick'
107
+ })
108
+ ]
43
109
  })
44
110
  ```
45
111
 
46
- 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`
47
113
 
48
114
  <br></details>
49
115
 
@@ -56,13 +122,11 @@ import CloudflareTunnel from 'unplugin-cloudflare-tunnel/rspack'
56
122
 
57
123
  export default {
58
124
  /* ... */
59
- plugins: [
60
- CloudflareTunnel(),
61
- ]
125
+ plugins: [CloudflareTunnel()]
62
126
  }
63
127
  ```
64
128
 
65
- 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`
66
130
 
67
131
  <br></details>
68
132
 
@@ -71,23 +135,116 @@ Example in [./example/rspack.config.ts](../example/rspack.config.ts): `bun --fil
71
135
 
72
136
  ```ts
73
137
  // webpack.config.js
138
+ const CloudflareTunnel = require('unplugin-cloudflare-tunnel/webpack')
139
+
74
140
  module.exports = {
75
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
+ },
76
166
  plugins: [
77
- require('unplugin-cloudflare-tunnel/webpack')({
78
- CloudflareTunnel(),
167
+ CloudflareTunnel({
168
+ hostname: 'dev.example.com',
169
+ apiToken: process.env.CLOUDFLARE_API_TOKEN,
170
+ port: 6420
171
+ })
79
172
  ]
80
- }
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
+ })
205
+ ```
206
+
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
+ })
81
233
  ```
82
234
 
83
- Example in [./example/webpack.config.ts](../example/webpack.config.ts): `bun --filter example dev:webpack`
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.
84
240
 
85
241
  <br></details>
86
242
 
87
243
  ## Virtual Module: Access Tunnel URL
88
244
 
89
245
  > [!NOTE]
90
- > 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.
91
248
 
92
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:
93
250
 
@@ -98,7 +255,7 @@ The plugin provides a virtual module that allows you to access the tunnel URL in
98
255
 
99
256
  ### Usage
100
257
 
101
- ```typescript
258
+ ```ts
102
259
  import { getTunnelUrl } from 'virtual:unplugin-cloudflare-tunnel'
103
260
 
104
261
  // Get the current tunnel URL
@@ -117,14 +274,14 @@ shareButton.onclick = () => {
117
274
 
118
275
  To get TypeScript support for the virtual module, add a reference to the types:
119
276
 
120
- ```typescript
277
+ ```ts
121
278
  // In your tsconfig.json or a .d.ts file
122
279
  /// <reference types="unplugin-cloudflare-tunnel/virtual" />
123
280
  ```
124
281
 
125
282
  Or create a `virtual.d.ts` file in your project:
126
283
 
127
- ```typescript
284
+ ```ts
128
285
  /// <reference types="unplugin-cloudflare-tunnel/virtual" />
129
286
  ```
130
287
 
@@ -134,6 +291,12 @@ Or create a `virtual.d.ts` file in your project:
134
291
  - **Named tunnel mode**: Returns your custom domain URL like `https://dev.example.com`
135
292
  - **Plugin disabled**: Returns an empty string `""`
136
293
 
294
+ ### Notes on modes
295
+
296
+ - Named-only options such as `hostname`, `apiToken`, `accountId`, `zoneId`, `tunnelName`, `dns`, `ssl`, and `cleanup` are only valid in named mode.
297
+ - Quick mode ignores Cloudflare account setup entirely and creates an ephemeral tunnel.
298
+ - `protocol` applies to both quick and named modes.
299
+
137
300
  ### Notes
138
301
 
139
302
  - The virtual module is only available during development mode
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,155 +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
- }, $strip>;
33
- declare const TunnelSchema: ZodMiniObject<{
34
- id: ZodMiniString<string>;
35
- name: ZodMiniString<string>;
36
- account_tag: ZodMiniString<string>;
37
- created_at: ZodMiniString<string>;
38
- connections: ZodMiniOptional<ZodMiniArray<ZodMiniUnknown>>;
39
- }, $strip>;
40
- declare const DNSRecordSchema: ZodMiniObject<{
41
- id: ZodMiniString<string>;
42
- type: ZodMiniString<string>;
43
- name: ZodMiniString<string>;
44
- content: ZodMiniString<string>;
45
- proxied: ZodMiniBoolean<boolean>;
46
- comment: ZodMiniOptional<ZodMiniNullable<ZodMiniString<string>>>;
47
- }, $strip>;
48
- type CloudflareApiResponse<T = unknown> = output<typeof CloudflareApiResponseSchema> & {
49
- result: T;
50
- };
51
- type Account = output<typeof AccountSchema>;
52
- type Zone = output<typeof ZoneSchema>;
53
- type Tunnel = output<typeof TunnelSchema>;
54
- type DNSRecord = output<typeof DNSRecordSchema>;
55
- /**
56
- * Base configuration options shared between named and quick tunnel modes
57
- */
58
- interface BaseTunnelOptions {
59
- /**
60
- * Local port your dev server listens on
61
- * If not specified, will automatically use the bundler's configured port
62
- * @default undefined (auto-detect from bundler config)
63
- */
64
- port?: number;
65
- /**
66
- * Path to write cloudflared logs to a file
67
- * Useful for debugging tunnel issues
68
- */
69
- logFile?: string;
70
- /**
71
- * Log level for cloudflared process
72
- * @default undefined (uses cloudflared default)
73
- */
74
- logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'fatal';
75
- /**
76
- * Enable additional verbose logging for easier debugging.
77
- * When true, the plugin will output extra information prefixed with
78
- * `[cloudflare-tunnel:debug]`.
79
- * @default false
80
- */
81
- debug?: boolean;
82
- /**
83
- * Enable or disable the tunnel plugin. When set to `false` the plugin is
84
- * completely disabled — cloudflared will NOT be downloaded or started.
85
- * @default true
86
- */
87
- enabled?: boolean;
88
- }
89
- /**
90
- * Configuration options for named tunnel mode (requires hostname and API token)
91
- */
92
- interface NamedTunnelOptions extends BaseTunnelOptions {
93
- /**
94
- * Public hostname for the tunnel (e.g., "dev.example.com")
95
- * Must be a domain in your Cloudflare account
96
- */
97
- hostname: string;
98
- /**
99
- * Cloudflare API token with required permissions:
100
- * - Zone:Zone:Read
101
- * - Zone:DNS:Edit
102
- * - Account:Cloudflare Tunnel:Edit
103
- *
104
- * Fallback priority:
105
- * 1. Provided apiToken option
106
- * 2. CLOUDFLARE_API_TOKEN environment variable
107
- */
108
- apiToken?: string;
109
- /**
110
- * Cloudflare account ID
111
- * If omitted, uses the first account associated with the API token
112
- */
113
- accountId?: string;
114
- /**
115
- * Cloudflare zone ID
116
- * If omitted, automatically resolved from the hostname
117
- */
118
- zoneId?: string;
119
- /**
120
- * Name for the tunnel in your Cloudflare dashboard
121
- * Must contain only letters, numbers, and hyphens. Cannot start or end with a hyphen.
122
- * @default "dev-tunnel"
123
- */
124
- tunnelName?: string;
125
- /**
126
- * Wildcard DNS domain to ensure exists (e.g., "*.example.com").
127
- * When provided the plugin will ensure both A and AAAA records exist.
128
- */
129
- dns?: string;
130
- /**
131
- * Wildcard SSL domain to ensure exists (e.g., "*.example.com").
132
- * When provided the plugin will request/ensure a wildcard edge certificate.
133
- * If omitted the plugin will attempt to detect an existing wildcard certificate
134
- * or Total TLS; otherwise it will request a regular certificate for the provided hostname.
135
- */
136
- ssl?: string;
137
- /**
138
- * Cleanup configuration for managing orphaned resources
139
- */
140
- cleanup?: {
141
- /**
142
- * Whether to automatically clean up orphaned DNS records on startup
143
- * @default true
144
- */
145
- autoCleanup?: boolean;
146
- /**
147
- * Array of tunnel names to preserve during cleanup (in addition to current tunnel)
148
- * @default []
149
- */
150
- preserveTunnels?: Array<string>;
151
- };
152
- }
153
- /**
154
- * Configuration options for quick tunnel mode (no hostname required, generates random URL)
155
- */
156
- interface QuickTunnelOptions extends BaseTunnelOptions {}
157
- /**
158
- * Configuration options for the Cloudflare Tunnel plugin
159
- *
160
- * Two modes are supported:
161
- * - Named tunnel mode: Provide `hostname` for a persistent tunnel with custom domain
162
- * - Quick tunnel mode: Omit `hostname` for a temporary tunnel with random trycloudflare.com URL
163
- */
164
- type CloudflareTunnelOptions = NamedTunnelOptions | QuickTunnelOptions;
165
16
  declare const CloudflareTunnel: UnpluginInstance<CloudflareTunnelOptions | undefined, false>;
166
17
  //#endregion
167
- export { Account, CloudflareApiResponse, CloudflareTunnel, CloudflareTunnel as default, CloudflareTunnelOptions, DNSRecord, Tunnel, Zone };
18
+ export { CloudflareTunnel, CloudflareTunnel as default };