vite-plugin-enter-dev 0.0.8 → 0.0.10

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/dist/index.d.ts CHANGED
@@ -5,6 +5,17 @@ interface DevOptions {
5
5
  * 是否注入消息监听器脚本(默认:true)
6
6
  */
7
7
  injectMessageListener?: boolean;
8
+ /**
9
+ * 是否注册 @vitejs/plugin-react(默认:true)。
10
+ *
11
+ * 宿主框架自己已经注册了 React 转换时必须传 false:vinext 会在
12
+ * configResolved 里检测重复注册并直接抛错
13
+ * ("[vinext] Duplicate @vitejs/plugin-react detected"),
14
+ * 整个 dev server 和 build 都起不来。关掉后本插件只保留
15
+ * allowedHosts / 端口 / base / 消息监听,代价是失去可视化编辑
16
+ * 需要的源码位置注入。
17
+ */
18
+ react?: boolean;
8
19
  }
9
20
  declare function enterDevPlugin(options?: DevOptions): Plugin[];
10
21
  interface ProdOptions {
package/dist/index.js CHANGED
@@ -287,9 +287,10 @@ function getParentElementType(parentNode) {
287
287
  // src/index.ts
288
288
  function enterDevPlugin(options = {}) {
289
289
  const {
290
- injectMessageListener = true
290
+ injectMessageListener = true,
291
+ react: enableReact = true
291
292
  } = options;
292
- const reactPlugin = react({
293
+ const reactPlugin = enableReact ? react({
293
294
  // 确保在开发模式下启用JSX源码映射
294
295
  jsxImportSource: void 0,
295
296
  jsxRuntime: "automatic",
@@ -310,7 +311,7 @@ function enterDevPlugin(options = {}) {
310
311
  ]
311
312
  ]
312
313
  }
313
- });
314
+ }) : [];
314
315
  const htmlInjectPlugin = {
315
316
  name: "enter-dev-message-listener",
316
317
  enforce: "pre",
@@ -325,6 +326,21 @@ function enterDevPlugin(options = {}) {
325
326
  window.__earlyConsoleLogs__ = [];
326
327
 
327
328
  const earlyErrorHandler = function(event) {
329
+ const target = event.target;
330
+ if (target && (target.tagName === 'SCRIPT' || target.tagName === 'LINK')) {
331
+ const isStylesheet =
332
+ target.tagName === 'LINK' &&
333
+ String(target.rel || '').toLowerCase().split(/s+/).includes('stylesheet');
334
+ if (target.tagName === 'SCRIPT' || isStylesheet) {
335
+ window.__earlyErrors__.push({
336
+ type: 'resource',
337
+ resourceType: target.tagName === 'SCRIPT' ? 'script' : 'stylesheet',
338
+ url: target.src || target.href || '',
339
+ timestamp: Date.now()
340
+ });
341
+ return;
342
+ }
343
+ }
328
344
  window.__earlyErrors__.push({
329
345
  type: 'error',
330
346
  message: event.message,
@@ -465,12 +481,33 @@ function enterDevPlugin(options = {}) {
465
481
  );
466
482
  }
467
483
  };
468
- return [...reactPlugin, htmlInjectPlugin, sandboxServerPlugin, routerBasePlugin];
484
+ const publicAssetReloadPlugin = {
485
+ name: "enter-dev-public-asset-reload",
486
+ apply: "serve",
487
+ configureServer(server) {
488
+ if (!process.cwd().startsWith("/workspace")) return;
489
+ const publicDir = server.config.publicDir;
490
+ const inPublicDir = (file) => file === publicDir || file.startsWith(`${publicDir}/`);
491
+ let timer;
492
+ const scheduleReload = () => {
493
+ clearTimeout(timer);
494
+ timer = setTimeout(() => {
495
+ server.ws.send({ type: "full-reload" });
496
+ }, 300);
497
+ };
498
+ for (const event of ["change", "add", "unlink"]) {
499
+ server.watcher.on(event, (file) => {
500
+ if (inPublicDir(file)) scheduleReload();
501
+ });
502
+ }
503
+ }
504
+ };
505
+ return [...reactPlugin, htmlInjectPlugin, sandboxServerPlugin, routerBasePlugin, publicAssetReloadPlugin];
469
506
  }
470
507
  function enterProdPlugin(options = {}) {
471
508
  const {
472
509
  injectGoogleFonts = true,
473
- googleFontsUrl = "https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900;950&family=Poppins:wght@100;200;300;400;500;600;700;800;900;950&family=Roboto:wght@100;200;300;400;500;600;700;800;900;950&display=swap"
510
+ googleFontsUrl = "https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Cormorant+Garamond:ital,wght@0,300..700;1,300..700&family=DM+Sans:ital,opsz,wght@0,9..40,100..1000;1,9..40,100..1000&family=Funnel+Display:wght@300..800&family=Instrument+Sans:ital,wght@0,400..700;1,400..700&family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Lato:ital,wght@0,100;0,300;0,400;0,700;0,900;1,100;1,300;1,400;1,700;1,900&family=Lora:ital,wght@0,400..700;1,400..700&family=Manrope:wght@200..800&family=Merriweather:ital,opsz,wght@0,18..144,300..900;1,18..144,300..900&family=Montserrat:ital,wght@0,100..900;1,100..900&family=Nunito:ital,wght@0,200..1000;1,200..1000&family=Open+Sans:ital,wght@0,300..800;1,300..800&family=Oswald:wght@200..700&family=Playfair+Display:ital,wght@0,400..900;1,400..900&family=Poppins:ital,wght@0,100..900;1,100..900&family=Raleway:ital,wght@0,100..900;1,100..900&family=Roboto:ital,wght@0,100..900;1,100..900&family=Space+Grotesk:wght@300..700&family=Work+Sans:ital,wght@0,100..900;1,100..900&display=swap"
474
511
  } = options;
475
512
  const fontsInjectPlugin = {
476
513
  name: "enter-prod-fonts-inject",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-enter-dev",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "description": "A Vite plugin for development enhancements",
@@ -19,7 +19,11 @@
19
19
  "scripts": {
20
20
  "build": "tsup",
21
21
  "dev": "tsup --watch",
22
- "lint": "eslint . --max-warnings 0"
22
+ "lint": "eslint . --max-warnings 0",
23
+ "typecheck": "tsc --noEmit"
24
+ },
25
+ "publishConfig": {
26
+ "registry": "https://registry.npmjs.org/"
23
27
  },
24
28
  "keywords": [
25
29
  "vite",
@@ -40,7 +44,7 @@
40
44
  "vite": "^6.0.0"
41
45
  },
42
46
  "peerDependencies": {
43
- "vite": "^5.0.0 || ^6.0.0"
47
+ "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
44
48
  },
45
49
  "dependencies": {
46
50
  "@vitejs/plugin-react": "^5.1.1"