@dev-to/react-plugin 0.4.1 → 1.0.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/README.md +16 -5
- package/dist/constants.d.ts +13 -10
- package/dist/constants.d.ts.map +1 -1
- package/dist/debugTools.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +98 -36
- package/dist/plugin.d.ts +0 -2
- package/dist/plugin.d.ts.map +1 -1
- package/dist/types.d.ts +0 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -39,15 +39,26 @@ export default defineConfig({
|
|
|
39
39
|
|
|
40
40
|
## 稳定桥接路径
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
插件会提供以下稳定路径(v2.0+ 统一命名空间):
|
|
43
43
|
|
|
44
|
-
-
|
|
45
|
-
-
|
|
46
|
-
-
|
|
47
|
-
- Debug
|
|
44
|
+
### 框架无关端点(Framework-Agnostic)
|
|
45
|
+
- **Discovery** (新): `/__dev_to__/discovery.json` - 统一发现端点,包含框架信息、服务器元数据、所有可用端点
|
|
46
|
+
- **Debug HTML**: `/__dev_to__/debug.html` - 可视化调试面板
|
|
47
|
+
- **Debug JSON**: `/__dev_to__/debug.json` - JSON 格式的调试信息
|
|
48
|
+
|
|
49
|
+
### React 专用端点(React-Specific)
|
|
50
|
+
- **Contract** (兼容): `/__dev_to__/react/contract.js` - 桥接合约
|
|
51
|
+
- **Init**: `/__dev_to__/react/init.js` - 安装 HMR + React Refresh preamble
|
|
52
|
+
- **Runtime**: `/__dev_to__/react/runtime.js` - React + ReactDOMClient
|
|
53
|
+
- **Loader UMD**: `/__dev_to__/react/loader.js` - ReactLoader UMD 构建
|
|
54
|
+
- **Component Loaders**: `/__dev_to__/react/loader/{ComponentName}.js` - 单组件加载器
|
|
48
55
|
|
|
49
56
|
这些路径与事件名常量集中在 `@dev-to/react-shared`,用于保证 Vite 侧与宿主侧协议一致。
|
|
50
57
|
|
|
58
|
+
### HMR 事件
|
|
59
|
+
- Full Reload: `dev_to:react:full-reload`
|
|
60
|
+
- HMR Update: `dev_to:react:hmr-update`
|
|
61
|
+
|
|
51
62
|
## 生产构建(Library Mode)
|
|
52
63
|
|
|
53
64
|
执行 `vite build --mode lib` 时,插件会按 `components` 参数为每个组件产出一个 UMD bundle,默认输出到 `dist/<component>/`。
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
export declare const PLUGIN_NAME: "dev_to_react";
|
|
2
|
-
export declare const PLUGIN_LOG_PREFIX: "[
|
|
3
|
-
export declare const STABLE_BASE_PATH: "/
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
2
|
+
export declare const PLUGIN_LOG_PREFIX: "[dev_to:react]";
|
|
3
|
+
export declare const STABLE_BASE_PATH: "/__dev_to__";
|
|
4
|
+
export declare const STABLE_DISCOVERY_PATH: "/__dev_to__/discovery.json";
|
|
5
|
+
export declare const STABLE_DEBUG_HTML_PATH: "/__dev_to__/debug.html";
|
|
6
|
+
export declare const STABLE_DEBUG_JSON_PATH: "/__dev_to__/debug.json";
|
|
7
|
+
export declare const STABLE_REACT_BASE_PATH: "/__dev_to__/react";
|
|
8
|
+
export declare const STABLE_CONTRACT_PATH: "/__dev_to__/react/contract.js";
|
|
9
|
+
export declare const STABLE_INIT_PATH: "/__dev_to__/react/init.js";
|
|
10
|
+
export declare const STABLE_REACT_RUNTIME_PATH: "/__dev_to__/react/runtime.js";
|
|
11
|
+
export declare const STABLE_LOADER_UMD_PATH: "/__dev_to__/react/loader.js";
|
|
12
|
+
export declare const STABLE_LOADER_BASE_PATH: "/__dev_to__/react/loader";
|
|
13
|
+
export declare const EVENT_FULL_RELOAD: "dev_to:react:full-reload";
|
|
14
|
+
export declare const EVENT_HMR_UPDATE: "dev_to:react:hmr-update";
|
|
12
15
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAiBA,eAAO,MAAM,WAAW,gBAA2D,CAAA;AACnF,eAAO,MAAM,iBAAiB,kBAA6D,CAAA;AAG3F,eAAO,MAAM,gBAAgB,eAAmB,CAAA;AAChD,eAAO,MAAM,qBAAqB,8BAAwB,CAAA;AAC1D,eAAO,MAAM,sBAAsB,0BAAyB,CAAA;AAC5D,eAAO,MAAM,sBAAsB,0BAAyB,CAAA;AAG5D,eAAO,MAAM,sBAAsB,qBAAyB,CAAA;AAC5D,eAAO,MAAM,oBAAoB,iCAA6B,CAAA;AAC9D,eAAO,MAAM,gBAAgB,6BAAyB,CAAA;AACtD,eAAO,MAAM,yBAAyB,gCAA4B,CAAA;AAClE,eAAO,MAAM,sBAAsB,+BAA+B,CAAA;AAClE,eAAO,MAAM,uBAAuB,4BAAgC,CAAA;AAEpE,eAAO,MAAM,iBAAiB,4BAAiC,CAAA;AAC/D,eAAO,MAAM,gBAAgB,2BAAgC,CAAA"}
|
package/dist/debugTools.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debugTools.d.ts","sourceRoot":"","sources":["../src/debugTools.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"debugTools.d.ts","sourceRoot":"","sources":["../src/debugTools.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAEzC,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAG/H,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,cAAc,CAAA;IACxB,KAAK,EAAE,WAAW,CAAA;IAClB,KAAK,EAAE,iBAAiB,CAAA;IACxB,cAAc,EAAE,0BAA0B,CAAA;IAC1C,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AA4ID,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,iBAAiB,EAAE,KAAK,EAAE,iBAAiB,QA0YxG"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { EVENT_FULL_RELOAD, EVENT_HMR_UPDATE, PLUGIN_LOG_PREFIX, PLUGIN_NAME, STABLE_BASE_PATH, STABLE_CONTRACT_PATH, STABLE_DEBUG_HTML_PATH, STABLE_DEBUG_JSON_PATH, STABLE_INIT_PATH, STABLE_REACT_RUNTIME_PATH, } from './constants.js';
|
|
2
|
-
export { devToReactPlugin
|
|
3
|
-
export type { BridgeContract, BridgeStats, BridgeStatsBucket, DebugStartupState, DevComponentAudit, DevComponentMapInput, DevToReactPluginOptions, ResolvedDevComponentConfig,
|
|
1
|
+
export { EVENT_FULL_RELOAD, EVENT_HMR_UPDATE, PLUGIN_LOG_PREFIX, PLUGIN_NAME, STABLE_BASE_PATH, STABLE_CONTRACT_PATH, STABLE_DEBUG_HTML_PATH, STABLE_DEBUG_JSON_PATH, STABLE_DISCOVERY_PATH, STABLE_INIT_PATH, STABLE_LOADER_BASE_PATH, STABLE_LOADER_UMD_PATH, STABLE_REACT_BASE_PATH, STABLE_REACT_RUNTIME_PATH, } from './constants.js';
|
|
2
|
+
export { devToReactPlugin } from './plugin.js';
|
|
3
|
+
export type { BridgeContract, BridgeStats, BridgeStatsBucket, DebugStartupState, DevComponentAudit, DevComponentMapInput, DevToReactPluginOptions, ResolvedDevComponentConfig, } from './types.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EACtB,gBAAgB,EAChB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EACtB,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAE9C,YAAY,EACV,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DEV_TO_BASE_PATH, DEV_TO_DEBUG_HTML_PATH, DEV_TO_DEBUG_JSON_PATH, DEV_TO_DISCOVERY_PATH, DEV_TO_NAMESPACE, DEV_TO_REACT_BASE_PATH, DEV_TO_REACT_CONTRACT_KEY, DEV_TO_REACT_CONTRACT_PATH, DEV_TO_REACT_DEBUG_STATE_KEY, DEV_TO_REACT_DID_OPEN_BROWSER_KEY, DEV_TO_REACT_EVENT_FULL_RELOAD, DEV_TO_REACT_EVENT_HMR_UPDATE, DEV_TO_REACT_INIT_PATH, DEV_TO_REACT_LOADER_BASE_PATH, DEV_TO_REACT_LOADER_UMD_PATH, DEV_TO_REACT_NAMESPACE, DEV_TO_REACT_ORIGIN_KEY, DEV_TO_REACT_RESOLVE_ASSET_KEY, DEV_TO_REACT_RUNTIME_PATH } from "@dev-to/react-shared";
|
|
2
2
|
import node_fs from "node:fs";
|
|
3
3
|
import node_path from "node:path";
|
|
4
4
|
import picocolors from "picocolors";
|
|
@@ -8,15 +8,18 @@ import { createRequire } from "node:module";
|
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
9
|
import node_os from "node:os";
|
|
10
10
|
import typescript from "typescript";
|
|
11
|
-
const PLUGIN_NAME = DEV_TO_REACT_NAMESPACE
|
|
12
|
-
const constants_PLUGIN_LOG_PREFIX = `[${
|
|
13
|
-
const STABLE_BASE_PATH =
|
|
11
|
+
const PLUGIN_NAME = `${DEV_TO_NAMESPACE}_${DEV_TO_REACT_NAMESPACE}`;
|
|
12
|
+
const constants_PLUGIN_LOG_PREFIX = `[${DEV_TO_NAMESPACE}:${DEV_TO_REACT_NAMESPACE}]`;
|
|
13
|
+
const STABLE_BASE_PATH = DEV_TO_BASE_PATH;
|
|
14
|
+
const STABLE_DISCOVERY_PATH = DEV_TO_DISCOVERY_PATH;
|
|
15
|
+
const STABLE_DEBUG_HTML_PATH = DEV_TO_DEBUG_HTML_PATH;
|
|
16
|
+
const STABLE_DEBUG_JSON_PATH = DEV_TO_DEBUG_JSON_PATH;
|
|
17
|
+
const STABLE_REACT_BASE_PATH = DEV_TO_REACT_BASE_PATH;
|
|
14
18
|
const constants_STABLE_CONTRACT_PATH = DEV_TO_REACT_CONTRACT_PATH;
|
|
15
19
|
const STABLE_INIT_PATH = DEV_TO_REACT_INIT_PATH;
|
|
16
|
-
const STABLE_REACT_RUNTIME_PATH =
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const STABLE_LOADER_BASE_PATH = DEV_TO_REACT_LOADER_BASE_PATH;
|
|
20
|
+
const STABLE_REACT_RUNTIME_PATH = DEV_TO_REACT_RUNTIME_PATH;
|
|
21
|
+
const STABLE_LOADER_UMD_PATH = DEV_TO_REACT_LOADER_UMD_PATH;
|
|
22
|
+
const constants_STABLE_LOADER_BASE_PATH = DEV_TO_REACT_LOADER_BASE_PATH;
|
|
20
23
|
const EVENT_FULL_RELOAD = DEV_TO_REACT_EVENT_FULL_RELOAD;
|
|
21
24
|
const EVENT_HMR_UPDATE = DEV_TO_REACT_EVENT_HMR_UPDATE;
|
|
22
25
|
function renderDebugHtml(params) {
|
|
@@ -244,7 +247,7 @@ function renderDebugHtml(params) {
|
|
|
244
247
|
${Object.entries(resolvedDevComponentMap).map(([name, entry])=>{
|
|
245
248
|
const abs = entryPathMap[name];
|
|
246
249
|
const displayPath = abs ? getShortPath(abs) : entry;
|
|
247
|
-
const wrapperUrl = (originCandidates[0] || 'http://localhost:5173') + '/
|
|
250
|
+
const wrapperUrl = (originCandidates[0] || 'http://localhost:5173') + '/__dev_to__/react/loader/' + name + '.js';
|
|
248
251
|
const entryHtml = abs ? '<a href="' + toVsCodeUrl(abs) + '" class="link-code" title="点击在 IDE 中打开"><code>' + escapeHtml(displayPath) + '</code></a>' : '<code>' + escapeHtml(entry) + '</code>';
|
|
249
252
|
return '<tr><td><code class="code-name">' + name + "</code></td><td>" + entryHtml + '</td><td><div style="display: flex; align-items: center; gap: 6px;"><code style="flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px;">' + escapeHtml(wrapperUrl) + '</code><button class="copy-wrapper-btn" data-url="' + wrapperUrl + '" style="padding: 2px 8px; font-size: 11px; border: 1px solid var(--b); background: #fff; border-radius: 4px; cursor: pointer; color: var(--t); transition: .2s;" title="复制包装地址">\uD83D\uDCCB</button></div></td></tr>';
|
|
250
253
|
}).join('')}
|
|
@@ -334,7 +337,7 @@ devToReactPlugin(<span class="str">'Demo'</span>, { open: <span class="kw">true<
|
|
|
334
337
|
|
|
335
338
|
<div class="info-grid">
|
|
336
339
|
<div class="info-label">端点:</div>
|
|
337
|
-
<div class="info-value"><code>/
|
|
340
|
+
<div class="info-value"><code>/__dev_to__/react/loader/{ComponentName}.js</code></div>
|
|
338
341
|
<div class="info-label">作用:</div>
|
|
339
342
|
<div class="info-value">自动将组件导出为 React 组件实例,无需宿主集成 @dev-to/react-loader</div>
|
|
340
343
|
<div class="info-label">依赖:</div>
|
|
@@ -357,7 +360,7 @@ devToReactPlugin(<span class="str">'Demo'</span>, { open: <span class="kw">true<
|
|
|
357
360
|
<span class="kw"><script></span> <span class="kw">src</span>=<span class="str">"https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"</span> <span class="kw"></script></span>
|
|
358
361
|
|
|
359
362
|
<span class="cmt">// 2. 加载包装器脚本</span>
|
|
360
|
-
<span class="kw"><script></span> <span class="kw">src</span>=<span class="str">"\${originCandidates[0] || 'http://localhost:5173'}/
|
|
363
|
+
<span class="kw"><script></span> <span class="kw">src</span>=<span class="str">"\${originCandidates[0] || 'http://localhost:5173'}/__dev_to__/react/loader/{ComponentName}.js"</span> <span class="kw"></script></span>
|
|
361
364
|
|
|
362
365
|
<span class="cmt">// 3. 直接作为 React 组件使用</span>
|
|
363
366
|
<span class="kw">const</span> root = ReactDOM.createRoot(document.getElementById(<span class="str">'app'</span>));
|
|
@@ -901,7 +904,7 @@ function createLoaderUmdWrapper(options) {
|
|
|
901
904
|
* <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
|
|
902
905
|
*
|
|
903
906
|
* 2. Load this wrapper:
|
|
904
|
-
* <script src="${origin}/
|
|
907
|
+
* <script src="${origin}/__dev_to__/react/loader/${componentName}.js"></script>
|
|
905
908
|
*
|
|
906
909
|
* 3. Use as a React component:
|
|
907
910
|
*
|
|
@@ -1177,24 +1180,17 @@ function installDebugTools(server, ctx, state) {
|
|
|
1177
1180
|
if ('number' == typeof server.config.server.port) return server.config.server.port;
|
|
1178
1181
|
return 5173;
|
|
1179
1182
|
})();
|
|
1180
|
-
const lanHosts = getLanIPv4Hosts();
|
|
1181
|
-
const candidateHosts = [
|
|
1182
|
-
'localhost',
|
|
1183
|
-
'127.0.0.1',
|
|
1184
|
-
...lanHosts
|
|
1185
|
-
];
|
|
1186
|
-
const urls = candidateHosts.map((h)=>`${proto}://${h}:${port}${STABLE_DEBUG_HTML_PATH}`);
|
|
1187
1183
|
const logger = server.config.logger;
|
|
1188
1184
|
const info = 'function' == typeof logger?.info ? logger.info.bind(logger) : console.log;
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
info('');
|
|
1185
|
+
setImmediate(()=>{
|
|
1186
|
+
info('');
|
|
1187
|
+
info(` ${picocolors.yellowBright('➜')} ${picocolors.bgCyanBright(picocolors.yellow(picocolors.bold(' DevTo ')))} ${picocolors.cyan(`${proto}://localhost:${port}${DEV_TO_BASE_PATH}`)}`);
|
|
1188
|
+
});
|
|
1194
1189
|
if (ctx.open && !didOpenBrowser) {
|
|
1195
1190
|
didOpenBrowser = true;
|
|
1196
1191
|
globalState[DEV_TO_REACT_DID_OPEN_BROWSER_KEY] = true;
|
|
1197
|
-
|
|
1192
|
+
const debugUrl = `${proto}://localhost:${port}${STABLE_DEBUG_HTML_PATH}`;
|
|
1193
|
+
openBrowser(debugUrl);
|
|
1198
1194
|
}
|
|
1199
1195
|
};
|
|
1200
1196
|
try {
|
|
@@ -1223,6 +1219,73 @@ function installDebugTools(server, ctx, state) {
|
|
|
1223
1219
|
res.end();
|
|
1224
1220
|
return;
|
|
1225
1221
|
}
|
|
1222
|
+
if (url.startsWith(STABLE_DISCOVERY_PATH)) {
|
|
1223
|
+
const isHttps = !!server.config.server.https;
|
|
1224
|
+
const proto = isHttps ? 'https' : 'http';
|
|
1225
|
+
const addr = server.httpServer?.address();
|
|
1226
|
+
const actualPort = addr && 'object' == typeof addr ? addr.port : void 0;
|
|
1227
|
+
const lanHosts = getLanIPv4Hosts();
|
|
1228
|
+
const candidateHosts = [
|
|
1229
|
+
'localhost',
|
|
1230
|
+
'127.0.0.1',
|
|
1231
|
+
...lanHosts
|
|
1232
|
+
];
|
|
1233
|
+
const originCandidates = candidateHosts.map((h)=>`${proto}://${h}${actualPort ? `:${actualPort}` : ''}`);
|
|
1234
|
+
const require = createRequire(import.meta.url);
|
|
1235
|
+
let reactVersion = '18.x';
|
|
1236
|
+
try {
|
|
1237
|
+
const reactPkgPath = require.resolve('react/package.json');
|
|
1238
|
+
const reactPkg = JSON.parse(node_fs.readFileSync(reactPkgPath, 'utf-8'));
|
|
1239
|
+
reactVersion = reactPkg.version || '18.x';
|
|
1240
|
+
} catch {}
|
|
1241
|
+
const components = {};
|
|
1242
|
+
for (const [name, entry] of Object.entries(ctx.contract?.dev?.componentMap || {}))components[name] = {
|
|
1243
|
+
name,
|
|
1244
|
+
entry,
|
|
1245
|
+
framework: 'react'
|
|
1246
|
+
};
|
|
1247
|
+
const discovery = {
|
|
1248
|
+
framework: {
|
|
1249
|
+
type: 'react',
|
|
1250
|
+
version: reactVersion
|
|
1251
|
+
},
|
|
1252
|
+
server: {
|
|
1253
|
+
host: String(server.config.server.host || 'localhost'),
|
|
1254
|
+
port: actualPort || server.config.server.port || 5173,
|
|
1255
|
+
protocol: proto,
|
|
1256
|
+
origins: originCandidates
|
|
1257
|
+
},
|
|
1258
|
+
endpoints: {
|
|
1259
|
+
discovery: STABLE_DISCOVERY_PATH,
|
|
1260
|
+
contract: constants_STABLE_CONTRACT_PATH,
|
|
1261
|
+
init: STABLE_INIT_PATH,
|
|
1262
|
+
runtime: STABLE_REACT_RUNTIME_PATH,
|
|
1263
|
+
debug: {
|
|
1264
|
+
html: STABLE_DEBUG_HTML_PATH,
|
|
1265
|
+
json: STABLE_DEBUG_JSON_PATH
|
|
1266
|
+
},
|
|
1267
|
+
loader: {
|
|
1268
|
+
base: constants_STABLE_LOADER_BASE_PATH,
|
|
1269
|
+
umd: STABLE_LOADER_UMD_PATH
|
|
1270
|
+
}
|
|
1271
|
+
},
|
|
1272
|
+
components,
|
|
1273
|
+
events: {
|
|
1274
|
+
fullReload: ctx.contract?.events?.fullReload || '',
|
|
1275
|
+
hmrUpdate: ctx.contract?.events?.hmrUpdate || ''
|
|
1276
|
+
},
|
|
1277
|
+
protocol: {
|
|
1278
|
+
version: '2.0.0',
|
|
1279
|
+
apiLevel: 1
|
|
1280
|
+
}
|
|
1281
|
+
};
|
|
1282
|
+
res.statusCode = 200;
|
|
1283
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
1284
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
1285
|
+
res.setHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
|
|
1286
|
+
res.end(JSON.stringify(discovery, null, 2));
|
|
1287
|
+
return;
|
|
1288
|
+
}
|
|
1226
1289
|
if (url.startsWith(STABLE_DEBUG_JSON_PATH)) {
|
|
1227
1290
|
const isHttps = !!server.config.server.https;
|
|
1228
1291
|
const proto = isHttps ? 'https' : 'http';
|
|
@@ -1295,7 +1358,7 @@ function installDebugTools(server, ctx, state) {
|
|
|
1295
1358
|
}, null, 2));
|
|
1296
1359
|
return;
|
|
1297
1360
|
}
|
|
1298
|
-
if (pathname ===
|
|
1361
|
+
if (pathname === STABLE_LOADER_UMD_PATH) try {
|
|
1299
1362
|
const reactLoaderUmdPath = getReactLoaderUmdPath();
|
|
1300
1363
|
const umdCode = node_fs.readFileSync(reactLoaderUmdPath, 'utf-8');
|
|
1301
1364
|
res.statusCode = 200;
|
|
@@ -1309,8 +1372,8 @@ function installDebugTools(server, ctx, state) {
|
|
|
1309
1372
|
res.end(`${error instanceof Error ? error.message : String(error)}`);
|
|
1310
1373
|
return;
|
|
1311
1374
|
}
|
|
1312
|
-
if (pathname.startsWith(
|
|
1313
|
-
const loaderPathPattern = new RegExp(`^${
|
|
1375
|
+
if (pathname.startsWith(constants_STABLE_LOADER_BASE_PATH)) {
|
|
1376
|
+
const loaderPathPattern = new RegExp(`^${constants_STABLE_LOADER_BASE_PATH}/([^/]+)\\.js$`);
|
|
1314
1377
|
const match = pathname.match(loaderPathPattern);
|
|
1315
1378
|
if (match) {
|
|
1316
1379
|
const componentName = match[1];
|
|
@@ -1324,7 +1387,7 @@ function installDebugTools(server, ctx, state) {
|
|
|
1324
1387
|
componentName,
|
|
1325
1388
|
origin,
|
|
1326
1389
|
contractEndpoint: constants_STABLE_CONTRACT_PATH,
|
|
1327
|
-
reactLoaderUrl: `${origin}${
|
|
1390
|
+
reactLoaderUrl: `${origin}${STABLE_LOADER_UMD_PATH}`
|
|
1328
1391
|
});
|
|
1329
1392
|
res.statusCode = 200;
|
|
1330
1393
|
res.setHeader('Content-Type', "application/javascript; charset=utf-8");
|
|
@@ -1545,11 +1608,11 @@ function transformViteDevCssAssetUrls(code, id) {
|
|
|
1545
1608
|
if (!/\.(css|less|sass|scss|styl|stylus)$/.test(cleanId)) return null;
|
|
1546
1609
|
if (!code.includes('__vite__updateStyle') || !code.includes('const __vite__css')) return null;
|
|
1547
1610
|
if (!/url\(\s*['"]?\//.test(code)) return null;
|
|
1548
|
-
if (code.includes('
|
|
1611
|
+
if (code.includes('__dev_to__css')) return null;
|
|
1549
1612
|
const updateCallRE = /__vite__updateStyle\(\s*__vite__id\s*,\s*__vite__css\s*\)/;
|
|
1550
1613
|
if (!updateCallRE.test(code)) return null;
|
|
1551
1614
|
const injected = `
|
|
1552
|
-
const
|
|
1615
|
+
const __dev_to__resolveAsset = (path) => {
|
|
1553
1616
|
if (!path) return path;
|
|
1554
1617
|
if (path.startsWith('http://') || path.startsWith('https://') || path.startsWith('data:') || path.startsWith('blob:')) {
|
|
1555
1618
|
return path;
|
|
@@ -1569,12 +1632,12 @@ const __dev_to_react_resolveAsset = (path) => {
|
|
|
1569
1632
|
return path;
|
|
1570
1633
|
}
|
|
1571
1634
|
};
|
|
1572
|
-
const
|
|
1573
|
-
const next =
|
|
1635
|
+
const __dev_to__css = __vite__css.replace(/url\\(\\s*(['"]?)(\\/(?!\\/)[^'")]+)\\1\\s*\\)/g, (_m, q, p) => {
|
|
1636
|
+
const next = __dev_to__resolveAsset(p);
|
|
1574
1637
|
return 'url(' + q + next + q + ')';
|
|
1575
1638
|
});
|
|
1576
1639
|
`;
|
|
1577
|
-
const nextCode = code.replace(updateCallRE, `${injected}__vite__updateStyle(__vite__id,
|
|
1640
|
+
const nextCode = code.replace(updateCallRE, `${injected}__vite__updateStyle(__vite__id, __dev_to__css)`);
|
|
1578
1641
|
return {
|
|
1579
1642
|
code: nextCode,
|
|
1580
1643
|
map: null
|
|
@@ -2049,5 +2112,4 @@ function devToReactPlugin(components, options) {
|
|
|
2049
2112
|
libPostPlugin
|
|
2050
2113
|
];
|
|
2051
2114
|
}
|
|
2052
|
-
|
|
2053
|
-
export { EVENT_FULL_RELOAD, EVENT_HMR_UPDATE, PLUGIN_NAME, STABLE_BASE_PATH, STABLE_DEBUG_HTML_PATH, STABLE_DEBUG_JSON_PATH, STABLE_INIT_PATH, STABLE_REACT_RUNTIME_PATH, constants_PLUGIN_LOG_PREFIX as PLUGIN_LOG_PREFIX, constants_STABLE_CONTRACT_PATH as STABLE_CONTRACT_PATH, devToReactPlugin, viteHostReactBridgePlugin };
|
|
2115
|
+
export { EVENT_FULL_RELOAD, EVENT_HMR_UPDATE, PLUGIN_NAME, STABLE_BASE_PATH, STABLE_DEBUG_HTML_PATH, STABLE_DEBUG_JSON_PATH, STABLE_DISCOVERY_PATH, STABLE_INIT_PATH, STABLE_LOADER_UMD_PATH, STABLE_REACT_BASE_PATH, STABLE_REACT_RUNTIME_PATH, constants_PLUGIN_LOG_PREFIX as PLUGIN_LOG_PREFIX, constants_STABLE_CONTRACT_PATH as STABLE_CONTRACT_PATH, constants_STABLE_LOADER_BASE_PATH as STABLE_LOADER_BASE_PATH, devToReactPlugin };
|
package/dist/plugin.d.ts
CHANGED
|
@@ -41,6 +41,4 @@ import type { DevComponentMapInput, DevToReactPluginOptions } from './types.js';
|
|
|
41
41
|
* devToReactPlugin(undefined, { css: false })
|
|
42
42
|
*/
|
|
43
43
|
export declare function devToReactPlugin(components?: DevComponentMapInput, options?: DevToReactPluginOptions): any;
|
|
44
|
-
/** @deprecated Use `devToReactPlugin` instead. */
|
|
45
|
-
export declare const viteHostReactBridgePlugin: typeof devToReactPlugin;
|
|
46
44
|
//# sourceMappingURL=plugin.d.ts.map
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAIV,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,YAAY,CAAA;AA0BnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,CAAC,EAAE,oBAAoB,EACjC,OAAO,CAAC,EAAE,uBAAuB,GAChC,GAAG,CAggBL
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAIV,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,YAAY,CAAA;AA0BnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,CAAC,EAAE,oBAAoB,EACjC,OAAO,CAAC,EAAE,uBAAuB,GAChC,GAAG,CAggBL"}
|
package/dist/types.d.ts
CHANGED
|
@@ -64,8 +64,6 @@ export interface DevToReactPluginOptions {
|
|
|
64
64
|
*/
|
|
65
65
|
open?: boolean;
|
|
66
66
|
}
|
|
67
|
-
/** @deprecated Use `DevToReactPluginOptions` instead. */
|
|
68
|
-
export type ViteHostReactBridgePluginOptions = DevToReactPluginOptions;
|
|
69
67
|
/**
|
|
70
68
|
* Component configuration input type
|
|
71
69
|
*
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAEpD;;;;;;;;;;GAUG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;;;;;;;;;;;;;;OAiBG;IACH,GAAG,CAAC,EAAE,UAAU,GAAG,KAAK,CAAA;IAExB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,EAAE,YAAY,CAAA;IAEpB;;;;;;;;;OASG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAEpD;;;;;;;;;;GAUG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;;;;;;;;;;;;;;OAiBG;IACH,GAAG,CAAC,EAAE,UAAU,GAAG,KAAK,CAAA;IAExB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,KAAK,CAAC,EAAE,YAAY,CAAA;IAEpB;;;;;;;;;OASG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAA;AAErF,MAAM,WAAW,iBAAiB;IAChC,eAAe,EAAE,MAAM,CAAA;IACvB,kBAAkB,EAAE,OAAO,CAAA;IAC3B,iBAAiB,EAAE,MAAM,CAAA;IACzB,cAAc,EAAE,KAAK,CAAC;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CACnE;AAED,MAAM,WAAW,0BAA0B;IACzC,eAAe,EAAE,MAAM,CAAA;IACvB,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACpC,KAAK,EAAE,iBAAiB,CAAA;CACzB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,iBAAiB,CAAA;IAC3B,IAAI,EAAE,iBAAiB,CAAA;IACvB,OAAO,EAAE,iBAAiB,CAAA;CAC3B;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE;QACL,QAAQ,EAAE,MAAM,CAAA;QAChB,UAAU,EAAE,MAAM,CAAA;QAClB,YAAY,EAAE,MAAM,CAAA;KACrB,CAAA;IACD,MAAM,EAAE;QACN,UAAU,EAAE,MAAM,CAAA;QAClB,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;IACD,GAAG,EAAE;QACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KACrC,CAAA;CACF;AAED,MAAM,WAAW,iBAAiB;IAChC,uBAAuB,EAAE,OAAO,CAAA;CACjC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dev-to/react-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"picocolors": "^1.1.0",
|
|
33
33
|
"typescript": "^5.4.5",
|
|
34
|
-
"@dev-to/react-shared": "0.
|
|
34
|
+
"@dev-to/react-shared": "1.0.0"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "rslib build",
|