react-cosmos-plugin-vite 6.0.0-alpha.9 → 6.0.0-canary.0b048af.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.
@@ -1,5 +1,4 @@
1
1
  {
2
2
  "name": "Vite",
3
- "devServer": "dist/viteDevServerPlugin.js",
4
- "export": "dist/viteExportPlugin.js"
3
+ "server": "dist/viteServerPlugin.js"
5
4
  }
@@ -0,0 +1,6 @@
1
+ import { CosmosConfig } from 'react-cosmos';
2
+ type ViteCosmosConfig = {
3
+ port: number;
4
+ };
5
+ export declare function createViteCosmosConfig(cosmosConfig: CosmosConfig): ViteCosmosConfig;
6
+ export {};
@@ -0,0 +1,6 @@
1
+ export function createViteCosmosConfig(cosmosConfig) {
2
+ const configInput = cosmosConfig.vite || {};
3
+ return {
4
+ port: configInput.port || 5050,
5
+ };
6
+ }
@@ -10,6 +10,9 @@ async function mount() {
10
10
  mountDomRenderer(args);
11
11
  }
12
12
 
13
+ // Fallback for when React Refresh isn't enabled.
14
+ // Under normal conditions accepting HMR updates here isn't necessary because
15
+ // individual React modules will be hot reloaded by React Refresh.
13
16
  if (import.meta.hot) {
14
17
  import.meta.hot.accept(() => {
15
18
  mount();
@@ -1,4 +1,4 @@
1
- import { CosmosConfig } from 'react-cosmos/server.js';
1
+ import { CosmosConfig } from 'react-cosmos';
2
2
  import { Plugin } from 'rollup';
3
3
  export declare const userDepsVirtualModuleId = "virtual:cosmos-userdeps";
4
4
  export declare const userDepsResolvedModuleId: string;
@@ -1,5 +1,5 @@
1
1
  import path from 'path';
2
- import { generateUserDepsModule, getPlaygroundUrl, } from 'react-cosmos/server.js';
2
+ import { generateUserDepsModule, getPlaygroundUrl, } from 'react-cosmos';
3
3
  import { createViteRendererIndex } from './createViteRendererIndex.js';
4
4
  export const userDepsVirtualModuleId = 'virtual:cosmos-userdeps';
5
5
  export const userDepsResolvedModuleId = '\0' + userDepsVirtualModuleId;
@@ -0,0 +1,2 @@
1
+ import { CosmosConfig, CosmosConfigPluginArgs } from 'react-cosmos';
2
+ export declare function viteConfigPlugin({ cosmosConfig, }: CosmosConfigPluginArgs): Promise<CosmosConfig>;
@@ -0,0 +1,18 @@
1
+ import { findNextAvailablePort, } from 'react-cosmos';
2
+ import { createViteCosmosConfig } from './createViteCosmosConfig.js';
3
+ export async function viteConfigPlugin({ cosmosConfig, }) {
4
+ const { rendererUrl } = cosmosConfig;
5
+ if (rendererUrl) {
6
+ return cosmosConfig;
7
+ }
8
+ const viteCosmosConfig = createViteCosmosConfig(cosmosConfig);
9
+ const port = await findNextAvailablePort(viteCosmosConfig.port, cosmosConfig.portRetries);
10
+ return {
11
+ ...cosmosConfig,
12
+ rendererUrl: `http://localhost:${port}`,
13
+ vite: {
14
+ ...viteCosmosConfig,
15
+ port: port,
16
+ },
17
+ };
18
+ }
@@ -1,2 +1,2 @@
1
- import { DevServerPluginArgs } from 'react-cosmos/server.js';
2
- export default function viteDevServerPlugin({ platformType, cosmosConfig, }: DevServerPluginArgs): Promise<(() => void) | undefined>;
1
+ import { DevServerPluginArgs } from 'react-cosmos';
2
+ export declare function viteDevServerPlugin({ platformType, cosmosConfig, }: DevServerPluginArgs): Promise<(() => void) | undefined>;
@@ -1,7 +1,8 @@
1
- import { startFixtureWatcher, } from 'react-cosmos/server.js';
1
+ import viteReactPlugin from '@vitejs/plugin-react';
2
+ import { startFixtureWatcher } from 'react-cosmos';
2
3
  import { createServer } from 'vite';
3
4
  import { reactCosmosViteRollupPlugin, userDepsResolvedModuleId, } from './reactCosmosViteRollupPlugin.js';
4
- export default async function viteDevServerPlugin({ platformType, cosmosConfig, }) {
5
+ export async function viteDevServerPlugin({ platformType, cosmosConfig, }) {
5
6
  if (platformType !== 'web')
6
7
  return;
7
8
  const { rendererUrl } = cosmosConfig;
@@ -16,7 +17,7 @@ export default async function viteDevServerPlugin({ platformType, cosmosConfig,
16
17
  host: '0.0.0.0',
17
18
  port: parseInt(new URL(rendererUrl).port, 10),
18
19
  },
19
- plugins: [reactCosmosViteRollupPlugin(cosmosConfig)],
20
+ plugins: [viteReactPlugin(), reactCosmosViteRollupPlugin(cosmosConfig)],
20
21
  });
21
22
  await server.listen();
22
23
  server.printUrls();
@@ -1,2 +1,2 @@
1
- import { ExportPluginArgs } from 'react-cosmos/server.js';
2
- export default function viteExportPlugin({ cosmosConfig, }: ExportPluginArgs): Promise<void>;
1
+ import { ExportPluginArgs } from 'react-cosmos';
2
+ export declare function viteExportPlugin({ cosmosConfig }: ExportPluginArgs): Promise<void>;
@@ -1,10 +1,11 @@
1
+ import viteReactPlugin from '@vitejs/plugin-react';
1
2
  import { rename } from 'node:fs/promises';
2
3
  import path from 'path';
4
+ import { RENDERER_FILENAME } from 'react-cosmos';
3
5
  import { removeLeadingSlash } from 'react-cosmos-core';
4
- import { RENDERER_FILENAME } from 'react-cosmos/server.js';
5
6
  import { build } from 'vite';
6
7
  import { reactCosmosViteRollupPlugin } from './reactCosmosViteRollupPlugin.js';
7
- export default async function viteExportPlugin({ cosmosConfig, }) {
8
+ export async function viteExportPlugin({ cosmosConfig }) {
8
9
  const { exportPath, publicUrl } = cosmosConfig;
9
10
  await build({
10
11
  configFile: false,
@@ -15,7 +16,7 @@ export default async function viteExportPlugin({ cosmosConfig, }) {
15
16
  emptyOutDir: false,
16
17
  minify: false,
17
18
  },
18
- plugins: [reactCosmosViteRollupPlugin(cosmosConfig)],
19
+ plugins: [viteReactPlugin(), reactCosmosViteRollupPlugin(cosmosConfig)],
19
20
  });
20
21
  // Make way for the Playground's index.html
21
22
  await rename(path.resolve(exportPath, 'index.html'), path.resolve(exportPath, RENDERER_FILENAME));
@@ -0,0 +1,3 @@
1
+ import { CosmosServerPlugin } from 'react-cosmos';
2
+ declare const viteServerPlugin: CosmosServerPlugin;
3
+ export default viteServerPlugin;
@@ -0,0 +1,10 @@
1
+ import { viteConfigPlugin } from './viteConfigPlugin.js';
2
+ import { viteDevServerPlugin } from './viteDevServerPlugin.js';
3
+ import { viteExportPlugin } from './viteExportPlugin.js';
4
+ const viteServerPlugin = {
5
+ name: 'vite',
6
+ config: viteConfigPlugin,
7
+ devServer: viteDevServerPlugin,
8
+ export: viteExportPlugin,
9
+ };
10
+ export default viteServerPlugin;
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "react-cosmos-plugin-vite",
3
- "version": "6.0.0-alpha.9",
3
+ "version": "6.0.0-canary.0b048af.0+0b048af",
4
4
  "description": "Vite plugin for React Cosmos",
5
5
  "repository": "https://github.com/react-cosmos/react-cosmos/tree/main/packages/react-cosmos-plugin-vite",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "main": "cosmos.plugin.json",
9
9
  "dependencies": {
10
- "react-cosmos-core": "^6.0.0-alpha.9",
11
- "react-cosmos-dom": "^6.0.0-alpha.9"
10
+ "@vitejs/plugin-react": "^3.1.0",
11
+ "react-cosmos-core": "6.0.0-canary.0b048af.0+0b048af",
12
+ "react-cosmos-dom": "6.0.0-canary.0b048af.0+0b048af"
12
13
  },
13
14
  "peerDependencies": {
14
15
  "vite": "*"
15
16
  },
16
- "gitHead": "b155b223f904f5cc29e2f13ac79ab7c4b302ed2b"
17
+ "gitHead": "0b048af65a4a302d42c6f62d94ef7470706fa85b"
17
18
  }