@react-perfscope/webpack 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 +21 -0
- package/README.md +55 -0
- package/dist/index.cjs +66 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -0
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,55 @@
|
|
|
1
|
+
# @react-perfscope/webpack
|
|
2
|
+
|
|
3
|
+
Webpack plugin that adds `react-perfscope/auto` as an additional entry in development mode.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install -D @react-perfscope/webpack react-perfscope
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
// webpack.config.js
|
|
15
|
+
const { ReactPerfscopePlugin } = require('@react-perfscope/webpack')
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
mode: 'development',
|
|
19
|
+
plugins: [
|
|
20
|
+
new ReactPerfscopePlugin(),
|
|
21
|
+
],
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The plugin checks `compiler.options.mode` and is a no-op when mode is anything other than `'development'`.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
<a id="한국어"></a>
|
|
30
|
+
|
|
31
|
+
# 한국어
|
|
32
|
+
|
|
33
|
+
development 모드에서 `react-perfscope/auto`를 추가 엔트리로 넣어주는 Webpack 플러그인.
|
|
34
|
+
|
|
35
|
+
## 설치
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
npm install -D @react-perfscope/webpack react-perfscope
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## 사용법
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
// webpack.config.js
|
|
45
|
+
const { ReactPerfscopePlugin } = require('@react-perfscope/webpack')
|
|
46
|
+
|
|
47
|
+
module.exports = {
|
|
48
|
+
mode: 'development',
|
|
49
|
+
plugins: [
|
|
50
|
+
new ReactPerfscopePlugin(),
|
|
51
|
+
],
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
플러그인은 `compiler.options.mode`를 확인해서 `'development'` 외에는 no-op으로 동작한다.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
ReactPerfscopePlugin: () => ReactPerfscopePlugin,
|
|
24
|
+
default: () => index_default
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var ReactPerfscopePlugin = class {
|
|
28
|
+
constructor(_opts) {
|
|
29
|
+
void _opts;
|
|
30
|
+
}
|
|
31
|
+
apply(compiler) {
|
|
32
|
+
if (compiler.options.mode !== "development") return;
|
|
33
|
+
const EntryPlugin = compiler.webpack.EntryPlugin;
|
|
34
|
+
new EntryPlugin(
|
|
35
|
+
compiler.context,
|
|
36
|
+
"react-perfscope/auto",
|
|
37
|
+
{}
|
|
38
|
+
).apply(compiler);
|
|
39
|
+
ensureJsProfilingHeader(compiler);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
function ensureJsProfilingHeader(compiler) {
|
|
43
|
+
const KEY = "Document-Policy";
|
|
44
|
+
const VALUE = "js-profiling";
|
|
45
|
+
const options = compiler.options;
|
|
46
|
+
const devServer = options.devServer ?? (options.devServer = {});
|
|
47
|
+
if (devServer.headers === void 0) {
|
|
48
|
+
devServer.headers = { [KEY]: VALUE };
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(devServer.headers)) {
|
|
52
|
+
if (!devServer.headers.some((h) => h.key === KEY)) {
|
|
53
|
+
devServer.headers.push({ key: KEY, value: VALUE });
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (!(KEY in devServer.headers)) {
|
|
58
|
+
devServer.headers[KEY] = VALUE;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
var index_default = ReactPerfscopePlugin;
|
|
62
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
63
|
+
0 && (module.exports = {
|
|
64
|
+
ReactPerfscopePlugin
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Compiler } from 'webpack'\n\nexport interface ReactPerfscopePluginOptions {\n // Reserved for Phase 6.\n}\n\n/**\n * Webpack plugin that adds `react-perfscope/auto` as an additional entry in\n * development mode. The auto module bootstraps recorder + render collector\n * + UI mount at runtime.\n */\nexport class ReactPerfscopePlugin {\n constructor(_opts?: ReactPerfscopePluginOptions) {\n void _opts\n }\n\n apply(compiler: Compiler): void {\n if (compiler.options.mode !== 'development') return\n const EntryPlugin = compiler.webpack.EntryPlugin\n // EntryPlugin's options arg can be `string | EntryOptions`. Passing an\n // empty EntryOptions makes this an additional \"global\" entry (loaded\n // alongside the named entries). Webpack 5's typing accepts {} here.\n new EntryPlugin(\n compiler.context,\n 'react-perfscope/auto',\n {} as ConstructorParameters<typeof EntryPlugin>[2]\n ).apply(compiler)\n ensureJsProfilingHeader(compiler)\n }\n}\n\n/**\n * The JS Self-Profiling API (used to attribute long tasks to the developer's\n * own functions) only initializes when the document is served with a\n * `Document-Policy: js-profiling` response header. webpack-dev-server reads\n * `compiler.options.devServer` when no options are passed to it explicitly\n * (the `webpack serve` CLI path), so we merge the header in here. It's a no-op\n * where the browser lacks the API, and we never overwrite a user-set value.\n *\n * webpack-dev-server's `headers` can be an object map or an array of\n * `{ key, value }` entries — handle both shapes.\n */\nfunction ensureJsProfilingHeader(compiler: Compiler): void {\n const KEY = 'Document-Policy'\n const VALUE = 'js-profiling'\n // `devServer` is contributed by webpack-dev-server's type augmentation and\n // isn't part of webpack's core Configuration; treat it loosely.\n const options = compiler.options as unknown as {\n devServer?: {\n headers?: Record<string, string> | Array<{ key: string; value: string }>\n }\n }\n const devServer = (options.devServer ??= {})\n if (devServer.headers === undefined) {\n devServer.headers = { [KEY]: VALUE }\n return\n }\n if (Array.isArray(devServer.headers)) {\n if (!devServer.headers.some((h) => h.key === KEY)) {\n devServer.headers.push({ key: KEY, value: VALUE })\n }\n return\n }\n if (!(KEY in devServer.headers)) {\n devServer.headers[KEY] = VALUE\n }\n}\n\nexport default ReactPerfscopePlugin\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWO,IAAM,uBAAN,MAA2B;AAAA,EAChC,YAAY,OAAqC;AAC/C,SAAK;AAAA,EACP;AAAA,EAEA,MAAM,UAA0B;AAC9B,QAAI,SAAS,QAAQ,SAAS,cAAe;AAC7C,UAAM,cAAc,SAAS,QAAQ;AAIrC,QAAI;AAAA,MACF,SAAS;AAAA,MACT;AAAA,MACA,CAAC;AAAA,IACH,EAAE,MAAM,QAAQ;AAChB,4BAAwB,QAAQ;AAAA,EAClC;AACF;AAaA,SAAS,wBAAwB,UAA0B;AACzD,QAAM,MAAM;AACZ,QAAM,QAAQ;AAGd,QAAM,UAAU,SAAS;AAKzB,QAAM,YAAa,QAAQ,cAAR,QAAQ,YAAc,CAAC;AAC1C,MAAI,UAAU,YAAY,QAAW;AACnC,cAAU,UAAU,EAAE,CAAC,GAAG,GAAG,MAAM;AACnC;AAAA,EACF;AACA,MAAI,MAAM,QAAQ,UAAU,OAAO,GAAG;AACpC,QAAI,CAAC,UAAU,QAAQ,KAAK,CAAC,MAAM,EAAE,QAAQ,GAAG,GAAG;AACjD,gBAAU,QAAQ,KAAK,EAAE,KAAK,KAAK,OAAO,MAAM,CAAC;AAAA,IACnD;AACA;AAAA,EACF;AACA,MAAI,EAAE,OAAO,UAAU,UAAU;AAC/B,cAAU,QAAQ,GAAG,IAAI;AAAA,EAC3B;AACF;AAEA,IAAO,gBAAQ;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference lib="es2015" />
|
|
2
|
+
/// <reference lib="dom" />
|
|
3
|
+
|
|
4
|
+
import { Compiler } from 'webpack';
|
|
5
|
+
|
|
6
|
+
interface ReactPerfscopePluginOptions {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Webpack plugin that adds `react-perfscope/auto` as an additional entry in
|
|
10
|
+
* development mode. The auto module bootstraps recorder + render collector
|
|
11
|
+
* + UI mount at runtime.
|
|
12
|
+
*/
|
|
13
|
+
declare class ReactPerfscopePlugin {
|
|
14
|
+
constructor(_opts?: ReactPerfscopePluginOptions);
|
|
15
|
+
apply(compiler: Compiler): void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { ReactPerfscopePlugin, type ReactPerfscopePluginOptions, ReactPerfscopePlugin as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference lib="es2015" />
|
|
2
|
+
/// <reference lib="dom" />
|
|
3
|
+
|
|
4
|
+
import { Compiler } from 'webpack';
|
|
5
|
+
|
|
6
|
+
interface ReactPerfscopePluginOptions {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Webpack plugin that adds `react-perfscope/auto` as an additional entry in
|
|
10
|
+
* development mode. The auto module bootstraps recorder + render collector
|
|
11
|
+
* + UI mount at runtime.
|
|
12
|
+
*/
|
|
13
|
+
declare class ReactPerfscopePlugin {
|
|
14
|
+
constructor(_opts?: ReactPerfscopePluginOptions);
|
|
15
|
+
apply(compiler: Compiler): void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { ReactPerfscopePlugin, type ReactPerfscopePluginOptions, ReactPerfscopePlugin as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var ReactPerfscopePlugin = class {
|
|
3
|
+
constructor(_opts) {
|
|
4
|
+
void _opts;
|
|
5
|
+
}
|
|
6
|
+
apply(compiler) {
|
|
7
|
+
if (compiler.options.mode !== "development") return;
|
|
8
|
+
const EntryPlugin = compiler.webpack.EntryPlugin;
|
|
9
|
+
new EntryPlugin(
|
|
10
|
+
compiler.context,
|
|
11
|
+
"react-perfscope/auto",
|
|
12
|
+
{}
|
|
13
|
+
).apply(compiler);
|
|
14
|
+
ensureJsProfilingHeader(compiler);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
function ensureJsProfilingHeader(compiler) {
|
|
18
|
+
const KEY = "Document-Policy";
|
|
19
|
+
const VALUE = "js-profiling";
|
|
20
|
+
const options = compiler.options;
|
|
21
|
+
const devServer = options.devServer ?? (options.devServer = {});
|
|
22
|
+
if (devServer.headers === void 0) {
|
|
23
|
+
devServer.headers = { [KEY]: VALUE };
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (Array.isArray(devServer.headers)) {
|
|
27
|
+
if (!devServer.headers.some((h) => h.key === KEY)) {
|
|
28
|
+
devServer.headers.push({ key: KEY, value: VALUE });
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!(KEY in devServer.headers)) {
|
|
33
|
+
devServer.headers[KEY] = VALUE;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
var index_default = ReactPerfscopePlugin;
|
|
37
|
+
export {
|
|
38
|
+
ReactPerfscopePlugin,
|
|
39
|
+
index_default as default
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Compiler } from 'webpack'\n\nexport interface ReactPerfscopePluginOptions {\n // Reserved for Phase 6.\n}\n\n/**\n * Webpack plugin that adds `react-perfscope/auto` as an additional entry in\n * development mode. The auto module bootstraps recorder + render collector\n * + UI mount at runtime.\n */\nexport class ReactPerfscopePlugin {\n constructor(_opts?: ReactPerfscopePluginOptions) {\n void _opts\n }\n\n apply(compiler: Compiler): void {\n if (compiler.options.mode !== 'development') return\n const EntryPlugin = compiler.webpack.EntryPlugin\n // EntryPlugin's options arg can be `string | EntryOptions`. Passing an\n // empty EntryOptions makes this an additional \"global\" entry (loaded\n // alongside the named entries). Webpack 5's typing accepts {} here.\n new EntryPlugin(\n compiler.context,\n 'react-perfscope/auto',\n {} as ConstructorParameters<typeof EntryPlugin>[2]\n ).apply(compiler)\n ensureJsProfilingHeader(compiler)\n }\n}\n\n/**\n * The JS Self-Profiling API (used to attribute long tasks to the developer's\n * own functions) only initializes when the document is served with a\n * `Document-Policy: js-profiling` response header. webpack-dev-server reads\n * `compiler.options.devServer` when no options are passed to it explicitly\n * (the `webpack serve` CLI path), so we merge the header in here. It's a no-op\n * where the browser lacks the API, and we never overwrite a user-set value.\n *\n * webpack-dev-server's `headers` can be an object map or an array of\n * `{ key, value }` entries — handle both shapes.\n */\nfunction ensureJsProfilingHeader(compiler: Compiler): void {\n const KEY = 'Document-Policy'\n const VALUE = 'js-profiling'\n // `devServer` is contributed by webpack-dev-server's type augmentation and\n // isn't part of webpack's core Configuration; treat it loosely.\n const options = compiler.options as unknown as {\n devServer?: {\n headers?: Record<string, string> | Array<{ key: string; value: string }>\n }\n }\n const devServer = (options.devServer ??= {})\n if (devServer.headers === undefined) {\n devServer.headers = { [KEY]: VALUE }\n return\n }\n if (Array.isArray(devServer.headers)) {\n if (!devServer.headers.some((h) => h.key === KEY)) {\n devServer.headers.push({ key: KEY, value: VALUE })\n }\n return\n }\n if (!(KEY in devServer.headers)) {\n devServer.headers[KEY] = VALUE\n }\n}\n\nexport default ReactPerfscopePlugin\n"],"mappings":";AAWO,IAAM,uBAAN,MAA2B;AAAA,EAChC,YAAY,OAAqC;AAC/C,SAAK;AAAA,EACP;AAAA,EAEA,MAAM,UAA0B;AAC9B,QAAI,SAAS,QAAQ,SAAS,cAAe;AAC7C,UAAM,cAAc,SAAS,QAAQ;AAIrC,QAAI;AAAA,MACF,SAAS;AAAA,MACT;AAAA,MACA,CAAC;AAAA,IACH,EAAE,MAAM,QAAQ;AAChB,4BAAwB,QAAQ;AAAA,EAClC;AACF;AAaA,SAAS,wBAAwB,UAA0B;AACzD,QAAM,MAAM;AACZ,QAAM,QAAQ;AAGd,QAAM,UAAU,SAAS;AAKzB,QAAM,YAAa,QAAQ,cAAR,QAAQ,YAAc,CAAC;AAC1C,MAAI,UAAU,YAAY,QAAW;AACnC,cAAU,UAAU,EAAE,CAAC,GAAG,GAAG,MAAM;AACnC;AAAA,EACF;AACA,MAAI,MAAM,QAAQ,UAAU,OAAO,GAAG;AACpC,QAAI,CAAC,UAAU,QAAQ,KAAK,CAAC,MAAM,EAAE,QAAQ,GAAG,GAAG;AACjD,gBAAU,QAAQ,KAAK,EAAE,KAAK,KAAK,OAAO,MAAM,CAAC;AAAA,IACnD;AACA;AAAA,EACF;AACA,MAAI,EAAE,OAAO,UAAU,UAAU;AAC/B,cAAU,QAAQ,GAAG,IAAI;AAAA,EAC3B;AACF;AAEA,IAAO,gBAAQ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-perfscope/webpack",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "webpack plugin for react-perfscope — auto-mounts the profiler in dev and injects the js-profiling Document-Policy header.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"webpack",
|
|
7
|
+
"webpack-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
|
+
"webpack": "^5.90.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"webpack": "^5.95.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/webpack-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
|
+
}
|