@hyperspan/plugin-preact 1.0.3 → 1.0.4
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/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JS_IMPORT_MAP, JS_ISLAND_PUBLIC_PATH } from '@hyperspan/framework/client/js';
|
|
2
2
|
import { assetHash } from '@hyperspan/framework/utils';
|
|
3
3
|
import { IS_PROD } from '@hyperspan/framework/server';
|
|
4
|
-
import {
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
5
|
import type { Hyperspan as HS } from '@hyperspan/framework';
|
|
6
6
|
import { html } from '@hyperspan/html';
|
|
7
7
|
import { h } from 'preact';
|
|
@@ -10,6 +10,8 @@ import debug from 'debug';
|
|
|
10
10
|
|
|
11
11
|
const log = debug('hyperspan:plugin-preact');
|
|
12
12
|
|
|
13
|
+
const CWD = process.cwd();
|
|
14
|
+
|
|
13
15
|
/** Dev: stable `[name].js` via Bun default. Prod: hashed filenames for caching. */
|
|
14
16
|
const ISLAND_JS_NAMING = IS_PROD ? '[dir]/[name]-[hash].[ext]' : undefined;
|
|
15
17
|
|
|
@@ -71,13 +73,14 @@ const PREACT_ISLAND_CACHE = new Map<string, PreactIslandCacheEntry>();
|
|
|
71
73
|
*/
|
|
72
74
|
async function copyPreactToPublicFolder(config: HS.Config) {
|
|
73
75
|
const currentNodeEnv = process.env.NODE_ENV || 'production';
|
|
74
|
-
const sourceFile = resolve(
|
|
76
|
+
const sourceFile = resolve(import.meta.dir, './preact-client.ts');
|
|
77
|
+
const outdir = resolve(CWD, config.publicDir, JS_ISLAND_PUBLIC_PATH.replace(/^\//, ''));
|
|
75
78
|
|
|
76
79
|
// Preact client JS is always production mode
|
|
77
80
|
process.env.NODE_ENV = 'production';
|
|
78
81
|
const result = await Bun.build({
|
|
79
82
|
entrypoints: [sourceFile],
|
|
80
|
-
outdir
|
|
83
|
+
outdir,
|
|
81
84
|
naming: ISLAND_JS_NAMING,
|
|
82
85
|
minify: true,
|
|
83
86
|
format: 'esm',
|
|
@@ -140,9 +143,10 @@ export function preactPlugin(): HS.Plugin {
|
|
|
140
143
|
log('tsx file not cached, building...', args.path);
|
|
141
144
|
// We need to build the file to ensure we can ship it to the client with dependencies
|
|
142
145
|
// Ironic, right? Calling Bun.build() inside of a plugin that runs on Bun.build()?
|
|
146
|
+
const islandOutdir = resolve(CWD, config.publicDir, JS_ISLAND_PUBLIC_PATH.replace(/^\//, ''));
|
|
143
147
|
const result = await Bun.build({
|
|
144
148
|
entrypoints: [args.path],
|
|
145
|
-
outdir:
|
|
149
|
+
outdir: islandOutdir,
|
|
146
150
|
naming: ISLAND_JS_NAMING,
|
|
147
151
|
external: Array.from(JS_IMPORT_MAP.keys()),
|
|
148
152
|
minify: true,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { h } from 'preact';
|
|
2
|
+
|
|
3
|
+
/** Top-level DOM access (fires as soon as this module is evaluated, before any render). */
|
|
4
|
+
void document.documentElement;
|
|
5
|
+
|
|
6
|
+
export default function UsesDocumentIsland(_props: Record<string, never>) {
|
|
7
|
+
return h('div', { 'data-test': 'uses-document-island' }, 'fixture');
|
|
8
|
+
}
|