@pr0ger/vite-plugin-tailscale-funnel 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sergey Petrov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # @pr0ger/vite-plugin-tailscale-funnel
2
+
3
+ A Vite plugin that automatically starts [Tailscale Funnel](https://tailscale.com/kb/1223/tailscale-funnel/) or [Tailscale Serve](https://tailscale.com/kb/1312/serve/) when your dev server starts.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -D @pr0ger/vite-plugin-tailscale-funnel
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ // vite.config.ts
15
+ import { defineConfig } from 'vite';
16
+ import { tailscaleFunnel } from '@pr0ger/vite-plugin-tailscale-funnel';
17
+
18
+ export default defineConfig({
19
+ plugins: [
20
+ tailscaleFunnel(),
21
+ ],
22
+ });
23
+ ```
24
+
25
+ ## Options
26
+
27
+ | Option | Type | Default | Description |
28
+ |--------|------|---------|-------------|
29
+ | `hostname` | `string` | Auto-detected | Your Tailscale hostname (e.g., `laptop.tailnet1337.ts.net`) |
30
+ | `autoDetectHostname` | `boolean` | `true` | Automatically detect hostname from `tailscale status --json` |
31
+ | `port` | `number` | Vite's bound port | Port to expose via Funnel/Serve |
32
+ | `disabled` | `boolean` | `process.env.CI === 'true'` | Disable the plugin (useful for CI) |
33
+ | `mode` | `'funnel' \| 'serve'` | `'funnel'` | `funnel` = public internet, `serve` = local Tailnet only |
34
+
35
+ ## Examples
36
+
37
+ ### Basic usage with auto-detected hostname
38
+
39
+ ```ts
40
+ tailscaleFunnel()
41
+ ```
42
+
43
+ ### Explicit hostname
44
+
45
+ ```ts
46
+ tailscaleFunnel({
47
+ hostname: 'my-machine.tailnet-name.ts.net',
48
+ })
49
+ ```
50
+
51
+ ### Local network only (Tailscale Serve)
52
+
53
+ ```ts
54
+ tailscaleFunnel({
55
+ mode: 'serve',
56
+ })
57
+ ```
58
+
59
+ ### Custom port
60
+
61
+ ```ts
62
+ tailscaleFunnel({
63
+ port: 3000,
64
+ })
65
+ ```
66
+
67
+ ### Disable in specific environments
68
+
69
+ ```ts
70
+ tailscaleFunnel({
71
+ disabled: process.env.NODE_ENV === 'test',
72
+ })
73
+ ```
74
+
75
+ ## Requirements
76
+
77
+ - [Tailscale](https://tailscale.com/) must be installed and running
78
+ - For Funnel mode: Funnel must be enabled on your tailnet
79
+
80
+ ## License
81
+
82
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ default: () => tailscaleFunnel,
34
+ tailscaleFunnel: () => tailscaleFunnel
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+ var import_node_child_process = require("child_process");
38
+ var import_picocolors = __toESM(require("picocolors"), 1);
39
+ function getHostnameFromTailscale() {
40
+ try {
41
+ const output = (0, import_node_child_process.execSync)("tailscale status --json", { encoding: "utf-8" });
42
+ const status = JSON.parse(output);
43
+ return status.Self.DNSName.replace(/\.$/, "");
44
+ } catch {
45
+ return null;
46
+ }
47
+ }
48
+ function getExposedPort(server, configuredPort) {
49
+ if (configuredPort !== void 0) {
50
+ return configuredPort;
51
+ }
52
+ const address = server.httpServer?.address();
53
+ if (address && typeof address === "object") {
54
+ return address.port;
55
+ }
56
+ return server.config.server.port ?? 5173;
57
+ }
58
+ function killProcess(proc) {
59
+ if (proc && !proc.killed) {
60
+ proc.kill("SIGTERM");
61
+ }
62
+ }
63
+ function tailscaleFunnel(options = {}) {
64
+ let funnelProcess = null;
65
+ const disabled = options.disabled ?? process.env.CI === "true";
66
+ const mode = options.mode ?? "funnel";
67
+ const cleanup = () => {
68
+ killProcess(funnelProcess);
69
+ funnelProcess = null;
70
+ };
71
+ const setupSignalHandlers = () => {
72
+ process.on("SIGINT", () => {
73
+ cleanup();
74
+ process.exit(0);
75
+ });
76
+ process.on("SIGTERM", () => {
77
+ cleanup();
78
+ process.exit(0);
79
+ });
80
+ };
81
+ return {
82
+ name: "vite-plugin-tailscale-funnel",
83
+ apply: "serve",
84
+ configureServer(server) {
85
+ if (disabled) {
86
+ return;
87
+ }
88
+ let hostname = options.hostname;
89
+ if (!hostname && options.autoDetectHostname !== false) {
90
+ hostname = getHostnameFromTailscale() ?? void 0;
91
+ }
92
+ if (!hostname) {
93
+ console.warn(
94
+ import_picocolors.default.yellow("\n \u26A0 Could not detect Tailscale hostname. Set hostname option or ensure Tailscale is running.\n")
95
+ );
96
+ return;
97
+ }
98
+ server.httpServer?.once("listening", () => {
99
+ const port = getExposedPort(server, options.port);
100
+ const url = `https://${hostname}/`;
101
+ const modeLabel = mode === "funnel" ? "Funnel" : "Serve";
102
+ const modeIcon = mode === "funnel" ? "\u{1F310}" : "\u{1F512}";
103
+ console.log(
104
+ `
105
+ ${modeIcon} ${import_picocolors.default.cyan(`Tailscale ${modeLabel}`)} \u2192 ${import_picocolors.default.green(url)}
106
+ `
107
+ );
108
+ const command = mode === "funnel" ? "funnel" : "serve";
109
+ funnelProcess = (0, import_node_child_process.spawn)("tailscale", [command, `${port}`], {
110
+ stdio: "inherit",
111
+ detached: false
112
+ });
113
+ setupSignalHandlers();
114
+ funnelProcess.on("error", (err) => {
115
+ console.error(import_picocolors.default.red(`Failed to start Tailscale ${modeLabel}:`), err.message);
116
+ });
117
+ funnelProcess.on("exit", (code) => {
118
+ if (code !== 0 && code !== null) {
119
+ console.error(import_picocolors.default.red(`Tailscale ${modeLabel} exited with code ${code}`));
120
+ }
121
+ funnelProcess = null;
122
+ });
123
+ });
124
+ server.httpServer?.on("close", cleanup);
125
+ },
126
+ buildEnd() {
127
+ cleanup();
128
+ }
129
+ };
130
+ }
131
+ // Annotate the CommonJS export names for ESM import in node:
132
+ 0 && (module.exports = {
133
+ tailscaleFunnel
134
+ });
135
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {Plugin, ViteDevServer} from 'vite';\nimport {type ChildProcess, execSync, spawn} from 'node:child_process';\nimport pc from 'picocolors';\n\nexport interface TailscaleFunnelOptions {\n hostname?: string;\n autoDetectHostname?: boolean;\n port?: number;\n disabled?: boolean;\n mode?: 'funnel' | 'serve';\n}\n\ninterface TailscaleStatus {\n Self: {\n DNSName: string;\n };\n}\n\nfunction getHostnameFromTailscale(): string | null {\n try {\n const output = execSync('tailscale status --json', {encoding: 'utf-8'});\n const status: TailscaleStatus = JSON.parse(output);\n return status.Self.DNSName.replace(/\\.$/, '');\n } catch {\n return null;\n }\n}\n\nfunction getExposedPort(server: ViteDevServer, configuredPort?: number): number {\n if (configuredPort !== undefined) {\n return configuredPort;\n }\n\n const address = server.httpServer?.address();\n if (address && typeof address === 'object') {\n return address.port;\n }\n\n return server.config.server.port ?? 5173;\n}\n\nfunction killProcess(proc: ChildProcess | null): void {\n if (proc && !proc.killed) {\n proc.kill('SIGTERM');\n }\n}\n\nexport default function tailscaleFunnel(options: TailscaleFunnelOptions = {}): Plugin {\n let funnelProcess: ChildProcess | null = null;\n const disabled = options.disabled ?? process.env.CI === 'true';\n const mode = options.mode ?? 'funnel';\n\n const cleanup = () => {\n killProcess(funnelProcess);\n funnelProcess = null;\n };\n\n const setupSignalHandlers = () => {\n process.on('SIGINT', () => {\n cleanup();\n process.exit(0);\n });\n process.on('SIGTERM', () => {\n cleanup();\n process.exit(0);\n });\n };\n\n return {\n name: 'vite-plugin-tailscale-funnel',\n apply: 'serve',\n\n configureServer(server: ViteDevServer) {\n if (disabled) {\n return;\n }\n\n let hostname = options.hostname;\n if (!hostname && options.autoDetectHostname !== false) {\n hostname = getHostnameFromTailscale() ?? undefined;\n }\n\n if (!hostname) {\n console.warn(\n pc.yellow('\\n ⚠ Could not detect Tailscale hostname. Set hostname option or ensure Tailscale is running.\\n')\n );\n return;\n }\n\n server.httpServer?.once('listening', () => {\n const port = getExposedPort(server, options.port);\n const url = `https://${hostname}/`;\n const modeLabel = mode === 'funnel' ? 'Funnel' : 'Serve';\n const modeIcon = mode === 'funnel' ? '🌐' : '🔒';\n\n console.log(\n `\\n ${modeIcon} ${pc.cyan(`Tailscale ${modeLabel}`)} → ${pc.green(url)}\\n`\n );\n\n const command = mode === 'funnel' ? 'funnel' : 'serve';\n funnelProcess = spawn('tailscale', [command, `${port}`], {\n stdio: 'inherit',\n detached: false,\n });\n\n setupSignalHandlers();\n\n funnelProcess.on('error', (err: Error) => {\n console.error(pc.red(`Failed to start Tailscale ${modeLabel}:`), err.message);\n });\n\n funnelProcess.on('exit', (code: number | null) => {\n if (code !== 0 && code !== null) {\n console.error(pc.red(`Tailscale ${modeLabel} exited with code ${code}`));\n }\n funnelProcess = null;\n });\n });\n\n server.httpServer?.on('close', cleanup);\n },\n\n buildEnd() {\n cleanup();\n },\n };\n}\n\nexport { tailscaleFunnel };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,gCAAiD;AACjD,wBAAe;AAgBf,SAAS,2BAA0C;AACjD,MAAI;AACF,UAAM,aAAS,oCAAS,2BAA2B,EAAC,UAAU,QAAO,CAAC;AACtE,UAAM,SAA0B,KAAK,MAAM,MAAM;AACjD,WAAO,OAAO,KAAK,QAAQ,QAAQ,OAAO,EAAE;AAAA,EAC9C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,eAAe,QAAuB,gBAA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,WAAW,cAAO;AAE5C,gBAAQ;AAAA,UACN;AAAA,IAAO,QAAQ,IAAI,kBAAAA,QAAG,KAAK,aAAa,SAAS,EAAE,CAAC,WAAM,kBAAAA,QAAG,MAAM,GAAG,CAAC;AAAA;AAAA,QACzE;AAEA,cAAM,UAAU,SAAS,WAAW,WAAW;AAC/C,4BAAgB,iCAAM,aAAa,CAAC,SAAS,GAAG,IAAI,EAAE,GAAG;AAAA,UACvD,OAAO;AAAA,UACP,UAAU;AAAA,QACZ,CAAC;AAED,4BAAoB;AAEpB,sBAAc,GAAG,SAAS,CAAC,QAAe;AACxC,kBAAQ,MAAM,kBAAAA,QAAG,IAAI,6BAA6B,SAAS,GAAG,GAAG,IAAI,OAAO;AAAA,QAC9E,CAAC;AAED,sBAAc,GAAG,QAAQ,CAAC,SAAwB;AAChD,cAAI,SAAS,KAAK,SAAS,MAAM;AAC/B,oBAAQ,MAAM,kBAAAA,QAAG,IAAI,aAAa,SAAS,qBAAqB,IAAI,EAAE,CAAC;AAAA,UACzE;AACA,0BAAgB;AAAA,QAClB,CAAC;AAAA,MACH,CAAC;AAED,aAAO,YAAY,GAAG,SAAS,OAAO;AAAA,IACxC;AAAA,IAEA,WAAW;AACT,cAAQ;AAAA,IACV;AAAA,EACF;AACF;","names":["pc"]}
@@ -0,0 +1,12 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface TailscaleFunnelOptions {
4
+ hostname?: string;
5
+ autoDetectHostname?: boolean;
6
+ port?: number;
7
+ disabled?: boolean;
8
+ mode?: 'funnel' | 'serve';
9
+ }
10
+ declare function tailscaleFunnel(options?: TailscaleFunnelOptions): Plugin;
11
+
12
+ export { type TailscaleFunnelOptions, tailscaleFunnel as default, tailscaleFunnel };
@@ -0,0 +1,12 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface TailscaleFunnelOptions {
4
+ hostname?: string;
5
+ autoDetectHostname?: boolean;
6
+ port?: number;
7
+ disabled?: boolean;
8
+ mode?: 'funnel' | 'serve';
9
+ }
10
+ declare function tailscaleFunnel(options?: TailscaleFunnelOptions): Plugin;
11
+
12
+ export { type TailscaleFunnelOptions, tailscaleFunnel as default, tailscaleFunnel };
package/dist/index.js ADDED
@@ -0,0 +1,100 @@
1
+ // src/index.ts
2
+ import { execSync, spawn } from "child_process";
3
+ import pc from "picocolors";
4
+ function getHostnameFromTailscale() {
5
+ try {
6
+ const output = execSync("tailscale status --json", { encoding: "utf-8" });
7
+ const status = JSON.parse(output);
8
+ return status.Self.DNSName.replace(/\.$/, "");
9
+ } catch {
10
+ return null;
11
+ }
12
+ }
13
+ function getExposedPort(server, configuredPort) {
14
+ if (configuredPort !== void 0) {
15
+ return configuredPort;
16
+ }
17
+ const address = server.httpServer?.address();
18
+ if (address && typeof address === "object") {
19
+ return address.port;
20
+ }
21
+ return server.config.server.port ?? 5173;
22
+ }
23
+ function killProcess(proc) {
24
+ if (proc && !proc.killed) {
25
+ proc.kill("SIGTERM");
26
+ }
27
+ }
28
+ function tailscaleFunnel(options = {}) {
29
+ let funnelProcess = null;
30
+ const disabled = options.disabled ?? process.env.CI === "true";
31
+ const mode = options.mode ?? "funnel";
32
+ const cleanup = () => {
33
+ killProcess(funnelProcess);
34
+ funnelProcess = null;
35
+ };
36
+ const setupSignalHandlers = () => {
37
+ process.on("SIGINT", () => {
38
+ cleanup();
39
+ process.exit(0);
40
+ });
41
+ process.on("SIGTERM", () => {
42
+ cleanup();
43
+ process.exit(0);
44
+ });
45
+ };
46
+ return {
47
+ name: "vite-plugin-tailscale-funnel",
48
+ apply: "serve",
49
+ configureServer(server) {
50
+ if (disabled) {
51
+ return;
52
+ }
53
+ let hostname = options.hostname;
54
+ if (!hostname && options.autoDetectHostname !== false) {
55
+ hostname = getHostnameFromTailscale() ?? void 0;
56
+ }
57
+ if (!hostname) {
58
+ console.warn(
59
+ pc.yellow("\n \u26A0 Could not detect Tailscale hostname. Set hostname option or ensure Tailscale is running.\n")
60
+ );
61
+ return;
62
+ }
63
+ server.httpServer?.once("listening", () => {
64
+ const port = getExposedPort(server, options.port);
65
+ const url = `https://${hostname}/`;
66
+ const modeLabel = mode === "funnel" ? "Funnel" : "Serve";
67
+ const modeIcon = mode === "funnel" ? "\u{1F310}" : "\u{1F512}";
68
+ console.log(
69
+ `
70
+ ${modeIcon} ${pc.cyan(`Tailscale ${modeLabel}`)} \u2192 ${pc.green(url)}
71
+ `
72
+ );
73
+ const command = mode === "funnel" ? "funnel" : "serve";
74
+ funnelProcess = spawn("tailscale", [command, `${port}`], {
75
+ stdio: "inherit",
76
+ detached: false
77
+ });
78
+ setupSignalHandlers();
79
+ funnelProcess.on("error", (err) => {
80
+ console.error(pc.red(`Failed to start Tailscale ${modeLabel}:`), err.message);
81
+ });
82
+ funnelProcess.on("exit", (code) => {
83
+ if (code !== 0 && code !== null) {
84
+ console.error(pc.red(`Tailscale ${modeLabel} exited with code ${code}`));
85
+ }
86
+ funnelProcess = null;
87
+ });
88
+ });
89
+ server.httpServer?.on("close", cleanup);
90
+ },
91
+ buildEnd() {
92
+ cleanup();
93
+ }
94
+ };
95
+ }
96
+ export {
97
+ tailscaleFunnel as default,
98
+ tailscaleFunnel
99
+ };
100
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {Plugin, ViteDevServer} from 'vite';\nimport {type ChildProcess, execSync, spawn} from 'node:child_process';\nimport pc from 'picocolors';\n\nexport interface TailscaleFunnelOptions {\n hostname?: string;\n autoDetectHostname?: boolean;\n port?: number;\n disabled?: boolean;\n mode?: 'funnel' | 'serve';\n}\n\ninterface TailscaleStatus {\n Self: {\n DNSName: string;\n };\n}\n\nfunction getHostnameFromTailscale(): string | null {\n try {\n const output = execSync('tailscale status --json', {encoding: 'utf-8'});\n const status: TailscaleStatus = JSON.parse(output);\n return status.Self.DNSName.replace(/\\.$/, '');\n } catch {\n return null;\n }\n}\n\nfunction getExposedPort(server: ViteDevServer, configuredPort?: number): number {\n if (configuredPort !== undefined) {\n return configuredPort;\n }\n\n const address = server.httpServer?.address();\n if (address && typeof address === 'object') {\n return address.port;\n }\n\n return server.config.server.port ?? 5173;\n}\n\nfunction killProcess(proc: ChildProcess | null): void {\n if (proc && !proc.killed) {\n proc.kill('SIGTERM');\n }\n}\n\nexport default function tailscaleFunnel(options: TailscaleFunnelOptions = {}): Plugin {\n let funnelProcess: ChildProcess | null = null;\n const disabled = options.disabled ?? process.env.CI === 'true';\n const mode = options.mode ?? 'funnel';\n\n const cleanup = () => {\n killProcess(funnelProcess);\n funnelProcess = null;\n };\n\n const setupSignalHandlers = () => {\n process.on('SIGINT', () => {\n cleanup();\n process.exit(0);\n });\n process.on('SIGTERM', () => {\n cleanup();\n process.exit(0);\n });\n };\n\n return {\n name: 'vite-plugin-tailscale-funnel',\n apply: 'serve',\n\n configureServer(server: ViteDevServer) {\n if (disabled) {\n return;\n }\n\n let hostname = options.hostname;\n if (!hostname && options.autoDetectHostname !== false) {\n hostname = getHostnameFromTailscale() ?? undefined;\n }\n\n if (!hostname) {\n console.warn(\n pc.yellow('\\n ⚠ Could not detect Tailscale hostname. Set hostname option or ensure Tailscale is running.\\n')\n );\n return;\n }\n\n server.httpServer?.once('listening', () => {\n const port = getExposedPort(server, options.port);\n const url = `https://${hostname}/`;\n const modeLabel = mode === 'funnel' ? 'Funnel' : 'Serve';\n const modeIcon = mode === 'funnel' ? '🌐' : '🔒';\n\n console.log(\n `\\n ${modeIcon} ${pc.cyan(`Tailscale ${modeLabel}`)} → ${pc.green(url)}\\n`\n );\n\n const command = mode === 'funnel' ? 'funnel' : 'serve';\n funnelProcess = spawn('tailscale', [command, `${port}`], {\n stdio: 'inherit',\n detached: false,\n });\n\n setupSignalHandlers();\n\n funnelProcess.on('error', (err: Error) => {\n console.error(pc.red(`Failed to start Tailscale ${modeLabel}:`), err.message);\n });\n\n funnelProcess.on('exit', (code: number | null) => {\n if (code !== 0 && code !== null) {\n console.error(pc.red(`Tailscale ${modeLabel} exited with code ${code}`));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in-tailscale-funnel",
3
+ "version": "0.1.0",
4
+ "description": "Vite plugin that starts Tailscale Funnel or Serve when the dev server starts",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "scripts": {
28
+ "build": "tsup",
29
+ "dev": "tsup --watch",
30
+ "prepublishOnly": "bun run build"
31
+ },
32
+ "keywords": [
33
+ "vite",
34
+ "vite-plugin",
35
+ "tailscale",
36
+ "funnel",
37
+ "tunnel",
38
+ "dev-server"
39
+ ],
40
+ "author": "Sergey Petrov",
41
+ "license": "MIT",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/Pr0Ger/vite-plugin-tailscale-funnel.git"
45
+ },
46
+ "peerDependencies": {
47
+ "vite": ">=4.0.0"
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "^25.0.9",
51
+ "tsup": "^8.0.0",
52
+ "typescript": "^5.0.0",
53
+ "vite": "^6.0.0"
54
+ },
55
+ "dependencies": {
56
+ "picocolors": "^1.0.0"
57
+ }
58
+ }