vite-plugin-online-debug 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024
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,90 @@
1
+ # Vite Plugin Template
2
+
3
+ A template for creating Vite plugins with TypeScript, testing, and publishing setup.
4
+
5
+ ## Features
6
+
7
+ - 📦 TypeScript support with type definitions
8
+ - 🧪 Testing with Vitest
9
+ - 📦 Dual CJS/ESM build with tsup
10
+ - 🔍 ESLint configuration
11
+ - 📚 Ready for npm publishing
12
+ - 🎯 Example plugin implementation
13
+
14
+ ## Usage
15
+
16
+ ### Installation
17
+
18
+ ```bash
19
+ npm install vite-plugin-template
20
+ ```
21
+
22
+ ### Basic Usage
23
+
24
+ ```typescript
25
+ // vite.config.ts
26
+ import { defineConfig } from 'vite'
27
+ import templatePlugin from 'vite-plugin-template'
28
+
29
+ export default defineConfig({
30
+ plugins: [
31
+ templatePlugin({
32
+ example: true
33
+ })
34
+ ]
35
+ })
36
+ ```
37
+
38
+ ## Development
39
+
40
+ ### Setup
41
+
42
+ ```bash
43
+ # Clone this template
44
+ git clone https://github.com/yourusername/vite-plugin-template.git
45
+ cd vite-plugin-template
46
+
47
+ # Install dependencies
48
+ npm install
49
+
50
+ # Start development
51
+ npm run dev
52
+ ```
53
+
54
+ ### Scripts
55
+
56
+ - `npm run dev` - Build in watch mode
57
+ - `npm run build` - Build the plugin
58
+ - `npm run test` - Run tests
59
+ - `npm run test:ui` - Run tests with UI
60
+ - `npm run lint` - Run ESLint
61
+ - `npm run lint:fix` - Fix ESLint issues
62
+ - `npm run prepublishOnly` - Build and test before publishing
63
+
64
+ ### Publishing to npm
65
+
66
+ 1. Update `package.json` with your plugin details
67
+ 2. Update the repository URL in `package.json`
68
+ 3. Run `npm run build && npm test`
69
+ 4. Publish with `npm publish`
70
+
71
+ ## Plugin Development
72
+
73
+ Your plugin's main logic goes in `src/index.ts`. The template includes:
74
+
75
+ - Plugin options interface
76
+ - Basic plugin structure with common hooks
77
+ - Example transformation logic
78
+ - Type safety with TypeScript
79
+
80
+ ### Testing
81
+
82
+ Write your tests in the `tests/` directory. The template includes example tests that demonstrate:
83
+
84
+ - Plugin creation
85
+ - Option handling
86
+ - Transformation logic
87
+
88
+ ## License
89
+
90
+ MIT
@@ -0,0 +1,13 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface PluginOptions {
4
+ /**
5
+ * @host 本地服务host,默认 127.0.0.1
6
+ * @entry 应用入口文件,默认 /src/main.js
7
+ */
8
+ host?: boolean;
9
+ entry?: string;
10
+ }
11
+ declare function createPlugin(options?: PluginOptions): Plugin;
12
+
13
+ export { PluginOptions, createPlugin as default };
@@ -0,0 +1,13 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface PluginOptions {
4
+ /**
5
+ * @host 本地服务host,默认 127.0.0.1
6
+ * @entry 应用入口文件,默认 /src/main.js
7
+ */
8
+ host?: boolean;
9
+ entry?: string;
10
+ }
11
+ declare function createPlugin(options?: PluginOptions): Plugin;
12
+
13
+ export { PluginOptions, createPlugin as default };
package/dist/index.js ADDED
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ default: () => createPlugin
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+ function createPlugin(options = {}) {
27
+ const {
28
+ host = "127.0.0.1",
29
+ entry = "/src/main.js"
30
+ } = options;
31
+ return {
32
+ name: "vite-plugin-online-debug",
33
+ apply: "build",
34
+ transform(code, id) {
35
+ if (id.includes("/src/main.js")) {
36
+ const environmentCheckCode = `
37
+ ${code}
38
+ function loadScript(src, options = {}) {
39
+ return new Promise((resolve, reject) => {
40
+ // \u9A8C\u8BC1\u8F93\u5165\u53C2\u6570
41
+ if (!src) {
42
+ reject(new Error('\u811A\u672CURL\u4E0D\u80FD\u4E3A\u7A7A'));
43
+ return;
44
+ }
45
+
46
+ // \u8BBE\u7F6E\u9ED8\u8BA4\u9009\u9879
47
+ const defaultOptions = {
48
+ async: true,
49
+ defer: false,
50
+ type: 'text/javascript',
51
+ charset: 'utf-8'
52
+ };
53
+
54
+ // \u5408\u5E76\u9009\u9879
55
+ const config = Object.assign(defaultOptions, options);
56
+ console.log("\u{1F680} ~ loadScript ~ config:", config)
57
+
58
+ // \u521B\u5EFAscript\u6807\u7B7E
59
+ const script = document.createElement('script');
60
+ script.src = src;
61
+ script.async = config.async;
62
+ script.defer = config.defer;
63
+ script.type = config.type;
64
+ script.charset = config.charset;
65
+
66
+ // \u76D1\u542C\u52A0\u8F7D\u6210\u529F\u4E8B\u4EF6
67
+ script.onload = function() {
68
+ resolve(script);
69
+ };
70
+
71
+ // \u76D1\u542C\u52A0\u8F7D\u5931\u8D25\u4E8B\u4EF6
72
+ script.onerror = function() {
73
+ reject(new Error('\u811A\u672C\u52A0\u8F7D\u5931\u8D25:' + src));
74
+ };
75
+
76
+ // \u6DFB\u52A0\u5230\u9875\u9762\u4E2D
77
+ document.head.appendChild(script);
78
+ });
79
+ }
80
+ // \u73AF\u5883\u68C0\u6D4B\u903B\u8F91
81
+ if (import.meta.env.PROD && window.location.search?.indexOf('_debug_') > -1) {
82
+ // \u751F\u4EA7\u73AF\u5883\u903B\u8F91
83
+ const params = new URLSearchParams(window.location?.search || '');
84
+ const port = params.get('_debug_') || '8080';
85
+ const res = document.querySelector('#app');
86
+ res.__vue_app__?.unmount()
87
+ loadScript('http://${host}' + ':' + port + '${entry}', { type: 'module' })
88
+ }
89
+ `;
90
+ return environmentCheckCode;
91
+ }
92
+ return code;
93
+ },
94
+ buildStart() {
95
+ console.log("online-debug build started");
96
+ },
97
+ generateBundle() {
98
+ console.log("online-debug generating bundle");
99
+ }
100
+ };
101
+ }
102
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Plugin } from 'vite'\n\nexport interface PluginOptions {\n /**\n * @host 本地服务host,默认 127.0.0.1\n * @entry 应用入口文件,默认 /src/main.js\n */\n host?: boolean,\n entry?: string,\n}\n\nexport default function createPlugin(options: PluginOptions = {}): Plugin {\n const {\n host = '127.0.0.1',\n entry = '/src/main.js'\n } = options;\n return {\n name: 'vite-plugin-online-debug',\n apply: 'build',\n \n transform(code: string, id: string) {\n if (id.includes('/src/main.js')) {\n \n const environmentCheckCode = `\n ${code}\n function loadScript(src, options = {}) {\n return new Promise((resolve, reject) => {\n // 验证输入参数\n if (!src) {\n reject(new Error('脚本URL不能为空'));\n return;\n }\n \n // 设置默认选项\n const defaultOptions = {\n async: true,\n defer: false,\n type: 'text/javascript',\n charset: 'utf-8'\n };\n \n // 合并选项\n const config = Object.assign(defaultOptions, options);\n console.log(\"🚀 ~ loadScript ~ config:\", config)\n \n // 创建script标签\n const script = document.createElement('script');\n script.src = src;\n script.async = config.async;\n script.defer = config.defer;\n script.type = config.type;\n script.charset = config.charset;\n \n // 监听加载成功事件\n script.onload = function() {\n resolve(script);\n };\n \n // 监听加载失败事件\n script.onerror = function() {\n reject(new Error('脚本加载失败:' + src));\n };\n \n // 添加到页面中\n document.head.appendChild(script);\n });\n }\n // 环境检测逻辑\n if (import.meta.env.PROD && window.location.search?.indexOf('_debug_') > -1) {\n // 生产环境逻辑\n const params = new URLSearchParams(window.location?.search || '');\n const port = params.get('_debug_') || '8080';\n const res = document.querySelector('#app');\n res.__vue_app__?.unmount()\n loadScript('http://${host}' + ':' + port + '${entry}', { type: 'module' })\n }\n `;\n return environmentCheckCode;\n }\n return code;\n },\n\n buildStart() {\n console.log('online-debug build started')\n },\n\n generateBundle() {\n console.log('online-debug generating bundle')\n }\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWe,SAAR,aAA8B,UAAyB,CAAC,GAAW;AACxE,QAAM;AAAA,IACJ,OAAO;AAAA,IACP,QAAQ;AAAA,EACV,IAAI;AACJ,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IAEP,UAAU,MAAc,IAAY;AAClC,UAAI,GAAG,SAAS,cAAc,GAAG;AAE/B,cAAM,uBAAuB;AAAA,cACvB,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qCAkDmB,IAAI,qBAAqB,KAAK;AAAA;AAAA;AAGvD,eAAO;AAAA,MACX;AACA,aAAO;AAAA,IACX;AAAA,IAEA,aAAa;AACX,cAAQ,IAAI,4BAA4B;AAAA,IAC1C;AAAA,IAEA,iBAAiB;AACf,cAAQ,IAAI,gCAAgC;AAAA,IAC9C;AAAA,EACF;AACF;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,81 @@
1
+ // src/index.ts
2
+ function createPlugin(options = {}) {
3
+ const {
4
+ host = "127.0.0.1",
5
+ entry = "/src/main.js"
6
+ } = options;
7
+ return {
8
+ name: "vite-plugin-online-debug",
9
+ apply: "build",
10
+ transform(code, id) {
11
+ if (id.includes("/src/main.js")) {
12
+ const environmentCheckCode = `
13
+ ${code}
14
+ function loadScript(src, options = {}) {
15
+ return new Promise((resolve, reject) => {
16
+ // \u9A8C\u8BC1\u8F93\u5165\u53C2\u6570
17
+ if (!src) {
18
+ reject(new Error('\u811A\u672CURL\u4E0D\u80FD\u4E3A\u7A7A'));
19
+ return;
20
+ }
21
+
22
+ // \u8BBE\u7F6E\u9ED8\u8BA4\u9009\u9879
23
+ const defaultOptions = {
24
+ async: true,
25
+ defer: false,
26
+ type: 'text/javascript',
27
+ charset: 'utf-8'
28
+ };
29
+
30
+ // \u5408\u5E76\u9009\u9879
31
+ const config = Object.assign(defaultOptions, options);
32
+ console.log("\u{1F680} ~ loadScript ~ config:", config)
33
+
34
+ // \u521B\u5EFAscript\u6807\u7B7E
35
+ const script = document.createElement('script');
36
+ script.src = src;
37
+ script.async = config.async;
38
+ script.defer = config.defer;
39
+ script.type = config.type;
40
+ script.charset = config.charset;
41
+
42
+ // \u76D1\u542C\u52A0\u8F7D\u6210\u529F\u4E8B\u4EF6
43
+ script.onload = function() {
44
+ resolve(script);
45
+ };
46
+
47
+ // \u76D1\u542C\u52A0\u8F7D\u5931\u8D25\u4E8B\u4EF6
48
+ script.onerror = function() {
49
+ reject(new Error('\u811A\u672C\u52A0\u8F7D\u5931\u8D25:' + src));
50
+ };
51
+
52
+ // \u6DFB\u52A0\u5230\u9875\u9762\u4E2D
53
+ document.head.appendChild(script);
54
+ });
55
+ }
56
+ // \u73AF\u5883\u68C0\u6D4B\u903B\u8F91
57
+ if (import.meta.env.PROD && window.location.search?.indexOf('_debug_') > -1) {
58
+ // \u751F\u4EA7\u73AF\u5883\u903B\u8F91
59
+ const params = new URLSearchParams(window.location?.search || '');
60
+ const port = params.get('_debug_') || '8080';
61
+ const res = document.querySelector('#app');
62
+ res.__vue_app__?.unmount()
63
+ loadScript('http://${host}' + ':' + port + '${entry}', { type: 'module' })
64
+ }
65
+ `;
66
+ return environmentCheckCode;
67
+ }
68
+ return code;
69
+ },
70
+ buildStart() {
71
+ console.log("online-debug build started");
72
+ },
73
+ generateBundle() {
74
+ console.log("online-debug generating bundle");
75
+ }
76
+ };
77
+ }
78
+ export {
79
+ createPlugin as default
80
+ };
81
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Plugin } from 'vite'\n\nexport interface PluginOptions {\n /**\n * @host 本地服务host,默认 127.0.0.1\n * @entry 应用入口文件,默认 /src/main.js\n */\n host?: boolean,\n entry?: string,\n}\n\nexport default function createPlugin(options: PluginOptions = {}): Plugin {\n const {\n host = '127.0.0.1',\n entry = '/src/main.js'\n } = options;\n return {\n name: 'vite-plugin-online-debug',\n apply: 'build',\n \n transform(code: string, id: string) {\n if (id.includes('/src/main.js')) {\n \n const environmentCheckCode = `\n ${code}\n function loadScript(src, options = {}) {\n return new Promise((resolve, reject) => {\n // 验证输入参数\n if (!src) {\n reject(new Error('脚本URL不能为空'));\n return;\n }\n \n // 设置默认选项\n const defaultOptions = {\n async: true,\n defer: false,\n type: 'text/javascript',\n charset: 'utf-8'\n };\n \n // 合并选项\n const config = Object.assign(defaultOptions, options);\n console.log(\"🚀 ~ loadScript ~ config:\", config)\n \n // 创建script标签\n const script = document.createElement('script');\n script.src = src;\n script.async = config.async;\n script.defer = config.defer;\n script.type = config.type;\n script.charset = config.charset;\n \n // 监听加载成功事件\n script.onload = function() {\n resolve(script);\n };\n \n // 监听加载失败事件\n script.onerror = function() {\n reject(new Error('脚本加载失败:' + src));\n };\n \n // 添加到页面中\n document.head.appendChild(script);\n });\n }\n // 环境检测逻辑\n if (import.meta.env.PROD && window.location.search?.indexOf('_debug_') > -1) {\n // 生产环境逻辑\n const params = new URLSearchParams(window.location?.search || '');\n const port = params.get('_debug_') || '8080';\n const res = document.querySelector('#app');\n res.__vue_app__?.unmount()\n loadScript('http://${host}' + ':' + port + '${entry}', { type: 'module' })\n }\n `;\n return environmentCheckCode;\n }\n return code;\n },\n\n buildStart() {\n console.log('online-debug build started')\n },\n\n generateBundle() {\n console.log('online-debug generating bundle')\n }\n }\n}"],"mappings":";AAWe,SAAR,aAA8B,UAAyB,CAAC,GAAW;AACxE,QAAM;AAAA,IACJ,OAAO;AAAA,IACP,QAAQ;AAAA,EACV,IAAI;AACJ,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IAEP,UAAU,MAAc,IAAY;AAClC,UAAI,GAAG,SAAS,cAAc,GAAG;AAE/B,cAAM,uBAAuB;AAAA,cACvB,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qCAkDmB,IAAI,qBAAqB,KAAK;AAAA;AAAA;AAGvD,eAAO;AAAA,MACX;AACA,aAAO;AAAA,IACX;AAAA,IAEA,aAAa;AACX,cAAQ,IAAI,4BAA4B;AAAA,IAC1C;AAAA,IAEA,iBAAiB;AACf,cAAQ,IAAI,gCAAgC;AAAA,IAC9C;AAAA,EACF;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "vite-plugin-online-debug",
3
+ "version": "0.0.1",
4
+ "description": "debug with online environment",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.esm.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.esm.js",
11
+ "require": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "dev": "npm run build -- --watch",
20
+ "build": "tsup src/index.ts --format cjs,esm --dts",
21
+ "test": "vitest",
22
+ "test:ui": "vitest --ui",
23
+ "lint": "eslint src --ext .ts",
24
+ "lint:fix": "eslint src --ext .ts --fix",
25
+ "prepublishOnly": "npm run build"
26
+ },
27
+ "keywords": [
28
+ "vite",
29
+ "plugin",
30
+ "vite-plugin",
31
+ "debug"
32
+ ],
33
+ "author": "estrayn5",
34
+ "license": "MIT",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": ""
38
+ },
39
+ "devDependencies": {
40
+ "@types/node": "^20.0.0",
41
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
42
+ "@typescript-eslint/parser": "^6.0.0",
43
+ "eslint": "^8.0.0",
44
+ "tsup": "^7.0.0",
45
+ "typescript": "^5.0.0",
46
+ "vite": "^5.0.0",
47
+ "vitest": "^1.0.0"
48
+ },
49
+ "peerDependencies": {
50
+ "vite": "^3.0.0 || ^4.0.0 || ^5.0.0"
51
+ }
52
+ }