@pithyjs/vite-plugin 0.2.0-beta.21 → 0.2.0-beta.22
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.
|
@@ -39,8 +39,14 @@ interface PithyBuildOptions {
|
|
|
39
39
|
*/
|
|
40
40
|
routesDir?: string;
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
42
|
+
* Emit source maps (`build.sourcemap`). Leave unset to keep the app's own
|
|
43
|
+
* `build.sourcemap`, or Vite's default (off).
|
|
44
|
+
*
|
|
45
|
+
* Off by default because a map embeds the original source (`sourcesContent`)
|
|
46
|
+
* and a production build publishes it next to the bundle. Pass `true` only
|
|
47
|
+
* when shipping that source is intended.
|
|
48
|
+
*
|
|
49
|
+
* @default undefined (the app's `build.sourcemap`, else off)
|
|
44
50
|
*/
|
|
45
51
|
sourcemap?: boolean;
|
|
46
52
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/buildPlugin/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,MAAM,CAAC;AAE/C;;GAEG;AACH,UAAU,iBAAiB;IACzB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/buildPlugin/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,OAAO,KAAK,EAAE,MAAM,EAAc,MAAM,MAAM,CAAC;AAE/C;;GAEG;AACH,UAAU,iBAAiB;IACzB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;;;;OASG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AA8ED,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,MAAM,CA6HlE"}
|
|
@@ -18,7 +18,6 @@ const DEFAULT_OPTIONS = {
|
|
|
18
18
|
lazyChunkPrefix: 'lazy-',
|
|
19
19
|
routeChunkPrefix: 'route-',
|
|
20
20
|
routesDir: 'routes',
|
|
21
|
-
sourcemap: true,
|
|
22
21
|
target: 'esnext',
|
|
23
22
|
};
|
|
24
23
|
/**
|
|
@@ -170,7 +169,12 @@ export function pithyBuild(options = {}) {
|
|
|
170
169
|
: undefined,
|
|
171
170
|
},
|
|
172
171
|
},
|
|
173
|
-
|
|
172
|
+
// Only when asked: a value here would override the app's own
|
|
173
|
+
// `build.sourcemap`, and a default of `true` published every app's
|
|
174
|
+
// original source.
|
|
175
|
+
...(config.sourcemap !== undefined
|
|
176
|
+
? { sourcemap: config.sourcemap }
|
|
177
|
+
: {}),
|
|
174
178
|
target: config.target,
|
|
175
179
|
},
|
|
176
180
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/buildPlugin/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AA6CF,MAAM,eAAe,GAAgC;IACnD,YAAY,EAAE,IAAI;IAClB,eAAe,EAAE,OAAO;IACxB,gBAAgB,EAAE,QAAQ;IAC1B,SAAS,EAAE,QAAQ;IACnB,SAAS,EAAE,IAAI;IACf,MAAM,EAAE,QAAQ;CACjB,CAAC;AAE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plugin\",\n \"title\": \"PithyJS Build Optimization Plugin\",\n \"category\": \"plugin\",\n \"description\": \"Build optimization plugin providing chunk naming strategies, vendor splitting, and route-based code splitting.\",\n \"since\": \"0.0.1\",\n \"stability\": \"stable\",\n \"testing\": {\n \"unit\": { \"required\": false, \"covered\": false },\n \"integration\": { \"required\": true, \"covered\": false },\n \"e2e\": { \"required\": false, \"covered\": false }\n }\n}\n*/\n\nimport type { Plugin, UserConfig } from 'vite';\n\n/**\n * Build plugin options\n */\ninterface PithyBuildOptions {\n /**\n * Enable vendor chunk splitting for framework packages\n * @default true\n */\n vendorChunks?: boolean;\n\n /**\n * Prefix for lazy-loaded component chunks\n * @default \"lazy-\"\n */\n lazyChunkPrefix?: string;\n\n /**\n * Prefix for route chunks\n * @default \"route-\"\n */\n routeChunkPrefix?: string;\n\n /**\n * Routes directory name (used for route chunk detection)\n * @default \"routes\"\n */\n routesDir?: string;\n\n /**\n * Enable source maps\n * @default true in development, false in production\n */\n sourcemap?: boolean;\n\n /**\n * Build target\n * @default \"esnext\"\n */\n target?: string;\n}\n\nconst DEFAULT_OPTIONS: Required<PithyBuildOptions> = {\n vendorChunks: true,\n lazyChunkPrefix: 'lazy-',\n routeChunkPrefix: 'route-',\n routesDir: 'routes',\n sourcemap: true,\n target: 'esnext',\n};\n\n/**\n * Vite plugin for PithyJS build optimizations.\n *\n * Provides:\n * - Chunk naming strategy for lazy-loaded components\n * - Route-based chunk naming\n * - Framework vendor chunk splitting\n * - Optimized asset naming\n *\n * @param options - Build configuration options\n * @returns Vite plugin\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { pithyBuild } from '@pithyjs/vite-plugin';\n *\n * export default defineConfig({\n * plugins: [\n * pithyBuild(),\n * ],\n * });\n * ```\n */\n/** @codexApi {\"parent\":\"pithy.vite.build-plugin\",\"name\":\"pithyBuild\",\"stability\":\"stable\",\"signature\":\"(options?: PithyBuildOptions) => Plugin\"} */\n/**\n * Whether every path from an entry to `id` crosses at least one `import()`.\n *\n * This is the question the `vendor` catch-all has to ask. A module reached only\n * through a dynamic import is code the app deliberately deferred; naming a\n * chunk for it merges it into a chunk the entry preloads and the deferral is\n * undone. Shiki is the case that exposed this — its WASM engine and ~300\n * grammars — but `parse5` is the same shape, and so is every future lazy\n * dependency. Hence a general rule rather than a list of names.\n *\n * STATIC IMPORTERS ALONE ARE NOT ENOUGH, which is the subtle half: a lazy\n * package's own closure has static importers — `hast-util-to-html` is\n * statically imported by `@shikijs/core`, which is itself only dynamically\n * imported. Asking \"does it have a static importer?\" keeps the closure in\n * `vendor` and leaves the bug in place. The walk has to continue upward until\n * it reaches an entry or a dynamic boundary.\n *\n * A module with no importers at all is an entry, so not deferred. A module\n * shared with eagerly-reachable code returns false and stays in `vendor`,\n * which is what stops it being duplicated into every chunk that wants it.\n */\nfunction isDeferredOnly(\n id: string,\n getModuleInfo: (id: string) => {\n importers: readonly string[];\n dynamicImporters: readonly string[];\n } | null,\n seen: Set<string> = new Set()\n): boolean {\n if (seen.has(id)) return true;\n seen.add(id);\n\n const info = getModuleInfo(id);\n if (!info) return false;\n\n // No static importer, but something `import()`s it: a deferred root.\n if (info.importers.length === 0) return info.dynamicImporters.length > 0;\n\n return info.importers.every(importer =>\n isDeferredOnly(importer, getModuleInfo, seen)\n );\n}\n\nexport function pithyBuild(options: PithyBuildOptions = {}): Plugin {\n const config: Required<PithyBuildOptions> = {\n ...DEFAULT_OPTIONS,\n ...options,\n };\n\n return {\n name: 'pithy:build',\n // Apply only during build\n apply: 'build',\n\n config(): UserConfig {\n return {\n build: {\n rollupOptions: {\n output: {\n // Chunk naming strategy\n chunkFileNames: chunkInfo => {\n const routesPattern = `/${config.routesDir}/`;\n\n // Route chunks get route-based names\n if (chunkInfo.facadeModuleId?.includes(routesPattern)) {\n const routePath =\n chunkInfo.facadeModuleId\n .split(routesPattern)[1]\n ?.replace(/\\+page\\.(ts|js|pithy)$/, '')\n .replace(/\\//g, '-')\n .replace(/-$/, '')\n // Sanitize dynamic route segments: [id] -> _id_, [...slug] -> _slug_\n .replace(/\\[\\.\\.\\.([^\\]]+)\\]/g, '_$1_')\n .replace(/\\[([^\\]]+)\\]/g, '_$1_') || 'index';\n return `assets/${config.routeChunkPrefix}${routePath}-[hash].js`;\n }\n\n // Vendor chunks keep their names\n if (chunkInfo.name?.startsWith('vendor')) {\n return `assets/[name]-[hash].js`;\n }\n\n // Dynamic entry chunks (from dynamic imports) are lazy-loaded components\n // Detect by: isDynamicEntry=true AND not a route AND not a vendor\n if (chunkInfo.isDynamicEntry && chunkInfo.facadeModuleId) {\n const moduleId = chunkInfo.facadeModuleId;\n const isVendor =\n moduleId.includes('node_modules') ||\n moduleId.includes('@pithyjs/') ||\n moduleId.includes('packages/core/') ||\n moduleId.includes('packages/signals/') ||\n moduleId.includes('packages/router/') ||\n moduleId.includes('packages/design-system/');\n\n if (!isVendor) {\n // This is a lazy-loaded component chunk\n return `assets/${config.lazyChunkPrefix}[name]-[hash].js`;\n }\n }\n\n // Default chunk naming\n return 'assets/[name]-[hash].js';\n },\n\n // Entry chunks\n entryFileNames: 'assets/[name]-[hash].js',\n\n // Assets like CSS\n assetFileNames: 'assets/[name]-[hash].[ext]',\n\n // Manual chunk splitting for better caching\n manualChunks: config.vendorChunks\n ? (id, { getModuleInfo }) => {\n // Core framework chunks - cached long-term\n // These patterns work both for local development (packages/)\n // and npm installs (node_modules/@pithyjs/)\n if (\n id.includes('@pithyjs/core') ||\n id.includes('packages/core/')\n ) {\n return 'vendor-pithy-core';\n }\n if (\n id.includes('@pithyjs/signals') ||\n id.includes('packages/signals/')\n ) {\n return 'vendor-pithy-signals';\n }\n if (\n id.includes('@pithyjs/router') ||\n id.includes('packages/router/')\n ) {\n return 'vendor-pithy-router';\n }\n if (\n id.includes('@pithyjs/design-system') ||\n id.includes('packages/design-system/')\n ) {\n return 'vendor-pithy-design';\n }\n\n // Node modules vendor chunk — EXCEPT anything the app only\n // reaches through `import()`. `vendor` is imported by the\n // entry and preloaded by the HTML, so naming a chunk for a\n // deferred module undoes the deferral.\n if (id.includes('node_modules')) {\n return isDeferredOnly(id, getModuleInfo)\n ? undefined\n : 'vendor';\n }\n\n return undefined;\n }\n : undefined,\n },\n },\n sourcemap: config.sourcemap,\n target: config.target,\n },\n };\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/buildPlugin/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAmDF,MAAM,eAAe,GAAmD;IACtE,YAAY,EAAE,IAAI;IAClB,eAAe,EAAE,OAAO;IACxB,gBAAgB,EAAE,QAAQ;IAC1B,SAAS,EAAE,QAAQ;IACnB,MAAM,EAAE,QAAQ;CACjB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,oJAAoJ;AACpJ;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAS,cAAc,CACrB,EAAU,EACV,aAGQ,EACR,OAAoB,IAAI,GAAG,EAAE;IAE7B,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAAE,OAAO,IAAI,CAAC;IAC9B,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAEb,MAAM,IAAI,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;IAC/B,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAC;IAExB,qEAAqE;IACrE,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC;IAEzE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CACrC,cAAc,CAAC,QAAQ,EAAE,aAAa,EAAE,IAAI,CAAC,CAC9C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,UAA6B,EAAE;IACxD,MAAM,MAAM,GAC6B;QACvC,GAAG,eAAe;QAClB,GAAG,OAAO;KACX,CAA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AC1D,2DAA2D;oCAC3D,uCAAuC;oCACvC,IAAI,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;wCAChC,OAAO,cAAc,CAAC,EAAE,EAAE,aAAa,CAAC;4CACtC,CAAC,CAAC,SAAS;4CACX,CAAC,CAAC,QAAQ,CAAC;oCACf,CAAC;oCAED,OAAO,SAAS,CAAC;gCACnB,CAAC;gCACH,CAAC,CAAC,SAAS;yBACd;qBACF;oBACD,6DAA6D;oBAC7D,mEAAmE;oBACnE,mBAAmB;oBACnB,GAAG,CAAC,MAAM,CAAC,SAAS,KAAK,SAAS;wBAChC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE;wBACjC,CAAC,CAAC,EAAE,CAAC;oBACP,MAAM,EAAE,MAAM,CAAC,MAAM;iBACtB;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/** @codex\n{\n \"id\": \"pithy.vite.build-plugin\",\n \"title\": \"PithyJS Build Optimization Plugin\",\n \"category\": \"plugin\",\n \"description\": \"Build optimization plugin providing chunk naming strategies, vendor splitting, and route-based code splitting.\",\n \"since\": \"0.0.1\",\n \"stability\": \"stable\",\n \"testing\": {\n \"unit\": { \"required\": false, \"covered\": false },\n \"integration\": { \"required\": true, \"covered\": false },\n \"e2e\": { \"required\": false, \"covered\": false }\n }\n}\n*/\n\nimport type { Plugin, UserConfig } from 'vite';\n\n/**\n * Build plugin options\n */\ninterface PithyBuildOptions {\n /**\n * Enable vendor chunk splitting for framework packages\n * @default true\n */\n vendorChunks?: boolean;\n\n /**\n * Prefix for lazy-loaded component chunks\n * @default \"lazy-\"\n */\n lazyChunkPrefix?: string;\n\n /**\n * Prefix for route chunks\n * @default \"route-\"\n */\n routeChunkPrefix?: string;\n\n /**\n * Routes directory name (used for route chunk detection)\n * @default \"routes\"\n */\n routesDir?: string;\n\n /**\n * Emit source maps (`build.sourcemap`). Leave unset to keep the app's own\n * `build.sourcemap`, or Vite's default (off).\n *\n * Off by default because a map embeds the original source (`sourcesContent`)\n * and a production build publishes it next to the bundle. Pass `true` only\n * when shipping that source is intended.\n *\n * @default undefined (the app's `build.sourcemap`, else off)\n */\n sourcemap?: boolean;\n\n /**\n * Build target\n * @default \"esnext\"\n */\n target?: string;\n}\n\nconst DEFAULT_OPTIONS: Required<Omit<PithyBuildOptions, 'sourcemap'>> = {\n vendorChunks: true,\n lazyChunkPrefix: 'lazy-',\n routeChunkPrefix: 'route-',\n routesDir: 'routes',\n target: 'esnext',\n};\n\n/**\n * Vite plugin for PithyJS build optimizations.\n *\n * Provides:\n * - Chunk naming strategy for lazy-loaded components\n * - Route-based chunk naming\n * - Framework vendor chunk splitting\n * - Optimized asset naming\n *\n * @param options - Build configuration options\n * @returns Vite plugin\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { pithyBuild } from '@pithyjs/vite-plugin';\n *\n * export default defineConfig({\n * plugins: [\n * pithyBuild(),\n * ],\n * });\n * ```\n */\n/** @codexApi {\"parent\":\"pithy.vite.build-plugin\",\"name\":\"pithyBuild\",\"stability\":\"stable\",\"signature\":\"(options?: PithyBuildOptions) => Plugin\"} */\n/**\n * Whether every path from an entry to `id` crosses at least one `import()`.\n *\n * This is the question the `vendor` catch-all has to ask. A module reached only\n * through a dynamic import is code the app deliberately deferred; naming a\n * chunk for it merges it into a chunk the entry preloads and the deferral is\n * undone. Shiki is the case that exposed this — its WASM engine and ~300\n * grammars — but `parse5` is the same shape, and so is every future lazy\n * dependency. Hence a general rule rather than a list of names.\n *\n * STATIC IMPORTERS ALONE ARE NOT ENOUGH, which is the subtle half: a lazy\n * package's own closure has static importers — `hast-util-to-html` is\n * statically imported by `@shikijs/core`, which is itself only dynamically\n * imported. Asking \"does it have a static importer?\" keeps the closure in\n * `vendor` and leaves the bug in place. The walk has to continue upward until\n * it reaches an entry or a dynamic boundary.\n *\n * A module with no importers at all is an entry, so not deferred. A module\n * shared with eagerly-reachable code returns false and stays in `vendor`,\n * which is what stops it being duplicated into every chunk that wants it.\n */\nfunction isDeferredOnly(\n id: string,\n getModuleInfo: (id: string) => {\n importers: readonly string[];\n dynamicImporters: readonly string[];\n } | null,\n seen: Set<string> = new Set()\n): boolean {\n if (seen.has(id)) return true;\n seen.add(id);\n\n const info = getModuleInfo(id);\n if (!info) return false;\n\n // No static importer, but something `import()`s it: a deferred root.\n if (info.importers.length === 0) return info.dynamicImporters.length > 0;\n\n return info.importers.every(importer =>\n isDeferredOnly(importer, getModuleInfo, seen)\n );\n}\n\nexport function pithyBuild(options: PithyBuildOptions = {}): Plugin {\n const config: Required<Omit<PithyBuildOptions, 'sourcemap'>> &\n Pick<PithyBuildOptions, 'sourcemap'> = {\n ...DEFAULT_OPTIONS,\n ...options,\n };\n\n return {\n name: 'pithy:build',\n // Apply only during build\n apply: 'build',\n\n config(): UserConfig {\n return {\n build: {\n rollupOptions: {\n output: {\n // Chunk naming strategy\n chunkFileNames: chunkInfo => {\n const routesPattern = `/${config.routesDir}/`;\n\n // Route chunks get route-based names\n if (chunkInfo.facadeModuleId?.includes(routesPattern)) {\n const routePath =\n chunkInfo.facadeModuleId\n .split(routesPattern)[1]\n ?.replace(/\\+page\\.(ts|js|pithy)$/, '')\n .replace(/\\//g, '-')\n .replace(/-$/, '')\n // Sanitize dynamic route segments: [id] -> _id_, [...slug] -> _slug_\n .replace(/\\[\\.\\.\\.([^\\]]+)\\]/g, '_$1_')\n .replace(/\\[([^\\]]+)\\]/g, '_$1_') || 'index';\n return `assets/${config.routeChunkPrefix}${routePath}-[hash].js`;\n }\n\n // Vendor chunks keep their names\n if (chunkInfo.name?.startsWith('vendor')) {\n return `assets/[name]-[hash].js`;\n }\n\n // Dynamic entry chunks (from dynamic imports) are lazy-loaded components\n // Detect by: isDynamicEntry=true AND not a route AND not a vendor\n if (chunkInfo.isDynamicEntry && chunkInfo.facadeModuleId) {\n const moduleId = chunkInfo.facadeModuleId;\n const isVendor =\n moduleId.includes('node_modules') ||\n moduleId.includes('@pithyjs/') ||\n moduleId.includes('packages/core/') ||\n moduleId.includes('packages/signals/') ||\n moduleId.includes('packages/router/') ||\n moduleId.includes('packages/design-system/');\n\n if (!isVendor) {\n // This is a lazy-loaded component chunk\n return `assets/${config.lazyChunkPrefix}[name]-[hash].js`;\n }\n }\n\n // Default chunk naming\n return 'assets/[name]-[hash].js';\n },\n\n // Entry chunks\n entryFileNames: 'assets/[name]-[hash].js',\n\n // Assets like CSS\n assetFileNames: 'assets/[name]-[hash].[ext]',\n\n // Manual chunk splitting for better caching\n manualChunks: config.vendorChunks\n ? (id, { getModuleInfo }) => {\n // Core framework chunks - cached long-term\n // These patterns work both for local development (packages/)\n // and npm installs (node_modules/@pithyjs/)\n if (\n id.includes('@pithyjs/core') ||\n id.includes('packages/core/')\n ) {\n return 'vendor-pithy-core';\n }\n if (\n id.includes('@pithyjs/signals') ||\n id.includes('packages/signals/')\n ) {\n return 'vendor-pithy-signals';\n }\n if (\n id.includes('@pithyjs/router') ||\n id.includes('packages/router/')\n ) {\n return 'vendor-pithy-router';\n }\n if (\n id.includes('@pithyjs/design-system') ||\n id.includes('packages/design-system/')\n ) {\n return 'vendor-pithy-design';\n }\n\n // Node modules vendor chunk — EXCEPT anything the app only\n // reaches through `import()`. `vendor` is imported by the\n // entry and preloaded by the HTML, so naming a chunk for a\n // deferred module undoes the deferral.\n if (id.includes('node_modules')) {\n return isDeferredOnly(id, getModuleInfo)\n ? undefined\n : 'vendor';\n }\n\n return undefined;\n }\n : undefined,\n },\n },\n // Only when asked: a value here would override the app's own\n // `build.sourcemap`, and a default of `true` published every app's\n // original source.\n ...(config.sourcemap !== undefined\n ? { sourcemap: config.sourcemap }\n : {}),\n target: config.target,\n },\n };\n },\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pithyjs/vite-plugin",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.22",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/PithyJS/pithyjs.git",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"@babel/types": "^7.27.3",
|
|
35
35
|
"fast-glob": "^3.3.0",
|
|
36
36
|
"parse5": "^7.3.0",
|
|
37
|
-
"@pithyjs/compiler": "0.1.0-beta.8",
|
|
38
|
-
"@pithyjs/design-system": "0.1.0-beta.11",
|
|
39
37
|
"@pithyjs/router": "0.2.0-beta.20",
|
|
38
|
+
"@pithyjs/design-system": "0.1.0-beta.11",
|
|
39
|
+
"@pithyjs/compiler": "0.1.0-beta.8",
|
|
40
40
|
"@pithyjs/shared": "0.1.0-beta.4"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|