honox 0.0.2 → 0.1.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.
package/README.md CHANGED
@@ -12,6 +12,22 @@
12
12
  - **Islands hydration** - If you want interactions, create an island. JavaScript is hydrated only for it.
13
13
  - **Middleware** - It works as Hono, so you can use a lot of Hono's middleware.
14
14
 
15
+ ## Installing
16
+
17
+ You can install the `honox` package from the npm.
18
+
19
+ ```txt
20
+ npm install hono honox
21
+ ```
22
+
23
+ ## Starter template
24
+
25
+ If you are starting a new HonoX project, use the `hono-create` command. Run the following and choose `x-basic`.
26
+
27
+ ```txt
28
+ npm create hono@latest
29
+ ```
30
+
15
31
  ## Get Started - Basic
16
32
 
17
33
  Let's create a basic HonoX application using hono/jsx as a renderer. This application has no client JavaScript and renders JSX on the server side.
@@ -271,6 +287,27 @@ export default jsxRenderer(({ children }) => {
271
287
  })
272
288
  ```
273
289
 
290
+ If you have a manifest file in `dist/.vite/manifest.json`, you can easily write it using `<Script />`.
291
+
292
+ ```tsx
293
+ // app/routes/_renderer.tsx
294
+ import { jsxRenderer } from 'hono/jsx-renderer'
295
+ import { Script } from 'honox/server'
296
+
297
+ export default jsxRenderer(({ children }) => {
298
+ return (
299
+ <html lang='en'>
300
+ <head>
301
+ <meta charset='UTF-8' />
302
+ <meta name='viewport' content='width=device-width, initial-scale=1.0' />
303
+ <Script src='/app/client.ts' />
304
+ </head>
305
+ <body>{children}</body>
306
+ </html>
307
+ )
308
+ })
309
+ ```
310
+
274
311
  ### Client Entry File
275
312
 
276
313
  A client side entry file should be in `app/client.ts`. Simply, write `createClient()`.
@@ -498,7 +535,7 @@ import mdx from '@mdx-js/rollup'
498
535
  import honox from 'honox/vite'
499
536
  import remarkFrontmatter from 'remark-frontmatter'
500
537
  import remarkMdxFrontmatter from 'remark-mdx-frontmatter'
501
- import { defineConfig } from '../../node_modules/vite'
538
+ import { defineConfig } from 'vite'
502
539
 
503
540
  const entry = './app/server.ts'
504
541
 
@@ -554,6 +591,7 @@ Since a HonoX instance is essentially a Hono instance, it can be deployed on any
554
591
  Setup the `vite.config.ts`:
555
592
 
556
593
  ```ts
594
+ // vite.config.ts
557
595
  import { defineConfig } from 'vite'
558
596
  import honox from 'honox/vite'
559
597
  import pages from '@hono/vite-cloudflare-pages'
@@ -567,25 +605,15 @@ If you want to include client side scripts and assets:
567
605
 
568
606
  ```ts
569
607
  // vite.config.ts
570
- import { defineConfig } from 'vite'
571
- import honox from 'honox/vite'
572
608
  import pages from '@hono/vite-cloudflare-pages'
609
+ import honox from 'honox/vite'
610
+ import client from 'honox/vite/client'
611
+ import { defineConfig } from 'vite'
573
612
 
574
613
  export default defineConfig(({ mode }) => {
575
614
  if (mode === 'client') {
576
615
  return {
577
- build: {
578
- rollupOptions: {
579
- input: ['./app/client.ts'],
580
- output: {
581
- entryFileNames: 'static/client.js',
582
- chunkFileNames: 'static/assets/[name]-[hash].js',
583
- assetFileNames: 'static/assets/[name].[ext]',
584
- },
585
- },
586
- emptyOutDir: false,
587
- copyPublicDir: false,
588
- },
616
+ plugins: [client()],
589
617
  }
590
618
  } else {
591
619
  return {
@@ -598,7 +626,7 @@ export default defineConfig(({ mode }) => {
598
626
  Build command (including a client):
599
627
 
600
628
  ```txt
601
- vite build && vite build --mode client
629
+ vite build --mode client && vite build
602
630
  ```
603
631
 
604
632
  Deploy with the following commands after build. Ensure you have [Wrangler](https://developers.cloudflare.com/workers/wrangler/) installed:
@@ -633,7 +661,6 @@ wrangler pages deploy ./dist
633
661
 
634
662
  ## Examples
635
663
 
636
- - [/example](./examples/)
637
664
  - https://github.com/yusukebe/honox-examples
638
665
 
639
666
  ## Related projects
@@ -1,6 +1,6 @@
1
1
  import { Fragment, jsx } from "hono/jsx/jsx-runtime";
2
2
  import { useRequestContext } from "hono/jsx-renderer";
3
- import { IMPORTING_ISLANDS_ID } from "../constants.js";
3
+ import { IMPORTING_ISLANDS_ID } from "../../constants.js";
4
4
  const HasIslands = ({ children }) => {
5
5
  const c = useRequestContext();
6
6
  return /* @__PURE__ */ jsx(Fragment, { children: c.get(IMPORTING_ISLANDS_ID) ? children : /* @__PURE__ */ jsx(Fragment, {}) });
@@ -0,0 +1,4 @@
1
+ export { HasIslands } from './has-islands.js';
2
+ export { Script } from './script.js';
3
+ import 'hono/jsx';
4
+ import 'vite';
@@ -0,0 +1,6 @@
1
+ import { HasIslands } from "./has-islands.js";
2
+ import { Script } from "./script.js";
3
+ export {
4
+ HasIslands,
5
+ Script
6
+ };
@@ -0,0 +1,11 @@
1
+ import { FC } from 'hono/jsx';
2
+ import { Manifest } from 'vite';
3
+
4
+ type Options = {
5
+ src: string;
6
+ prod?: boolean;
7
+ manifest?: Manifest;
8
+ };
9
+ declare const Script: FC<Options>;
10
+
11
+ export { Script };
@@ -0,0 +1,31 @@
1
+ import { Fragment, jsx } from "hono/jsx/jsx-runtime";
2
+ import { HasIslands } from "./has-islands.js";
3
+ const Script = async (options) => {
4
+ const src = options.src;
5
+ if (options.prod ?? import.meta.env.PROD) {
6
+ let manifest = options.manifest;
7
+ if (!manifest) {
8
+ const MANIFEST = import.meta.glob("/dist/.vite/manifest.json", {
9
+ eager: true
10
+ });
11
+ for (const [, manifestFile] of Object.entries(MANIFEST)) {
12
+ if (manifestFile["default"]) {
13
+ manifest = manifestFile["default"];
14
+ break;
15
+ }
16
+ }
17
+ }
18
+ if (manifest) {
19
+ const scriptInManifest = manifest[src.replace(/^\//, "")];
20
+ if (scriptInManifest) {
21
+ return /* @__PURE__ */ jsx(HasIslands, { children: /* @__PURE__ */ jsx("script", { type: "module", src: `/${scriptInManifest.file}` }) });
22
+ }
23
+ }
24
+ return /* @__PURE__ */ jsx(Fragment, {});
25
+ } else {
26
+ return /* @__PURE__ */ jsx("script", { type: "module", src });
27
+ }
28
+ };
29
+ export {
30
+ Script
31
+ };
@@ -0,0 +1,19 @@
1
+ import * as hono_types from 'hono/types';
2
+ import * as hono from 'hono';
3
+ import { Env, Hono } from 'hono';
4
+
5
+ declare const createRoute: {
6
+ <I extends hono.Input = {}>(handler1: hono_types.H<Env, any, I>): [hono_types.H<Env, any, I>];
7
+ <I_1 extends hono.Input = {}, I2 extends hono.Input = I_1, R extends hono_types.HandlerResponse<any> = any>(handler1: hono_types.H<Env, any, I_1, R>, handler2: hono_types.H<Env, any, I2, R>): [hono_types.H<Env, any, I_1, R>, hono_types.H<Env, any, I2, R>];
8
+ <I_2 extends hono.Input = {}, I2_1 extends hono.Input = I_2, I3 extends hono.Input = I_2 & I2_1, R_1 extends hono_types.HandlerResponse<any> = any>(handler1: hono_types.H<Env, any, I_2, R_1>, handler2: hono_types.H<Env, any, I2_1, R_1>, handler3: hono_types.H<Env, any, I3, R_1>): [hono_types.H<Env, any, I_2, R_1>, hono_types.H<Env, any, I2_1, R_1>, hono_types.H<Env, any, I3, R_1>];
9
+ <I_3 extends hono.Input = {}, I2_2 extends hono.Input = I_3, I3_1 extends hono.Input = I_3 & I2_2, I4 extends hono.Input = I_3 & I2_2 & I3_1, R_2 extends hono_types.HandlerResponse<any> = any>(handler1: hono_types.H<Env, any, I_3, R_2>, handler2: hono_types.H<Env, any, I2_2, R_2>, handler3: hono_types.H<Env, any, I3_1, R_2>, handler4: hono_types.H<Env, any, I4, R_2>): [hono_types.H<Env, any, I_3, R_2>, hono_types.H<Env, any, I2_2, R_2>, hono_types.H<Env, any, I3_1, R_2>, hono_types.H<Env, any, I4, R_2>];
10
+ <I_4 extends hono.Input = {}, I2_3 extends hono.Input = I_4, I3_2 extends hono.Input = I_4 & I2_3, I4_1 extends hono.Input = I_4 & I2_3 & I3_2, I5 extends hono.Input = I_4 & I2_3 & I3_2 & I4_1, R_3 extends hono_types.HandlerResponse<any> = any>(handler1: hono_types.H<Env, any, I_4, R_3>, handler2: hono_types.H<Env, any, I2_3, R_3>, handler3: hono_types.H<Env, any, I3_2, R_3>, handler4: hono_types.H<Env, any, I4_1, R_3>, handler5: hono_types.H<Env, any, I5, R_3>): [hono_types.H<Env, any, I_4, R_3>, hono_types.H<Env, any, I2_3, R_3>, hono_types.H<Env, any, I3_2, R_3>, hono_types.H<Env, any, I4_1, R_3>, hono_types.H<Env, any, I5, R_3>];
11
+ <I_5 extends hono.Input = {}, I2_4 extends hono.Input = I_5, I3_3 extends hono.Input = I_5 & I2_4, I4_2 extends hono.Input = I_5 & I2_4 & I3_3, I5_1 extends hono.Input = I_5 & I2_4 & I3_3 & I4_2, I6 extends hono.Input = I_5 & I2_4 & I3_3 & I4_2 & I5_1, R_4 extends hono_types.HandlerResponse<any> = any>(handler1: hono_types.H<Env, any, I_5, R_4>, handler2: hono_types.H<Env, any, I2_4, R_4>, handler3: hono_types.H<Env, any, I3_3, R_4>, handler4: hono_types.H<Env, any, I4_2, R_4>, handler5: hono_types.H<Env, any, I5_1, R_4>, handler6: hono_types.H<Env, any, I6, R_4>): [hono_types.H<Env, any, I_5, R_4>, hono_types.H<Env, any, I2_4, R_4>, hono_types.H<Env, any, I3_3, R_4>, hono_types.H<Env, any, I4_2, R_4>, hono_types.H<Env, any, I5_1, R_4>, hono_types.H<Env, any, I6, R_4>];
12
+ <I_6 extends hono.Input = {}, I2_5 extends hono.Input = I_6, I3_4 extends hono.Input = I_6 & I2_5, I4_3 extends hono.Input = I_6 & I2_5 & I3_4, I5_2 extends hono.Input = I_6 & I2_5 & I3_4 & I4_3, I6_1 extends hono.Input = I_6 & I2_5 & I3_4 & I4_3 & I5_2, I7 extends hono.Input = I_6 & I2_5 & I3_4 & I4_3 & I5_2 & I6_1, R_5 extends hono_types.HandlerResponse<any> = any>(handler1: hono_types.H<Env, any, I_6, R_5>, handler2: hono_types.H<Env, any, I2_5, R_5>, handler3: hono_types.H<Env, any, I3_4, R_5>, handler4: hono_types.H<Env, any, I4_3, R_5>, handler5: hono_types.H<Env, any, I5_2, R_5>, handler6: hono_types.H<Env, any, I6_1, R_5>, handler7: hono_types.H<Env, any, I7, R_5>): [hono_types.H<Env, any, I_6, R_5>, hono_types.H<Env, any, I2_5, R_5>, hono_types.H<Env, any, I3_4, R_5>, hono_types.H<Env, any, I4_3, R_5>, hono_types.H<Env, any, I5_2, R_5>, hono_types.H<Env, any, I6_1, R_5>, hono_types.H<Env, any, I7, R_5>];
13
+ <I_7 extends hono.Input = {}, I2_6 extends hono.Input = I_7, I3_5 extends hono.Input = I_7 & I2_6, I4_4 extends hono.Input = I_7 & I2_6 & I3_5, I5_3 extends hono.Input = I_7 & I2_6 & I3_5 & I4_4, I6_2 extends hono.Input = I_7 & I2_6 & I3_5 & I4_4 & I5_3, I7_1 extends hono.Input = I_7 & I2_6 & I3_5 & I4_4 & I5_3 & I6_2, I8 extends hono.Input = I_7 & I2_6 & I3_5 & I4_4 & I5_3 & I6_2 & I7_1, R_6 extends hono_types.HandlerResponse<any> = any>(handler1: hono_types.H<Env, any, I_7, R_6>, handler2: hono_types.H<Env, any, I2_6, R_6>, handler3: hono_types.H<Env, any, I3_5, R_6>, handler4: hono_types.H<Env, any, I4_4, R_6>, handler5: hono_types.H<Env, any, I5_3, R_6>, handler6: hono_types.H<Env, any, I6_2, R_6>, handler7: hono_types.H<Env, any, I7_1, R_6>, handler8: hono_types.H<Env, any, I8, R_6>): [hono_types.H<Env, any, I_7, R_6>, hono_types.H<Env, any, I2_6, R_6>, hono_types.H<Env, any, I3_5, R_6>, hono_types.H<Env, any, I4_4, R_6>, hono_types.H<Env, any, I5_3, R_6>, hono_types.H<Env, any, I6_2, R_6>, hono_types.H<Env, any, I7_1, R_6>, hono_types.H<Env, any, I8, R_6>];
14
+ <I_8 extends hono.Input = {}, I2_7 extends hono.Input = I_8, I3_6 extends hono.Input = I_8 & I2_7, I4_5 extends hono.Input = I_8 & I2_7 & I3_6, I5_4 extends hono.Input = I_8 & I2_7 & I3_6 & I4_5, I6_3 extends hono.Input = I_8 & I2_7 & I3_6 & I4_5 & I5_4, I7_2 extends hono.Input = I_8 & I2_7 & I3_6 & I4_5 & I5_4 & I6_3, I8_1 extends hono.Input = I_8 & I2_7 & I3_6 & I4_5 & I5_4 & I6_3 & I7_2, I9 extends hono.Input = I_8 & I2_7 & I3_6 & I4_5 & I5_4 & I6_3 & I7_2 & I8_1, R_7 extends hono_types.HandlerResponse<any> = any>(handler1: hono_types.H<Env, any, I_8, R_7>, handler2: hono_types.H<Env, any, I2_7, R_7>, handler3: hono_types.H<Env, any, I3_6, R_7>, handler4: hono_types.H<Env, any, I4_5, R_7>, handler5: hono_types.H<Env, any, I5_4, R_7>, handler6: hono_types.H<Env, any, I6_3, R_7>, handler7: hono_types.H<Env, any, I7_2, R_7>, handler8: hono_types.H<Env, any, I8_1, R_7>, handler9: hono_types.H<Env, any, I9, R_7>): [hono_types.H<Env, any, I_8, R_7>, hono_types.H<Env, any, I2_7, R_7>, hono_types.H<Env, any, I3_6, R_7>, hono_types.H<Env, any, I4_5, R_7>, hono_types.H<Env, any, I5_4, R_7>, hono_types.H<Env, any, I6_3, R_7>, hono_types.H<Env, any, I7_2, R_7>, hono_types.H<Env, any, I8_1, R_7>, hono_types.H<Env, any, I9, R_7>];
15
+ <I_9 extends hono.Input = {}, I2_8 extends hono.Input = I_9, I3_7 extends hono.Input = I_9 & I2_8, I4_6 extends hono.Input = I_9 & I2_8 & I3_7, I5_5 extends hono.Input = I_9 & I2_8 & I3_7 & I4_6, I6_4 extends hono.Input = I_9 & I2_8 & I3_7 & I4_6 & I5_5, I7_3 extends hono.Input = I_9 & I2_8 & I3_7 & I4_6 & I5_5 & I6_4, I8_2 extends hono.Input = I_9 & I2_8 & I3_7 & I4_6 & I5_5 & I6_4 & I7_3, I9_1 extends hono.Input = I_9 & I2_8 & I3_7 & I4_6 & I5_5 & I6_4 & I7_3 & I8_2, I10 extends hono.Input = I_9 & I2_8 & I3_7 & I4_6 & I5_5 & I6_4 & I7_3 & I8_2 & I9_1, R_8 extends hono_types.HandlerResponse<any> = any>(handler1: hono_types.H<Env, any, I_9, R_8>, handler2: hono_types.H<Env, any, I2_8, R_8>, handler3: hono_types.H<Env, any, I3_7, R_8>, handler4: hono_types.H<Env, any, I4_6, R_8>, handler5: hono_types.H<Env, any, I5_5, R_8>, handler6: hono_types.H<Env, any, I6_4, R_8>, handler7: hono_types.H<Env, any, I7_3, R_8>, handler8: hono_types.H<Env, any, I8_2, R_8>, handler9: hono_types.H<Env, any, I9_1, R_8>, handler10: hono_types.H<Env, any, I10, R_8>): [hono_types.H<Env, any, I_9, R_8>, hono_types.H<Env, any, I2_8, R_8>, hono_types.H<Env, any, I3_7, R_8>, hono_types.H<Env, any, I4_6, R_8>, hono_types.H<Env, any, I5_5, R_8>, hono_types.H<Env, any, I6_4, R_8>, hono_types.H<Env, any, I7_3, R_8>, hono_types.H<Env, any, I8_2, R_8>, hono_types.H<Env, any, I9_1, R_8>, hono_types.H<Env, any, I10, R_8>];
16
+ };
17
+ declare const createHono: () => Hono<Env, hono_types.BlankSchema, "/">;
18
+
19
+ export { createHono, createRoute };
@@ -0,0 +1,11 @@
1
+ import { Hono } from "hono";
2
+ import { createFactory } from "hono/factory";
3
+ const factory = createFactory();
4
+ const createRoute = factory.createHandlers;
5
+ const createHono = () => {
6
+ return new Hono();
7
+ };
8
+ export {
9
+ createHono,
10
+ createRoute
11
+ };
@@ -0,0 +1,3 @@
1
+ export { createHono, createRoute } from './factory.js';
2
+ import 'hono/types';
3
+ import 'hono';
@@ -0,0 +1,5 @@
1
+ import { createRoute, createHono } from "./factory.js";
2
+ export {
3
+ createHono,
4
+ createRoute
5
+ };
@@ -1,6 +1,8 @@
1
1
  export { ServerOptions, createApp } from './server.js';
2
- export { HasIslands } from './components.js';
2
+ export { HasIslands } from './components/has-islands.js';
3
+ export { Script } from './components/script.js';
3
4
  import 'hono/types';
4
5
  import 'hono';
5
6
  import '../constants.js';
6
7
  import 'hono/jsx';
8
+ import 'vite';
@@ -1,6 +1,5 @@
1
1
  import { createApp } from "./server.js";
2
- import { HasIslands } from "./components.js";
2
+ export * from "./components/index.js";
3
3
  export {
4
- HasIslands,
5
4
  createApp
6
5
  };
@@ -0,0 +1,10 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ type Options = {
4
+ jsxImportSource?: string;
5
+ assetsDir?: string;
6
+ };
7
+ declare const defaultOptions: Options;
8
+ declare function client(options?: Options): Plugin;
9
+
10
+ export { client as default, defaultOptions };
@@ -0,0 +1,28 @@
1
+ const defaultOptions = {
2
+ jsxImportSource: "hono/jsx/dom",
3
+ assetsDir: "static"
4
+ };
5
+ function client(options) {
6
+ return {
7
+ name: "honox-vite-client",
8
+ config: () => {
9
+ return {
10
+ build: {
11
+ rollupOptions: {
12
+ input: ["/app/client.ts"]
13
+ },
14
+ assetsDir: options?.assetsDir ?? defaultOptions.assetsDir,
15
+ manifest: true
16
+ },
17
+ esbuild: {
18
+ jsxImportSource: options?.jsxImportSource ?? defaultOptions.jsxImportSource
19
+ }
20
+ };
21
+ }
22
+ };
23
+ }
24
+ var client_default = client;
25
+ export {
26
+ client_default as default,
27
+ defaultOptions
28
+ };
@@ -3,13 +3,13 @@ export { defaultOptions as devServerDefaultOptions } from '@hono/vite-dev-server
3
3
  import { PluginOption } from 'vite';
4
4
  export { islandComponents } from './island-components.js';
5
5
 
6
- type HonoXOptions = {
6
+ type Options = {
7
7
  islands?: boolean;
8
8
  entry?: string;
9
9
  devServer?: DevServerOptions;
10
10
  external?: string[];
11
11
  };
12
- declare const defaultOptions: HonoXOptions;
13
- declare function honox(options?: HonoXOptions): PluginOption[];
12
+ declare const defaultOptions: Options;
13
+ declare function honox(options?: Options): PluginOption[];
14
14
 
15
15
  export { honox as default, defaultOptions };
@@ -27,7 +27,14 @@ function honox(options) {
27
27
  plugins.push(injectImportingIslands());
28
28
  return [
29
29
  {
30
- name: "honox-vite-config"
30
+ name: "honox-vite-config",
31
+ config: () => {
32
+ return {
33
+ ssr: {
34
+ noExternal: true
35
+ }
36
+ };
37
+ }
31
38
  },
32
39
  ...plugins
33
40
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "honox",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "main": "dist/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -52,6 +52,10 @@
52
52
  "./vite": {
53
53
  "types": "./dist/vite/index.d.ts",
54
54
  "import": "./dist/vite/index.js"
55
+ },
56
+ "./vite/client": {
57
+ "types": "./dist/vite/client.d.ts",
58
+ "import": "./dist/vite/client.js"
55
59
  }
56
60
  },
57
61
  "typesVersions": {
@@ -73,6 +77,9 @@
73
77
  ],
74
78
  "vite": [
75
79
  "./dist/vite"
80
+ ],
81
+ "vite/client": [
82
+ "./dist/vite/client"
76
83
  ]
77
84
  }
78
85
  },
@@ -1,5 +0,0 @@
1
- import { Plugin } from 'vite';
2
-
3
- declare function injectHasIslands(): Plugin;
4
-
5
- export { injectHasIslands };
@@ -1,52 +0,0 @@
1
- import _generate from "@babel/generator";
2
- import { parse } from "@babel/parser";
3
- import _traverse from "@babel/traverse";
4
- import { HAS_ISLANDS_ID } from "../constants.js";
5
- const traverse = _traverse.default ?? _traverse;
6
- const generate = _generate.default ?? _generate;
7
- function injectHasIslands() {
8
- return {
9
- name: "inject-has-islands",
10
- transform(code, id) {
11
- if (id.endsWith(".tsx") || id.endsWith(".jsx")) {
12
- let hasIslandsImport = false;
13
- const ast = parse(code, {
14
- sourceType: "module",
15
- plugins: ["jsx"]
16
- });
17
- traverse(ast, {
18
- ImportDeclaration(path) {
19
- if (path.node.source.value.includes("islands/")) {
20
- hasIslandsImport = true;
21
- }
22
- }
23
- });
24
- if (hasIslandsImport) {
25
- const hasIslandsNode = {
26
- type: "ExportNamedDeclaration",
27
- declaration: {
28
- type: "VariableDeclaration",
29
- declarations: [
30
- {
31
- type: "VariableDeclarator",
32
- id: { type: "Identifier", name: HAS_ISLANDS_ID },
33
- init: { type: "BooleanLiteral", value: true }
34
- }
35
- ],
36
- kind: "const"
37
- }
38
- };
39
- ast.program.body.push(hasIslandsNode);
40
- }
41
- const output = generate(ast, {}, code);
42
- return {
43
- code: output.code,
44
- map: output.map
45
- };
46
- }
47
- }
48
- };
49
- }
50
- export {
51
- injectHasIslands
52
- };
@@ -1,8 +0,0 @@
1
- import { Plugin } from 'vite';
2
-
3
- type RemoveElementsOptions = {
4
- attributes: string[];
5
- };
6
- declare function removeElementsPlugin(options: RemoveElementsOptions): Plugin;
7
-
8
- export { removeElementsPlugin };
@@ -1,52 +0,0 @@
1
- import _generate from "@babel/generator";
2
- import { parse } from "@babel/parser";
3
- import _traverse from "@babel/traverse";
4
- import { HAS_ISLANDS_ID } from "../constants";
5
- const traverse = _traverse.default ?? _traverse;
6
- const generate = _generate.default ?? _generate;
7
- function injectHasIslands() {
8
- return {
9
- name: "inject-has-islands",
10
- transform(code, id) {
11
- if (id.endsWith(".tsx") || id.endsWith(".jsx")) {
12
- let hasIslandsImport = false;
13
- const ast = parse(code, {
14
- sourceType: "module",
15
- plugins: ["jsx"]
16
- });
17
- traverse(ast, {
18
- ImportDeclaration(path) {
19
- if (path.node.source.value.includes("islands/")) {
20
- hasIslandsImport = true;
21
- }
22
- }
23
- });
24
- if (hasIslandsImport) {
25
- const hasIslandsNode = {
26
- type: "ExportNamedDeclaration",
27
- declaration: {
28
- type: "VariableDeclaration",
29
- declarations: [
30
- {
31
- type: "VariableDeclarator",
32
- id: { type: "Identifier", name: HAS_ISLANDS_ID },
33
- init: { type: "BooleanLiteral", value: true }
34
- }
35
- ],
36
- kind: "const"
37
- }
38
- };
39
- ast.program.body.push(hasIslandsNode);
40
- }
41
- const output = generate(ast, {}, code);
42
- return {
43
- code: output.code,
44
- map: output.map
45
- };
46
- }
47
- }
48
- };
49
- }
50
- export {
51
- injectHasIslands
52
- };