react-cosmos-plugin-vite 6.0.0-alpha.15 → 6.0.0-alpha.17
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 +1 @@
|
|
|
1
|
-
export declare function createViteRendererIndex(
|
|
1
|
+
export declare function createViteRendererIndex(userImportsModuleId: string): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function createViteRendererIndex(
|
|
1
|
+
export function createViteRendererIndex(userImportsModuleId) {
|
|
2
2
|
return `
|
|
3
3
|
import { mountDomRenderer } from 'react-cosmos-dom';
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ mount();
|
|
|
6
6
|
|
|
7
7
|
async function mount() {
|
|
8
8
|
// Use dynamic import to reload updated modules upon hot reloading
|
|
9
|
-
const args = await import('${
|
|
9
|
+
const args = await import('${userImportsModuleId}');
|
|
10
10
|
mountDomRenderer(args);
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CosmosConfig } from 'react-cosmos';
|
|
2
2
|
import { Plugin } from 'rollup';
|
|
3
3
|
import { CosmosViteConfig } from './createCosmosViteConfig.js';
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
4
|
+
export declare const userImportsVirtualModuleId = "virtual:cosmos-imports";
|
|
5
|
+
export declare const userImportsResolvedModuleId: string;
|
|
6
6
|
export declare function reactCosmosViteRollupPlugin(cosmosConfig: CosmosConfig, cosmosViteConfig: CosmosViteConfig): Plugin;
|
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import {
|
|
2
|
+
import { generateUserImports, getPlaygroundUrl, } from 'react-cosmos';
|
|
3
3
|
import { createViteRendererIndex } from './createViteRendererIndex.js';
|
|
4
|
-
export const
|
|
5
|
-
export const
|
|
4
|
+
export const userImportsVirtualModuleId = 'virtual:cosmos-imports';
|
|
5
|
+
export const userImportsResolvedModuleId = '\0' + userImportsVirtualModuleId;
|
|
6
6
|
const defaultIndexPattern = new RegExp(`^(src\\${path.sep})?(index|main)\.(js|ts)x?$`);
|
|
7
7
|
export function reactCosmosViteRollupPlugin(cosmosConfig, cosmosViteConfig) {
|
|
8
8
|
return {
|
|
9
9
|
name: 'react-cosmos-vite-renderer',
|
|
10
10
|
resolveId(id) {
|
|
11
|
-
if (id ===
|
|
12
|
-
return
|
|
11
|
+
if (id === userImportsVirtualModuleId) {
|
|
12
|
+
return userImportsResolvedModuleId;
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
load(id) {
|
|
19
|
-
if (id ==
|
|
20
|
-
return
|
|
19
|
+
if (id == userImportsResolvedModuleId) {
|
|
20
|
+
return generateUserImports({
|
|
21
21
|
cosmosConfig,
|
|
22
22
|
rendererConfig: {
|
|
23
23
|
playgroundUrl: getPlaygroundUrl(cosmosConfig),
|
|
24
24
|
containerQuerySelector: cosmosConfig.dom.containerQuerySelector,
|
|
25
25
|
},
|
|
26
26
|
relativeToDir: null,
|
|
27
|
+
typeScript: false,
|
|
27
28
|
});
|
|
28
29
|
}
|
|
29
30
|
else {
|
|
@@ -38,7 +39,7 @@ export function reactCosmosViteRollupPlugin(cosmosConfig, cosmosViteConfig) {
|
|
|
38
39
|
const relPath = path.relative(process.cwd(), id);
|
|
39
40
|
console.log(`[Cosmos] Replacing vite index module at ${relPath}`);
|
|
40
41
|
return {
|
|
41
|
-
code: createViteRendererIndex(
|
|
42
|
+
code: createViteRendererIndex(userImportsVirtualModuleId),
|
|
42
43
|
map: null,
|
|
43
44
|
};
|
|
44
45
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { startFixtureWatcher } from 'react-cosmos';
|
|
2
2
|
import { createServer } from 'vite';
|
|
3
3
|
import { createCosmosViteConfig } from './createCosmosViteConfig.js';
|
|
4
|
-
import { reactCosmosViteRollupPlugin,
|
|
4
|
+
import { reactCosmosViteRollupPlugin, userImportsResolvedModuleId, } from './reactCosmosViteRollupPlugin.js';
|
|
5
5
|
export async function viteDevServerPlugin({ platformType, cosmosConfig, }) {
|
|
6
6
|
if (platformType !== 'web')
|
|
7
7
|
return;
|
|
@@ -25,9 +25,9 @@ export async function viteDevServerPlugin({ platformType, cosmosConfig, }) {
|
|
|
25
25
|
});
|
|
26
26
|
await server.listen();
|
|
27
27
|
const watcher = await startFixtureWatcher(cosmosConfig, 'add', () => {
|
|
28
|
-
const module = server.moduleGraph.getModuleById(
|
|
28
|
+
const module = server.moduleGraph.getModuleById(userImportsResolvedModuleId);
|
|
29
29
|
if (!module) {
|
|
30
|
-
throw new Error(`Vite module graph doesn't contain module with id ${
|
|
30
|
+
throw new Error(`Vite module graph doesn't contain module with id ${userImportsResolvedModuleId}`);
|
|
31
31
|
}
|
|
32
32
|
server.moduleGraph.invalidateModule(module);
|
|
33
33
|
server.reloadModule(module);
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-cosmos-plugin-vite",
|
|
3
|
-
"version": "6.0.0-alpha.
|
|
3
|
+
"version": "6.0.0-alpha.17",
|
|
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.
|
|
11
|
-
"react-cosmos-dom": "6.0.0-alpha.
|
|
10
|
+
"react-cosmos-core": "6.0.0-alpha.17",
|
|
11
|
+
"react-cosmos-dom": "6.0.0-alpha.17"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"vite": "*"
|
|
15
15
|
},
|
|
16
|
-
"gitHead": "
|
|
16
|
+
"gitHead": "2369058dc27280b59ef854a9246086d99e94990b"
|
|
17
17
|
}
|