unplugin-cloudflare-tunnel 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.
@@ -0,0 +1,141 @@
1
+ # unplugin-cloudflare-tunnel
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)
5
+
6
+ A plugin that automatically creates and manages Cloudflare tunnels for local development.
7
+ Available for:
8
+
9
+ - [Vite](https://vite.dev),
10
+ - [Rspack](https://rspack.rs)
11
+ - [Webpack](https://webpack.js.org)
12
+ - [Astro](https://astro.build) <sup>soon</sup>
13
+ - [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
+
18
+ > [!NOTE]
19
+ > This is under active development.
20
+ > If you have any suggestions, I'm all ears, please open an issue.
21
+
22
+ ## Install
23
+
24
+ unplugin-cloudflare-tunnel
25
+
26
+ ```bash
27
+ npm add unplugin-cloudflare-tunnel
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ <details>
33
+ <summary>Vite</summary><br>
34
+
35
+ ```ts
36
+ // vite.config.ts
37
+ import CloudflareTunnel from 'unplugin-cloudflare-tunnel/vite'
38
+
39
+ export default defineConfig({
40
+ plugins: [
41
+ CloudflareTunnel(),
42
+ ],
43
+ })
44
+ ```
45
+
46
+ Example in [./example/vite.config.ts](../example/vite.config.ts): `bun --filter example dev:vite`
47
+
48
+ <br></details>
49
+
50
+ <details>
51
+ <summary>Rspack</summary><br>
52
+
53
+ ```ts
54
+ // rspack.config.mjs
55
+ import CloudflareTunnel from 'unplugin-cloudflare-tunnel/rspack'
56
+
57
+ export default {
58
+ /* ... */
59
+ plugins: [
60
+ CloudflareTunnel(),
61
+ ]
62
+ }
63
+ ```
64
+
65
+ Example in [./example/rspack.config.ts](../example/rspack.config.ts): `bun --filter example dev:rspack`
66
+
67
+ <br></details>
68
+
69
+ <details>
70
+ <summary>Webpack</summary><br>
71
+
72
+ ```ts
73
+ // webpack.config.js
74
+ module.exports = {
75
+ /* ... */
76
+ plugins: [
77
+ require('unplugin-cloudflare-tunnel/webpack')({
78
+ CloudflareTunnel(),
79
+ ]
80
+ }
81
+ ```
82
+
83
+ Example in [./example/webpack.config.ts](../example/webpack.config.ts): `bun --filter example dev:webpack`
84
+
85
+ <br></details>
86
+
87
+ ## Virtual Module: Access Tunnel URL
88
+
89
+ > [!NOTE]
90
+ > This feature is only available in Vite and Vite-based frameworks (i.e., Astro)
91
+
92
+ 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
+
94
+ - Displaying the tunnel URL in your UI
95
+ - Sharing the URL with users
96
+ - Debugging and logging
97
+ - Building features that need the public URL
98
+
99
+ ### Usage
100
+
101
+ ```typescript
102
+ import { getTunnelUrl } from 'virtual:unplugin-cloudflare-tunnel'
103
+
104
+ // Get the current tunnel URL
105
+ const tunnelUrl = getTunnelUrl()
106
+ console.log('Public tunnel URL:', tunnelUrl)
107
+
108
+ // Example: Copy tunnel URL to clipboard
109
+ const shareButton = document.getElementById('share')
110
+ shareButton.onclick = () => {
111
+ navigator.clipboard.writeText(getTunnelUrl())
112
+ alert('Tunnel URL copied!')
113
+ }
114
+ ```
115
+
116
+ ### TypeScript Support
117
+
118
+ To get TypeScript support for the virtual module, add a reference to the types:
119
+
120
+ ```typescript
121
+ // In your tsconfig.json or a .d.ts file
122
+ /// <reference types="unplugin-cloudflare-tunnel/virtual" />
123
+ ```
124
+
125
+ Or create a `virtual.d.ts` file in your project:
126
+
127
+ ```typescript
128
+ /// <reference types="unplugin-cloudflare-tunnel/virtual" />
129
+ ```
130
+
131
+ ### Return Value
132
+
133
+ - **Quick tunnel mode**: Returns a random URL like `https://abc-123.trycloudflare.com`
134
+ - **Named tunnel mode**: Returns your custom domain URL like `https://dev.example.com`
135
+ - **Plugin disabled**: Returns an empty string `""`
136
+
137
+ ### Notes
138
+
139
+ - The virtual module is only available during development mode
140
+ - In production builds, the virtual module will not be available
141
+ - The URL is automatically updated if the port changes or tunnel restarts
package/dist/astro.d.mts CHANGED
@@ -1,25 +1,6 @@
1
+ import { CloudflareTunnelOptions } from "./index.mjs";
2
+
1
3
  //#region src/astro.d.ts
2
- /**
3
- * This entry file is for Astro plugin.
4
- *
5
- * @module
6
- */
7
- /**
8
- * TODO: figure out how to import the Astro plugin
9
- */
10
- /**
11
- * Astro plugin
12
- *
13
- * @example
14
- * ```ts
15
- * // astro.config.ts
16
- * import CloudflareTunnel from 'unplugin-cloudflare-tunnel/astro'
17
- *
18
- * export default defineConfig({
19
- * plugins: [CloudflareTunnel()],
20
- * })
21
- * ```
22
- */
23
- declare const astro: never;
4
+ declare const _default: (options: CloudflareTunnelOptions) => any;
24
5
  //#endregion
25
- export { astro as default, astro as "module.exports" };
6
+ export { _default as default };
package/dist/astro.mjs CHANGED
@@ -1,27 +1,13 @@
1
+ import src_default from "./index.mjs";
2
+
1
3
  //#region src/astro.ts
2
- /**
3
- * This entry file is for Astro plugin.
4
- *
5
- * @module
6
- */
7
- /**
8
- * TODO: figure out how to import the Astro plugin
9
- */
10
- /**
11
- * Astro plugin
12
- *
13
- * @example
14
- * ```ts
15
- * // astro.config.ts
16
- * import CloudflareTunnel from 'unplugin-cloudflare-tunnel/astro'
17
- *
18
- * export default defineConfig({
19
- * plugins: [CloudflareTunnel()],
20
- * })
21
- * ```
22
- */
23
- const astro = {};
24
- var astro_default = astro;
4
+ var astro_default = (options) => ({
5
+ name: "unplugin-cloudflare-tunnel",
6
+ hooks: { "astro:config:setup": async (astro) => {
7
+ astro.config.vite.plugins ||= [];
8
+ astro.config.vite.plugins.push(src_default.vite(options));
9
+ } }
10
+ });
25
11
 
26
12
  //#endregion
27
- export { astro_default as default, astro as "module.exports" };
13
+ export { astro_default as default };
@@ -1,7 +1,13 @@
1
- import { CloudflareTunnel } from "./index.mjs";
1
+ import { CloudflareTunnelOptions } from "./index.mjs";
2
+ import * as esbuild0 from "esbuild";
2
3
 
3
4
  //#region src/esbuild.d.ts
4
5
 
6
+ /**
7
+ * This entry file is for esbuild plugin.
8
+ *
9
+ * @module
10
+ */
5
11
  /**
6
12
  * Esbuild plugin
7
13
  *
@@ -13,6 +19,6 @@ import { CloudflareTunnel } from "./index.mjs";
13
19
  * build({ plugins: [Starter()] })
14
20
  ```
15
21
  */
16
- declare const esbuild: typeof CloudflareTunnel.esbuild;
22
+ declare const esbuild: (options?: CloudflareTunnelOptions | undefined) => esbuild0.Plugin;
17
23
  //#endregion
18
24
  export { esbuild as default, esbuild as "module.exports" };
package/dist/farm.d.mts CHANGED
@@ -1,7 +1,12 @@
1
- import { CloudflareTunnel } from "./index.mjs";
1
+ import { CloudflareTunnelOptions } from "./index.mjs";
2
2
 
3
3
  //#region src/farm.d.ts
4
4
 
5
+ /**
6
+ * This entry file is for Farm plugin.
7
+ *
8
+ * @module
9
+ */
5
10
  /**
6
11
  * Farm plugin
7
12
  *
@@ -15,6 +20,6 @@ import { CloudflareTunnel } from "./index.mjs";
15
20
  * }
16
21
  * ```
17
22
  */
18
- declare const farm: typeof CloudflareTunnel.farm;
23
+ declare const farm: (options?: CloudflareTunnelOptions | undefined) => JsPlugin;
19
24
  //#endregion
20
25
  export { farm as default, farm as "module.exports" };
@@ -1,7 +1,13 @@
1
- import { CloudflareTunnel } from "./index.mjs";
1
+ import { CloudflareTunnelOptions } from "./index.mjs";
2
+ import * as rolldown0 from "rolldown";
2
3
 
3
4
  //#region src/rolldown.d.ts
4
5
 
6
+ /**
7
+ * This entry file is for Rolldown plugin.
8
+ *
9
+ * @module
10
+ */
5
11
  /**
6
12
  * Rolldown plugin
7
13
  *
@@ -15,6 +21,6 @@ import { CloudflareTunnel } from "./index.mjs";
15
21
  * }
16
22
  * ```
17
23
  */
18
- declare const rolldown: typeof CloudflareTunnel.rolldown;
24
+ declare const rolldown: (options?: CloudflareTunnelOptions | undefined) => rolldown0.Plugin<any>;
19
25
  //#endregion
20
26
  export { rolldown as default, rolldown as "module.exports" };
package/dist/rollup.d.mts CHANGED
@@ -1,7 +1,13 @@
1
- import { CloudflareTunnel } from "./index.mjs";
1
+ import { CloudflareTunnelOptions } from "./index.mjs";
2
+ import * as rollup0 from "rollup";
2
3
 
3
4
  //#region src/rollup.d.ts
4
5
 
6
+ /**
7
+ * This entry file is for Rollup plugin.
8
+ *
9
+ * @module
10
+ */
5
11
  /**
6
12
  * Rollup plugin
7
13
  *
@@ -15,6 +21,6 @@ import { CloudflareTunnel } from "./index.mjs";
15
21
  * }
16
22
  * ```
17
23
  */
18
- declare const rollup: typeof CloudflareTunnel.rollup;
24
+ declare const rollup: (options?: CloudflareTunnelOptions | undefined) => rollup0.Plugin<any>;
19
25
  //#endregion
20
26
  export { rollup as default, rollup as "module.exports" };
package/dist/rspack.d.mts CHANGED
@@ -1,7 +1,13 @@
1
- import { CloudflareTunnel } from "./index.mjs";
1
+ import { CloudflareTunnelOptions } from "./index.mjs";
2
+ import * as unplugin0 from "unplugin";
2
3
 
3
4
  //#region src/rspack.d.ts
4
5
 
6
+ /**
7
+ * This entry file is for Rspack plugin.
8
+ *
9
+ * @module
10
+ */
5
11
  /**
6
12
  * Rspack plugin
7
13
  *
@@ -15,6 +21,6 @@ import { CloudflareTunnel } from "./index.mjs";
15
21
  * }
16
22
  * ```
17
23
  */
18
- declare const rspack: typeof CloudflareTunnel.rspack;
24
+ declare const rspack: (options?: CloudflareTunnelOptions | undefined) => unplugin0.RspackPluginInstance;
19
25
  //#endregion
20
26
  export { rspack as default, rspack as "module.exports" };
package/dist/vite.d.mts CHANGED
@@ -1,7 +1,13 @@
1
- import { CloudflareTunnel } from "./index.mjs";
1
+ import { CloudflareTunnelOptions } from "./index.mjs";
2
+ import * as vite0 from "vite";
2
3
 
3
4
  //#region src/vite.d.ts
4
5
 
6
+ /**
7
+ * This entry file is for Vite plugin.
8
+ *
9
+ * @module
10
+ */
5
11
  /**
6
12
  * Vite plugin
7
13
  *
@@ -15,6 +21,6 @@ import { CloudflareTunnel } from "./index.mjs";
15
21
  * })
16
22
  * ```
17
23
  */
18
- declare const vite: typeof CloudflareTunnel.vite;
24
+ declare const vite: (options?: CloudflareTunnelOptions | undefined) => vite0.Plugin<any>;
19
25
  //#endregion
20
26
  export { vite as default, vite as "module.exports" };
@@ -1,7 +1,13 @@
1
- import { CloudflareTunnel } from "./index.mjs";
1
+ import { CloudflareTunnelOptions } from "./index.mjs";
2
+ import * as webpack0 from "webpack";
2
3
 
3
4
  //#region src/webpack.d.ts
4
5
 
6
+ /**
7
+ * This entry file is for webpack plugin.
8
+ *
9
+ * @module
10
+ */
5
11
  /**
6
12
  * Webpack plugin
7
13
  *
@@ -15,6 +21,6 @@ import { CloudflareTunnel } from "./index.mjs";
15
21
  * }
16
22
  * ```
17
23
  */
18
- declare const webpack: typeof CloudflareTunnel.webpack;
24
+ declare const webpack: (options?: CloudflareTunnelOptions | undefined) => webpack0.WebpackPluginInstance;
19
25
  //#endregion
20
26
  export { webpack as default, webpack as "module.exports" };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unplugin-cloudflare-tunnel",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "A plugin that automatically creates and manages Cloudflare tunnels for local development",
5
5
  "type": "module",
6
6
  "imports": {
@@ -9,7 +9,9 @@
9
9
  },
10
10
  "files": [
11
11
  "dist",
12
- "package.json"
12
+ "LICENSE",
13
+ "package.json",
14
+ "./.github/README.md"
13
15
  ],
14
16
  "main": "./dist/index.mjs",
15
17
  "module": "./dist/index.mjs",
@@ -66,6 +68,7 @@
66
68
  "tsx": "^4.21.0",
67
69
  "typescript": "^5.9.3",
68
70
  "unplugin-unused": "^0.5.6",
71
+ "unplugin-utils": "^0.3.1",
69
72
  "vite": "^7.3.0",
70
73
  "vitest": "^4.0.16",
71
74
  "webpack-dev-server": "^5.2.2",
@@ -106,12 +109,6 @@
106
109
  "optional": true
107
110
  }
108
111
  },
109
- "resolutions": {
110
- "zod": "^4.3.3"
111
- },
112
- "overrides": {
113
- "zod": "^4.3.3"
114
- },
115
112
  "engines": {
116
113
  "node": ">=20.0"
117
114
  },