@shadow-js/vite
Advanced tools
+1
-1
@@ -37,3 +37,3 @@ 'use strict'; | ||
| runtime: "automatic", | ||
| importSource: "shadow-js" | ||
| importSource: "@shadow-js/core" | ||
| } | ||
@@ -40,0 +40,0 @@ }, |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/index.ts"],"names":["transformSource","swcTransform"],"mappings":";;;;;;AA8De,SAAR,MAAA,GAAwC;AAC7C,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,iBAAA;AAAA,IACN,OAAA,EAAS,KAAA;AAAA;AAAA,IAGT,MAAA,GAAS;AACP,MAAA,OAAO;AAAA,QACL,OAAA,EAAS;AAAA,UACP,GAAA,EAAK;AAAA;AACP,OACF;AAAA,IACF,CAAA;AAAA,IAEA,MAAM,SAAA,CAAU,IAAA,EAAM,EAAA,EAAI;AAExB,MAAA,IAAI,CAAC,cAAA,CAAe,IAAA,CAAK,EAAE,GAAG,OAAO,IAAA;AACrC,MAAA,IAAI,EAAA,CAAG,QAAA,CAAS,cAAc,CAAA,EAAG,OAAO,IAAA;AAGxC,MAAA,IAAI,eAAA;AACJ,MAAA,IAAI;AACF,QAAA,eAAA,GAAkBA,yBAAgB,IAAI,CAAA;AAAA,MACxC,SAAS,CAAA,EAAG;AACV,QAAA,MAAM,MAAM,CAAA,YAAa,KAAA,GAAQ,CAAA,CAAE,OAAA,GAAU,OAAO,CAAC,CAAA;AACrD,QAAA,MAAM,IAAI,KAAA,CAAM,CAAA,qCAAA,EAAwC,EAAE,CAAA,EAAA,EAAK,GAAG,CAAA,CAAE,CAAA;AAAA,MACtE;AAGA,MAAA,IAAI;AACF,QAAA,MAAM,MAAA,GAAS,MAAMC,cAAA,CAAa,eAAA,EAAiB;AAAA,UACjD,QAAA,EAAU,EAAA;AAAA,UACV,GAAA,EAAK;AAAA,YACH,MAAA,EAAQ,EAAE,MAAA,EAAQ,YAAA,EAAc,KAAK,IAAA,EAAK;AAAA,YAC1C,SAAA,EAAW;AAAA,cACT,KAAA,EAAO;AAAA,gBACL,OAAA,EAAS,WAAA;AAAA,gBACT,YAAA,EAAc;AAAA;AAChB,aACF;AAAA,YACA,MAAA,EAAQ;AAAA,WACV;AAAA,UACA,MAAA,EAAQ,EAAE,IAAA,EAAM,KAAA,EAAM;AAAA,UACtB,UAAA,EAAY;AAAA,SACb,CAAA;AAED,QAAA,OAAO;AAAA,UACL,MAAM,MAAA,CAAO,IAAA;AAAA,UACb,GAAA,EAAK,OAAO,GAAA,IAAO;AAAA,SACrB;AAAA,MACF,SAAS,CAAA,EAAG;AACV,QAAA,MAAM,MAAM,CAAA,YAAa,KAAA,GAAQ,CAAA,CAAE,OAAA,GAAU,OAAO,CAAC,CAAA;AACrD,QAAA,MAAM,IAAI,KAAA,CAAM,CAAA,gCAAA,EAAmC,EAAE,CAAA,EAAA,EAAK,GAAG,CAAA,CAAE,CAAA;AAAA,MACjE;AAAA,IACF;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["import type { PluginOption } from \"vite\";\nimport { transformSource } from \"@shadow-js/compiler\";\nimport { transform as swcTransform } from \"@swc/core\";\n\n/**\n * Shadow Vite Plugin\n *\n * This plugin integrates Shadow with Vite to provide seamless development experience.\n * It handles the complete transformation pipeline from TSX/JSX source code to\n * Shadow-compatible JavaScript with reactive expressions.\n *\n * Plugin Pipeline:\n * 1. **Shadow Compiler**: Applies JSX transformations to inject reactive functions\n * 2. **SWC Transformation**: Converts TypeScript/JSX to JavaScript with proper imports\n * 3. **JSX Runtime Injection**: Automatically imports Shadow's JSX runtime functions\n * 4. **Source Map Generation**: Preserves debugging capabilities\n *\n * Features:\n * - **Selective Processing**: Only transforms user code (excludes node_modules)\n * - **TypeScript Support**: Full TypeScript and TSX compilation\n * - **Hot Module Replacement**: Compatible with Vite's HMR system\n * - **Error Handling**: Provides clear error messages for compilation failures\n * - **Performance**: Uses fast SWC compiler for optimal build speeds\n *\n * The plugin automatically configures Vite to preserve JSX for SWC processing\n * instead of using esbuild's JSX transform, ensuring compatibility with Shadow's\n * reactive programming model.\n *\n * @returns Vite PluginOption instance for Shadow integration\n *\n * @example\n * ```typescript\n * // vite.config.ts\n * import { defineConfig } from \"vite\";\n * import shadow from \"@shadow-js/vite\";\n *\n * export default defineConfig({\n * plugins: [shadow()]\n * })\n * ```\n *\n * @example\n * ```typescript\n * // Your component file (App.tsx)\n * import { useStore, Show } from \"shadow-js\";\n *\n * function App() {\n * const [count, setCount] = useStore(0)\n *\n * return (\n * <div>\n * <button onClick={() => setCount((c) => c + 1)}>\n * Increment\n * </button>\n * <Show when={count() > 0}>\n * <div>Count: {count()}</div>\n * </Show>\n * </div>\n * )\n * }\n * ```\n */\nexport default function shadow(): PluginOption {\n return {\n name: \"@shadow-js/vite\",\n enforce: \"pre\",\n\n // Prevent esbuild from also transforming JSX to avoid double transforms.\n config() {\n return {\n esbuild: {\n jsx: \"preserve\",\n },\n };\n },\n\n async transform(code, id) {\n // Only TSX/JSX user files\n if (!/\\.(tsx|jsx)$/.test(id)) return null;\n if (id.includes(\"node_modules\")) return null;\n\n // 1) Apply Shadow compiler transforms on source text\n let transformedCode: string;\n try {\n transformedCode = transformSource(code);\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new Error(`ShadowJS (vite): compiler failed for ${id}: ${msg}`);\n }\n\n // 2) Use SWC to handle TS/JSX -> JS and inject jsx runtime imports\n try {\n const result = await swcTransform(transformedCode, {\n filename: id,\n jsc: {\n parser: { syntax: \"typescript\", tsx: true },\n transform: {\n react: {\n runtime: \"automatic\",\n importSource: \"shadow-js\",\n },\n },\n target: \"es2022\",\n },\n module: { type: \"es6\" },\n sourceMaps: true,\n });\n\n return {\n code: result.code,\n map: result.map ?? null,\n };\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new Error(`ShadowJS (vite): SWC failed for ${id}: ${msg}`);\n }\n },\n } satisfies PluginOption;\n}\n"]} | ||
| {"version":3,"sources":["../src/index.ts"],"names":["transformSource","swcTransform"],"mappings":";;;;;;AA8De,S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M,MAAA,CAAO,IAAA;AAAA,UACb,GAAA,EAAK,OAAO,GAAA,IAAO;AAAA,SACrB;AAAA,MACF,SAAS,CAAA,EAAG;AACV,QAAA,MAAM,MAAM,CAAA,YAAa,KAAA,GAAQ,CAAA,CAAE,OAAA,GAAU,OAAO,CAAC,CAAA;AACrD,QAAA,MAAM,IAAI,KAAA,CAAM,CAAA,gCAAA,EAAmC,EAAE,CAAA,EAAA,EAAK,GAAG,CAAA,CAAE,CAAA;AAAA,MACjE;AAAA,IACF;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["import type { PluginOption } from \"vite\";\nimport { transformSource } from \"@shadow-js/compiler\";\nimport { transform as swcTransform } from \"@swc/core\";\n\n/**\n * Shadow Vite Plugin\n *\n * This plugin integrates Shadow with Vite to provide seamless development experience.\n * It handles the complete transformation pipeline from TSX/JSX source code to\n * Shadow-compatible JavaScript with reactive expressions.\n *\n * Plugin Pipeline:\n * 1. **Shadow Compiler**: Applies JSX transformations to inject reactive functions\n * 2. **SWC Transformation**: Converts TypeScript/JSX to JavaScript with proper imports\n * 3. **JSX Runtime Injection**: Automatically imports Shadow's JSX runtime functions\n * 4. **Source Map Generation**: Preserves debugging capabilities\n *\n * Features:\n * - **Selective Processing**: Only transforms user code (excludes node_modules)\n * - **TypeScript Support**: Full TypeScript and TSX compilation\n * - **Hot Module Replacement**: Compatible with Vite's HMR system\n * - **Error Handling**: Provides clear error messages for compilation failures\n * - **Performance**: Uses fast SWC compiler for optimal build speeds\n *\n * The plugin automatically configures Vite to preserve JSX for SWC processing\n * instead of using esbuild's JSX transform, ensuring compatibility with Shadow's\n * reactive programming model.\n *\n * @returns Vite PluginOption instance for Shadow integration\n *\n * @example\n * ```typescript\n * // vite.config.ts\n * import { defineConfig } from \"vite\";\n * import shadow from \"@shadow-js/vite\";\n *\n * export default defineConfig({\n * plugins: [shadow()]\n * })\n * ```\n *\n * @example\n * ```typescript\n * // Your component file (App.tsx)\n * import { useStore, Show } from \"@shadow-js/core\";\n *\n * function App() {\n * const [count, setCount] = useStore(0)\n *\n * return (\n * <div>\n * <button onClick={() => setCount((c) => c + 1)}>\n * Increment\n * </button>\n * <Show when={count() > 0}>\n * <div>Count: {count()}</div>\n * </Show>\n * </div>\n * )\n * }\n * ```\n */\nexport default function shadow(): PluginOption {\n return {\n name: \"@shadow-js/vite\",\n enforce: \"pre\",\n\n // Prevent esbuild from also transforming JSX to avoid double transforms.\n config() {\n return {\n esbuild: {\n jsx: \"preserve\",\n },\n };\n },\n\n async transform(code, id) {\n // Only TSX/JSX user files\n if (!/\\.(tsx|jsx)$/.test(id)) return null;\n if (id.includes(\"node_modules\")) return null;\n\n // 1) Apply Shadow compiler transforms on source text\n let transformedCode: string;\n try {\n transformedCode = transformSource(code);\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new Error(`ShadowJS (vite): compiler failed for ${id}: ${msg}`);\n }\n\n // 2) Use SWC to handle TS/JSX -> JS and inject jsx runtime imports\n try {\n const result = await swcTransform(transformedCode, {\n filename: id,\n jsc: {\n parser: { syntax: \"typescript\", tsx: true },\n transform: {\n react: {\n runtime: \"automatic\",\n importSource: \"@shadow-js/core\",\n },\n },\n target: \"es2022\",\n },\n module: { type: \"es6\" },\n sourceMaps: true,\n });\n\n return {\n code: result.code,\n map: result.map ?? null,\n };\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new Error(`ShadowJS (vite): SWC failed for ${id}: ${msg}`);\n }\n },\n } satisfies PluginOption;\n}\n"]} |
+1
-1
@@ -43,3 +43,3 @@ import { PluginOption } from 'vite'; | ||
| * // Your component file (App.tsx) | ||
| * import { useStore, Show } from "shadow-js"; | ||
| * import { useStore, Show } from "@shadow-js/core"; | ||
| * | ||
@@ -46,0 +46,0 @@ * function App() { |
+1
-1
@@ -43,3 +43,3 @@ import { PluginOption } from 'vite'; | ||
| * // Your component file (App.tsx) | ||
| * import { useStore, Show } from "shadow-js"; | ||
| * import { useStore, Show } from "@shadow-js/core"; | ||
| * | ||
@@ -46,0 +46,0 @@ * function App() { |
+1
-1
@@ -35,3 +35,3 @@ import { transformSource } from '@shadow-js/compiler'; | ||
| runtime: "automatic", | ||
| importSource: "shadow-js" | ||
| importSource: "@shadow-js/core" | ||
| } | ||
@@ -38,0 +38,0 @@ }, |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["../src/index.ts"],"names":["swcTransform"],"mappings":";;;;AA8De,SAAR,MAAA,GAAwC;AAC7C,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,iBAAA;AAAA,IACN,OAAA,EAAS,KAAA;AAAA;AAAA,IAGT,MAAA,GAAS;AACP,MAAA,OAAO;AAAA,QACL,OAAA,EAAS;AAAA,UACP,GAAA,EAAK;AAAA;AACP,OACF;AAAA,IACF,CAAA;AAAA,IAEA,MAAM,SAAA,CAAU,IAAA,EAAM,EAAA,EAAI;AAExB,MAAA,IAAI,CAAC,cAAA,CAAe,IAAA,CAAK,EAAE,GAAG,OAAO,IAAA;AACrC,MAAA,IAAI,EAAA,CAAG,QAAA,CAAS,cAAc,CAAA,EAAG,OAAO,IAAA;AAGxC,MAAA,IAAI,eAAA;AACJ,MAAA,IAAI;AACF,QAAA,eAAA,GAAkB,gBAAgB,IAAI,CAAA;AAAA,MACxC,SAAS,CAAA,EAAG;AACV,QAAA,MAAM,MAAM,CAAA,YAAa,KAAA,GAAQ,CAAA,CAAE,OAAA,GAAU,OAAO,CAAC,CAAA;AACrD,QAAA,MAAM,IAAI,KAAA,CAAM,CAAA,qCAAA,EAAwC,EAAE,CAAA,EAAA,EAAK,GAAG,CAAA,CAAE,CAAA;AAAA,MACtE;AAGA,MAAA,IAAI;AACF,QAAA,MAAM,MAAA,GAAS,MAAMA,SAAA,CAAa,eAAA,EAAiB;AAAA,UACjD,QAAA,EAAU,EAAA;AAAA,UACV,GAAA,EAAK;AAAA,YACH,MAAA,EAAQ,EAAE,MAAA,EAAQ,YAAA,EAAc,KAAK,IAAA,EAAK;AAAA,YAC1C,SAAA,EAAW;AAAA,cACT,KAAA,EAAO;AAAA,gBACL,OAAA,EAAS,WAAA;AAAA,gBACT,YAAA,EAAc;AAAA;AAChB,aACF;AAAA,YACA,MAAA,EAAQ;AAAA,WACV;AAAA,UACA,MAAA,EAAQ,EAAE,IAAA,EAAM,KAAA,EAAM;AAAA,UACtB,UAAA,EAAY;AAAA,SACb,CAAA;AAED,QAAA,OAAO;AAAA,UACL,MAAM,MAAA,CAAO,IAAA;AAAA,UACb,GAAA,EAAK,OAAO,GAAA,IAAO;AAAA,SACrB;AAAA,MACF,SAAS,CAAA,EAAG;AACV,QAAA,MAAM,MAAM,CAAA,YAAa,KAAA,GAAQ,CAAA,CAAE,OAAA,GAAU,OAAO,CAAC,CAAA;AACrD,QAAA,MAAM,IAAI,KAAA,CAAM,CAAA,gCAAA,EAAmC,EAAE,CAAA,EAAA,EAAK,GAAG,CAAA,CAAE,CAAA;AAAA,MACjE;AAAA,IACF;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import type { PluginOption } from \"vite\";\nimport { transformSource } from \"@shadow-js/compiler\";\nimport { transform as swcTransform } from \"@swc/core\";\n\n/**\n * Shadow Vite Plugin\n *\n * This plugin integrates Shadow with Vite to provide seamless development experience.\n * It handles the complete transformation pipeline from TSX/JSX source code to\n * Shadow-compatible JavaScript with reactive expressions.\n *\n * Plugin Pipeline:\n * 1. **Shadow Compiler**: Applies JSX transformations to inject reactive functions\n * 2. **SWC Transformation**: Converts TypeScript/JSX to JavaScript with proper imports\n * 3. **JSX Runtime Injection**: Automatically imports Shadow's JSX runtime functions\n * 4. **Source Map Generation**: Preserves debugging capabilities\n *\n * Features:\n * - **Selective Processing**: Only transforms user code (excludes node_modules)\n * - **TypeScript Support**: Full TypeScript and TSX compilation\n * - **Hot Module Replacement**: Compatible with Vite's HMR system\n * - **Error Handling**: Provides clear error messages for compilation failures\n * - **Performance**: Uses fast SWC compiler for optimal build speeds\n *\n * The plugin automatically configures Vite to preserve JSX for SWC processing\n * instead of using esbuild's JSX transform, ensuring compatibility with Shadow's\n * reactive programming model.\n *\n * @returns Vite PluginOption instance for Shadow integration\n *\n * @example\n * ```typescript\n * // vite.config.ts\n * import { defineConfig } from \"vite\";\n * import shadow from \"@shadow-js/vite\";\n *\n * export default defineConfig({\n * plugins: [shadow()]\n * })\n * ```\n *\n * @example\n * ```typescript\n * // Your component file (App.tsx)\n * import { useStore, Show } from \"shadow-js\";\n *\n * function App() {\n * const [count, setCount] = useStore(0)\n *\n * return (\n * <div>\n * <button onClick={() => setCount((c) => c + 1)}>\n * Increment\n * </button>\n * <Show when={count() > 0}>\n * <div>Count: {count()}</div>\n * </Show>\n * </div>\n * )\n * }\n * ```\n */\nexport default function shadow(): PluginOption {\n return {\n name: \"@shadow-js/vite\",\n enforce: \"pre\",\n\n // Prevent esbuild from also transforming JSX to avoid double transforms.\n config() {\n return {\n esbuild: {\n jsx: \"preserve\",\n },\n };\n },\n\n async transform(code, id) {\n // Only TSX/JSX user files\n if (!/\\.(tsx|jsx)$/.test(id)) return null;\n if (id.includes(\"node_modules\")) return null;\n\n // 1) Apply Shadow compiler transforms on source text\n let transformedCode: string;\n try {\n transformedCode = transformSource(code);\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new Error(`ShadowJS (vite): compiler failed for ${id}: ${msg}`);\n }\n\n // 2) Use SWC to handle TS/JSX -> JS and inject jsx runtime imports\n try {\n const result = await swcTransform(transformedCode, {\n filename: id,\n jsc: {\n parser: { syntax: \"typescript\", tsx: true },\n transform: {\n react: {\n runtime: \"automatic\",\n importSource: \"shadow-js\",\n },\n },\n target: \"es2022\",\n },\n module: { type: \"es6\" },\n sourceMaps: true,\n });\n\n return {\n code: result.code,\n map: result.map ?? null,\n };\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new Error(`ShadowJS (vite): SWC failed for ${id}: ${msg}`);\n }\n },\n } satisfies PluginOption;\n}\n"]} | ||
| {"version":3,"sources":["../src/index.ts"],"names":["swcTransform"],"mappings":";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,UACL,MAAM,MAAA,CAAO,IAAA;AAAA,UACb,GAAA,EAAK,OAAO,GAAA,IAAO;AAAA,SACrB;AAAA,MACF,SAAS,CAAA,EAAG;AACV,QAAA,MAAM,MAAM,CAAA,YAAa,KAAA,GAAQ,CAAA,CAAE,OAAA,GAAU,OAAO,CAAC,CAAA;AACrD,QAAA,MAAM,IAAI,KAAA,CAAM,CAAA,gCAAA,EAAmC,EAAE,CAAA,EAAA,EAAK,GAAG,CAAA,CAAE,CAAA;AAAA,MACjE;AAAA,IACF;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import type { PluginOption } from \"vite\";\nimport { transformSource } from \"@shadow-js/compiler\";\nimport { transform as swcTransform } from \"@swc/core\";\n\n/**\n * Shadow Vite Plugin\n *\n * This plugin integrates Shadow with Vite to provide seamless development experience.\n * It handles the complete transformation pipeline from TSX/JSX source code to\n * Shadow-compatible JavaScript with reactive expressions.\n *\n * Plugin Pipeline:\n * 1. **Shadow Compiler**: Applies JSX transformations to inject reactive functions\n * 2. **SWC Transformation**: Converts TypeScript/JSX to JavaScript with proper imports\n * 3. **JSX Runtime Injection**: Automatically imports Shadow's JSX runtime functions\n * 4. **Source Map Generation**: Preserves debugging capabilities\n *\n * Features:\n * - **Selective Processing**: Only transforms user code (excludes node_modules)\n * - **TypeScript Support**: Full TypeScript and TSX compilation\n * - **Hot Module Replacement**: Compatible with Vite's HMR system\n * - **Error Handling**: Provides clear error messages for compilation failures\n * - **Performance**: Uses fast SWC compiler for optimal build speeds\n *\n * The plugin automatically configures Vite to preserve JSX for SWC processing\n * instead of using esbuild's JSX transform, ensuring compatibility with Shadow's\n * reactive programming model.\n *\n * @returns Vite PluginOption instance for Shadow integration\n *\n * @example\n * ```typescript\n * // vite.config.ts\n * import { defineConfig } from \"vite\";\n * import shadow from \"@shadow-js/vite\";\n *\n * export default defineConfig({\n * plugins: [shadow()]\n * })\n * ```\n *\n * @example\n * ```typescript\n * // Your component file (App.tsx)\n * import { useStore, Show } from \"@shadow-js/core\";\n *\n * function App() {\n * const [count, setCount] = useStore(0)\n *\n * return (\n * <div>\n * <button onClick={() => setCount((c) => c + 1)}>\n * Increment\n * </button>\n * <Show when={count() > 0}>\n * <div>Count: {count()}</div>\n * </Show>\n * </div>\n * )\n * }\n * ```\n */\nexport default function shadow(): PluginOption {\n return {\n name: \"@shadow-js/vite\",\n enforce: \"pre\",\n\n // Prevent esbuild from also transforming JSX to avoid double transforms.\n config() {\n return {\n esbuild: {\n jsx: \"preserve\",\n },\n };\n },\n\n async transform(code, id) {\n // Only TSX/JSX user files\n if (!/\\.(tsx|jsx)$/.test(id)) return null;\n if (id.includes(\"node_modules\")) return null;\n\n // 1) Apply Shadow compiler transforms on source text\n let transformedCode: string;\n try {\n transformedCode = transformSource(code);\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new Error(`ShadowJS (vite): compiler failed for ${id}: ${msg}`);\n }\n\n // 2) Use SWC to handle TS/JSX -> JS and inject jsx runtime imports\n try {\n const result = await swcTransform(transformedCode, {\n filename: id,\n jsc: {\n parser: { syntax: \"typescript\", tsx: true },\n transform: {\n react: {\n runtime: \"automatic\",\n importSource: \"@shadow-js/core\",\n },\n },\n target: \"es2022\",\n },\n module: { type: \"es6\" },\n sourceMaps: true,\n });\n\n return {\n code: result.code,\n map: result.map ?? null,\n };\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new Error(`ShadowJS (vite): SWC failed for ${id}: ${msg}`);\n }\n },\n } satisfies PluginOption;\n}\n"]} |
+3
-3
| { | ||
| "name": "@shadow-js/vite", | ||
| "version": "0.1.0", | ||
| "version": "0.2.0", | ||
| "description": "Vite plugin for ShadowJS (JSX + transforms via SWC)", | ||
@@ -49,7 +49,7 @@ "author": "Jehaad AL-Johani", | ||
| "dependencies": { | ||
| "@shadow-js/compiler": "^0.1.0" | ||
| "@shadow-js/compiler": "^0.2.0" | ||
| }, | ||
| "peerDependencies": { | ||
| "@swc/core": "^1.3.96", | ||
| "shadow-js": "^0.1.0", | ||
| "@shadow-js/core": "^0.1.0", | ||
| "vite": "^7.1.3" | ||
@@ -56,0 +56,0 @@ }, |
+5
-5
@@ -29,3 +29,3 @@ # ShadowJS Vite Plugin | ||
| ```bash | ||
| npm install shadow-js @shadow-js/vite | ||
| npm install @shadow-js/core @shadow-js/vite | ||
| ``` | ||
@@ -51,3 +51,3 @@ | ||
| ```jsx | ||
| import { useStore, Show } from "shadow-js"; | ||
| import { useStore, Show } from "@shadow-js/core"; | ||
@@ -74,3 +74,3 @@ function App() { | ||
| ```typescript | ||
| import { render } from "shadow-js"; | ||
| import { render } from "@shadow-js/core"; | ||
| import App from "./App"; | ||
@@ -296,4 +296,4 @@ | ||
| - **Examples**: [Integration Examples](../../documentation/examples.md) | ||
| - **Issues**: [GitHub Issues](https://github.com/shadow-js/shadow/issues) | ||
| - **Discussions**: [GitHub Discussions](https://github.com/shadow-js/shadow/discussions) | ||
| - **Issues**: [GitHub Issues](https://github.com/shadowjs-dev/shadow/issues) | ||
| - **Discussions**: [GitHub Discussions](https://github.com/shadowjs-dev/shadow/discussions) | ||
@@ -300,0 +300,0 @@ --- |
27274
0.29%+ Added
+ Added
- Removed
Updated