@react-perfscope/vite 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 ray
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,59 @@
1
+ # @react-perfscope/vite
2
+
3
+ Vite plugin that auto-injects `react-perfscope/auto` into your HTML entry in dev mode.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install -D @react-perfscope/vite react-perfscope
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ // vite.config.ts
15
+ import { defineConfig } from 'vite'
16
+ import react from '@vitejs/plugin-react'
17
+ import reactPerfscope from '@react-perfscope/vite'
18
+
19
+ export default defineConfig({
20
+ plugins: [
21
+ reactPerfscope(),
22
+ react(),
23
+ ],
24
+ })
25
+ ```
26
+
27
+ The plugin is a no-op in `vite build` (production). In `vite serve`, it adds a `<script type="module" src="/@id/react-perfscope/auto">` to the HTML head so the bootstrap loads before your app's entry.
28
+
29
+ ---
30
+
31
+ <a id="한국어"></a>
32
+
33
+ # 한국어
34
+
35
+ dev 모드에서 HTML 엔트리에 `react-perfscope/auto`를 자동으로 주입하는 Vite 플러그인.
36
+
37
+ ## 설치
38
+
39
+ ```sh
40
+ npm install -D @react-perfscope/vite react-perfscope
41
+ ```
42
+
43
+ ## 사용법
44
+
45
+ ```ts
46
+ // vite.config.ts
47
+ import { defineConfig } from 'vite'
48
+ import react from '@vitejs/plugin-react'
49
+ import reactPerfscope from '@react-perfscope/vite'
50
+
51
+ export default defineConfig({
52
+ plugins: [
53
+ reactPerfscope(),
54
+ react(),
55
+ ],
56
+ })
57
+ ```
58
+
59
+ `vite build`(프로덕션)에서는 no-op이다. `vite serve`에서는 HTML `<head>`에 `<script type="module" src="/@id/react-perfscope/auto">`를 추가해서 부트스트랩이 앱 엔트리보다 먼저 실행되도록 한다.
package/dist/index.cjs ADDED
@@ -0,0 +1,70 @@
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 index_exports = {};
22
+ __export(index_exports, {
23
+ default: () => reactPerfscope
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var VIRTUAL_ID = "\0virtual:react-perfscope-bootstrap";
27
+ var VIRTUAL_URL = "/@react-perfscope-bootstrap.js";
28
+ function reactPerfscope(_opts) {
29
+ return {
30
+ name: "react-perfscope",
31
+ apply: "serve",
32
+ config(config) {
33
+ var _a, _b;
34
+ config.optimizeDeps ?? (config.optimizeDeps = {});
35
+ (_a = config.optimizeDeps).include ?? (_a.include = []);
36
+ const toInclude = ["react-perfscope", "react-perfscope/auto"];
37
+ for (const dep of toInclude) {
38
+ if (!config.optimizeDeps.include.includes(dep)) {
39
+ config.optimizeDeps.include.push(dep);
40
+ }
41
+ }
42
+ config.server ?? (config.server = {});
43
+ (_b = config.server).headers ?? (_b.headers = {});
44
+ if (!("Document-Policy" in config.server.headers)) {
45
+ config.server.headers["Document-Policy"] = "js-profiling";
46
+ }
47
+ return config;
48
+ },
49
+ resolveId(id) {
50
+ if (id === VIRTUAL_URL) return VIRTUAL_ID;
51
+ return null;
52
+ },
53
+ load(id) {
54
+ if (id === VIRTUAL_ID) {
55
+ return `import 'react-perfscope/auto'`;
56
+ }
57
+ return null;
58
+ },
59
+ transformIndexHtml(_html) {
60
+ return [
61
+ {
62
+ tag: "script",
63
+ attrs: { type: "module", src: VIRTUAL_URL },
64
+ injectTo: "head-prepend"
65
+ }
66
+ ];
67
+ }
68
+ };
69
+ }
70
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Plugin, HtmlTagDescriptor } from 'vite'\n\nexport interface ReactPerfscopePluginOptions {\n // Reserved for Phase 6 (position, host, disabled, etc.).\n}\n\nconst VIRTUAL_ID = '\\0virtual:react-perfscope-bootstrap'\nconst VIRTUAL_URL = '/@react-perfscope-bootstrap.js'\n\n/**\n * Vite plugin that auto-injects `react-perfscope/auto` into the HTML entry\n * during dev mode. The injected script imports the meta package which\n * bootstraps a recorder + render collector + UI mount.\n *\n * Implementation: Vite does NOT transform inline `<script type=\"module\">`\n * content, so writing `import 'react-perfscope/auto'` directly into a tag\n * fails (the browser can't resolve bare specifiers). Instead we expose a\n * virtual module via `resolveId`/`load` and inject a `<script src>` that\n * points at it — Vite's module-loading pipeline transforms the module body\n * (where the bare specifier IS resolved) before delivering it.\n */\nexport default function reactPerfscope(_opts?: ReactPerfscopePluginOptions): Plugin {\n return {\n name: 'react-perfscope',\n apply: 'serve',\n config(config) {\n // Force-bundle the perfscope packages as deps so @vitejs/plugin-react\n // (and similar transforms) see them as node_modules — otherwise the\n // workspace-linked dist files get pulled through Fast Refresh, which\n // throws \"can't detect preamble\" because our bootstrap runs before\n // the React plugin's preamble. We only list packages we expect the\n // consumer to actually have in package.json — `react-perfscope` is\n // the user-facing dep, `/auto` is its side-effect entry. Vite's\n // optimizer follows transitive imports (core/react/ui) automatically.\n config.optimizeDeps ??= {}\n config.optimizeDeps.include ??= []\n const toInclude = ['react-perfscope', 'react-perfscope/auto']\n for (const dep of toInclude) {\n if (!config.optimizeDeps.include.includes(dep)) {\n config.optimizeDeps.include.push(dep)\n }\n }\n // The JS Self-Profiling API (used to attribute long tasks to the\n // developer's own functions) only initializes when the document is\n // served with this response header. Set it for all dev responses so\n // attribution works with zero config; it's a no-op where the browser\n // lacks the API. We merge rather than overwrite any user-set headers.\n config.server ??= {}\n config.server.headers ??= {}\n if (!('Document-Policy' in config.server.headers)) {\n config.server.headers['Document-Policy'] = 'js-profiling'\n }\n return config\n },\n resolveId(id) {\n if (id === VIRTUAL_URL) return VIRTUAL_ID\n return null\n },\n load(id) {\n if (id === VIRTUAL_ID) {\n return `import 'react-perfscope/auto'`\n }\n return null\n },\n transformIndexHtml(_html: string): HtmlTagDescriptor[] {\n return [\n {\n tag: 'script',\n attrs: { type: 'module', src: VIRTUAL_URL },\n injectTo: 'head-prepend',\n },\n ]\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,IAAM,aAAa;AACnB,IAAM,cAAc;AAcL,SAAR,eAAgC,OAA6C;AAClF,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,OAAO,QAAQ;AAzBnB;AAkCM,aAAO,iBAAP,OAAO,eAAiB,CAAC;AACzB,mBAAO,cAAa,YAApB,GAAoB,UAAY,CAAC;AACjC,YAAM,YAAY,CAAC,mBAAmB,sBAAsB;AAC5D,iBAAW,OAAO,WAAW;AAC3B,YAAI,CAAC,OAAO,aAAa,QAAQ,SAAS,GAAG,GAAG;AAC9C,iBAAO,aAAa,QAAQ,KAAK,GAAG;AAAA,QACtC;AAAA,MACF;AAMA,aAAO,WAAP,OAAO,SAAW,CAAC;AACnB,mBAAO,QAAO,YAAd,GAAc,UAAY,CAAC;AAC3B,UAAI,EAAE,qBAAqB,OAAO,OAAO,UAAU;AACjD,eAAO,OAAO,QAAQ,iBAAiB,IAAI;AAAA,MAC7C;AACA,aAAO;AAAA,IACT;AAAA,IACA,UAAU,IAAI;AACZ,UAAI,OAAO,YAAa,QAAO;AAC/B,aAAO;AAAA,IACT;AAAA,IACA,KAAK,IAAI;AACP,UAAI,OAAO,YAAY;AACrB,eAAO;AAAA,MACT;AACA,aAAO;AAAA,IACT;AAAA,IACA,mBAAmB,OAAoC;AACrD,aAAO;AAAA,QACL;AAAA,UACE,KAAK;AAAA,UACL,OAAO,EAAE,MAAM,UAAU,KAAK,YAAY;AAAA,UAC1C,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,22 @@
1
+ /// <reference lib="es2015" />
2
+ /// <reference lib="dom" />
3
+
4
+ import { Plugin } from 'vite';
5
+
6
+ interface ReactPerfscopePluginOptions {
7
+ }
8
+ /**
9
+ * Vite plugin that auto-injects `react-perfscope/auto` into the HTML entry
10
+ * during dev mode. The injected script imports the meta package which
11
+ * bootstraps a recorder + render collector + UI mount.
12
+ *
13
+ * Implementation: Vite does NOT transform inline `<script type="module">`
14
+ * content, so writing `import 'react-perfscope/auto'` directly into a tag
15
+ * fails (the browser can't resolve bare specifiers). Instead we expose a
16
+ * virtual module via `resolveId`/`load` and inject a `<script src>` that
17
+ * points at it — Vite's module-loading pipeline transforms the module body
18
+ * (where the bare specifier IS resolved) before delivering it.
19
+ */
20
+ declare function reactPerfscope(_opts?: ReactPerfscopePluginOptions): Plugin;
21
+
22
+ export { type ReactPerfscopePluginOptions, reactPerfscope as default };
@@ -0,0 +1,22 @@
1
+ /// <reference lib="es2015" />
2
+ /// <reference lib="dom" />
3
+
4
+ import { Plugin } from 'vite';
5
+
6
+ interface ReactPerfscopePluginOptions {
7
+ }
8
+ /**
9
+ * Vite plugin that auto-injects `react-perfscope/auto` into the HTML entry
10
+ * during dev mode. The injected script imports the meta package which
11
+ * bootstraps a recorder + render collector + UI mount.
12
+ *
13
+ * Implementation: Vite does NOT transform inline `<script type="module">`
14
+ * content, so writing `import 'react-perfscope/auto'` directly into a tag
15
+ * fails (the browser can't resolve bare specifiers). Instead we expose a
16
+ * virtual module via `resolveId`/`load` and inject a `<script src>` that
17
+ * points at it — Vite's module-loading pipeline transforms the module body
18
+ * (where the bare specifier IS resolved) before delivering it.
19
+ */
20
+ declare function reactPerfscope(_opts?: ReactPerfscopePluginOptions): Plugin;
21
+
22
+ export { type ReactPerfscopePluginOptions, reactPerfscope as default };
package/dist/index.js ADDED
@@ -0,0 +1,49 @@
1
+ // src/index.ts
2
+ var VIRTUAL_ID = "\0virtual:react-perfscope-bootstrap";
3
+ var VIRTUAL_URL = "/@react-perfscope-bootstrap.js";
4
+ function reactPerfscope(_opts) {
5
+ return {
6
+ name: "react-perfscope",
7
+ apply: "serve",
8
+ config(config) {
9
+ var _a, _b;
10
+ config.optimizeDeps ?? (config.optimizeDeps = {});
11
+ (_a = config.optimizeDeps).include ?? (_a.include = []);
12
+ const toInclude = ["react-perfscope", "react-perfscope/auto"];
13
+ for (const dep of toInclude) {
14
+ if (!config.optimizeDeps.include.includes(dep)) {
15
+ config.optimizeDeps.include.push(dep);
16
+ }
17
+ }
18
+ config.server ?? (config.server = {});
19
+ (_b = config.server).headers ?? (_b.headers = {});
20
+ if (!("Document-Policy" in config.server.headers)) {
21
+ config.server.headers["Document-Policy"] = "js-profiling";
22
+ }
23
+ return config;
24
+ },
25
+ resolveId(id) {
26
+ if (id === VIRTUAL_URL) return VIRTUAL_ID;
27
+ return null;
28
+ },
29
+ load(id) {
30
+ if (id === VIRTUAL_ID) {
31
+ return `import 'react-perfscope/auto'`;
32
+ }
33
+ return null;
34
+ },
35
+ transformIndexHtml(_html) {
36
+ return [
37
+ {
38
+ tag: "script",
39
+ attrs: { type: "module", src: VIRTUAL_URL },
40
+ injectTo: "head-prepend"
41
+ }
42
+ ];
43
+ }
44
+ };
45
+ }
46
+ export {
47
+ reactPerfscope as default
48
+ };
49
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Plugin, HtmlTagDescriptor } from 'vite'\n\nexport interface ReactPerfscopePluginOptions {\n // Reserved for Phase 6 (position, host, disabled, etc.).\n}\n\nconst VIRTUAL_ID = '\\0virtual:react-perfscope-bootstrap'\nconst VIRTUAL_URL = '/@react-perfscope-bootstrap.js'\n\n/**\n * Vite plugin that auto-injects `react-perfscope/auto` into the HTML entry\n * during dev mode. The injected script imports the meta package which\n * bootstraps a recorder + render collector + UI mount.\n *\n * Implementation: Vite does NOT transform inline `<script type=\"module\">`\n * content, so writing `import 'react-perfscope/auto'` directly into a tag\n * fails (the browser can't resolve bare specifiers). Instead we expose a\n * virtual module via `resolveId`/`load` and inject a `<script src>` that\n * points at it — Vite's module-loading pipeline transforms the module body\n * (where the bare specifier IS resolved) before delivering it.\n */\nexport default function reactPerfscope(_opts?: ReactPerfscopePluginOptions): Plugin {\n return {\n name: 'react-perfscope',\n apply: 'serve',\n config(config) {\n // Force-bundle the perfscope packages as deps so @vitejs/plugin-react\n // (and similar transforms) see them as node_modules — otherwise the\n // workspace-linked dist files get pulled through Fast Refresh, which\n // throws \"can't detect preamble\" because our bootstrap runs before\n // the React plugin's preamble. We only list packages we expect the\n // consumer to actually have in package.json — `react-perfscope` is\n // the user-facing dep, `/auto` is its side-effect entry. Vite's\n // optimizer follows transitive imports (core/react/ui) automatically.\n config.optimizeDeps ??= {}\n config.optimizeDeps.include ??= []\n const toInclude = ['react-perfscope', 'react-perfscope/auto']\n for (const dep of toInclude) {\n if (!config.optimizeDeps.include.includes(dep)) {\n config.optimizeDeps.include.push(dep)\n }\n }\n // The JS Self-Profiling API (used to attribute long tasks to the\n // developer's own functions) only initializes when the document is\n // served with this response header. Set it for all dev responses so\n // attribution works with zero config; it's a no-op where the browser\n // lacks the API. We merge rather than overwrite any user-set headers.\n config.server ??= {}\n config.server.headers ??= {}\n if (!('Document-Policy' in config.server.headers)) {\n config.server.headers['Document-Policy'] = 'js-profiling'\n }\n return config\n },\n resolveId(id) {\n if (id === VIRTUAL_URL) return VIRTUAL_ID\n return null\n },\n load(id) {\n if (id === VIRTUAL_ID) {\n return `import 'react-perfscope/auto'`\n }\n return null\n },\n transformIndexHtml(_html: string): HtmlTagDescriptor[] {\n return [\n {\n tag: 'script',\n attrs: { type: 'module', src: VIRTUAL_URL },\n injectTo: 'head-prepend',\n },\n ]\n },\n }\n}\n"],"mappings":";AAMA,IAAM,aAAa;AACnB,IAAM,cAAc;AAcL,SAAR,eAAgC,OAA6C;AAClF,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,OAAO,QAAQ;AAzBnB;AAkCM,aAAO,iBAAP,OAAO,eAAiB,CAAC;AACzB,mBAAO,cAAa,YAApB,GAAoB,UAAY,CAAC;AACjC,YAAM,YAAY,CAAC,mBAAmB,sBAAsB;AAC5D,iBAAW,OAAO,WAAW;AAC3B,YAAI,CAAC,OAAO,aAAa,QAAQ,SAAS,GAAG,GAAG;AAC9C,iBAAO,aAAa,QAAQ,KAAK,GAAG;AAAA,QACtC;AAAA,MACF;AAMA,aAAO,WAAP,OAAO,SAAW,CAAC;AACnB,mBAAO,QAAO,YAAd,GAAc,UAAY,CAAC;AAC3B,UAAI,EAAE,qBAAqB,OAAO,OAAO,UAAU;AACjD,eAAO,OAAO,QAAQ,iBAAiB,IAAI;AAAA,MAC7C;AACA,aAAO;AAAA,IACT;AAAA,IACA,UAAU,IAAI;AACZ,UAAI,OAAO,YAAa,QAAO;AAC/B,aAAO;AAAA,IACT;AAAA,IACA,KAAK,IAAI;AACP,UAAI,OAAO,YAAY;AACrB,eAAO;AAAA,MACT;AACA,aAAO;AAAA,IACT;AAAA,IACA,mBAAmB,OAAoC;AACrD,aAAO;AAAA,QACL;AAAA,UACE,KAAK;AAAA,UACL,OAAO,EAAE,MAAM,UAAU,KAAK,YAAY;AAAA,UAC1C,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@react-perfscope/vite",
3
+ "version": "0.1.0",
4
+ "description": "Vite plugin for react-perfscope — auto-mounts the profiler in dev and injects the js-profiling Document-Policy header.",
5
+ "keywords": [
6
+ "vite",
7
+ "vite-plugin",
8
+ "react",
9
+ "performance",
10
+ "profiler"
11
+ ],
12
+ "type": "module",
13
+ "main": "./dist/index.cjs",
14
+ "module": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js",
20
+ "require": "./dist/index.cjs"
21
+ }
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "sideEffects": false,
27
+ "peerDependencies": {
28
+ "vite": "^5.0.0 || ^6.0.0"
29
+ },
30
+ "devDependencies": {
31
+ "vite": "^5.4.0"
32
+ },
33
+ "license": "MIT",
34
+ "author": "rayforvideos",
35
+ "homepage": "https://github.com/rayforvideos/react-perfscope#readme",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/rayforvideos/react-perfscope.git",
39
+ "directory": "packages/vite-plugin"
40
+ },
41
+ "bugs": "https://github.com/rayforvideos/react-perfscope/issues",
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "scripts": {
46
+ "build": "tsup && node scripts/prepend-dts-refs.mjs",
47
+ "typecheck": "tsc --noEmit"
48
+ }
49
+ }