@webjourney/vite-plugins 1.2.1 → 1.2.2

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/dist/build.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export interface BuildOptions {
2
- projectRoot: string;
3
- ssrEntry?: string;
2
+ projectRoot?: string;
3
+ appPath?: string;
4
4
  clientBuildOptions?: string;
5
5
  }
6
- export declare function buildWithSSR(options: BuildOptions): Promise<void>;
6
+ export declare function buildWithSSR(options?: BuildOptions): Promise<void>;
7
7
  //# sourceMappingURL=build.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE,YAAY,iBA4BvD"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAsB,YAAY,CAAC,OAAO,GAAE,YAAiB,iBA+C5D"}
package/dist/build.js CHANGED
@@ -1,30 +1,47 @@
1
1
  import { execSync } from 'node:child_process';
2
- import { createRequire } from 'node:module';
3
2
  import fs from 'node:fs';
4
3
  import path from 'node:path';
5
4
  import { JSDOM } from 'jsdom';
6
- export async function buildWithSSR(options) {
7
- const { projectRoot, ssrEntry = 'src/entry-server.tsx', clientBuildOptions = '--base=\'./\'' } = options;
5
+ export async function buildWithSSR(options = {}) {
6
+ const { projectRoot = process.cwd(), appPath = 'src/App.tsx', clientBuildOptions = '--base=\'./\'' } = options;
8
7
  const toAbsolute = (p) => path.resolve(projectRoot, p);
8
+ // Auto-generate entry-server.tsx
9
+ const generatedEntryServer = toAbsolute('.webjourney-entry-server.tsx');
10
+ const entryServerContent = `import { createServerRenderer } from '@webjourney/vite-plugins/entry-server';
11
+ import App from './${appPath.replace(/\.tsx?$/, '')}';
12
+
13
+ export { App };
14
+ export const render = createServerRenderer(App);
15
+ `;
9
16
  console.log('Building for production with SSR...\n');
10
- // Step 1: Type check
11
- console.log('1. Type checking...');
12
- execSync('tsc -b', { stdio: 'inherit', cwd: projectRoot });
13
- // Step 2: Build SSR bundle
14
- console.log('\n2. Building SSR bundle...');
15
- execSync(`vite build --ssr ${ssrEntry} --outDir dist-ssr`, { stdio: 'inherit', cwd: projectRoot });
16
- // Step 3: Build client bundle
17
- console.log('\n3. Building client bundle...');
18
- execSync(`vite build ${clientBuildOptions}`, { stdio: 'inherit', cwd: projectRoot });
19
- // Step 4: Pre-render HTML
20
- console.log('\n4. Pre-rendering HTML...');
21
- await prerender(projectRoot);
22
- console.log('\n✓ Build complete!');
17
+ try {
18
+ // Write temporary entry-server file
19
+ fs.writeFileSync(generatedEntryServer, entryServerContent);
20
+ // Step 1: Type check
21
+ console.log('1. Type checking...');
22
+ execSync('tsc -b', { stdio: 'inherit', cwd: projectRoot });
23
+ // Step 2: Build SSR bundle
24
+ console.log('\n2. Building SSR bundle...');
25
+ execSync(`vite build --ssr .webjourney-entry-server.tsx --outDir dist-ssr`, { stdio: 'inherit', cwd: projectRoot });
26
+ // Step 3: Build client bundle
27
+ console.log('\n3. Building client bundle...');
28
+ execSync(`vite build ${clientBuildOptions}`, { stdio: 'inherit', cwd: projectRoot });
29
+ // Step 4: Pre-render HTML
30
+ console.log('\n4. Pre-rendering HTML...');
31
+ await prerender(projectRoot);
32
+ console.log('\n✓ Build complete!');
33
+ }
34
+ finally {
35
+ // Clean up temporary entry-server file
36
+ if (fs.existsSync(generatedEntryServer)) {
37
+ fs.unlinkSync(generatedEntryServer);
38
+ }
39
+ }
23
40
  }
24
41
  async function extractRoutes(projectRoot) {
25
42
  const toAbsolute = (p) => path.resolve(projectRoot, p);
26
43
  // Import App component from the built SSR bundle
27
- const entryServerPath = toAbsolute('dist-ssr/entry-server.js');
44
+ const entryServerPath = toAbsolute('dist-ssr/.webjourney-entry-server.js');
28
45
  const { App } = await import(entryServerPath);
29
46
  // Create a temporary React element to traverse
30
47
  const appElement = App();
@@ -79,12 +96,10 @@ async function prerender(projectRoot) {
79
96
  value: dom.window.document,
80
97
  });
81
98
  // Import the server entry after setting up globals
82
- const entryServerPath = toAbsolute('dist-ssr/entry-server.js');
99
+ const entryServerPath = toAbsolute('dist-ssr/.webjourney-entry-server.js');
83
100
  const { render } = await import(entryServerPath);
84
101
  // Dynamically import renderToString from the project's react-dom
85
- // Use createRequire to properly resolve in hoisted workspaces
86
- const require = createRequire(path.join(projectRoot, 'package.json'));
87
- const reactDomServerPath = require.resolve('react-dom/server');
102
+ const reactDomServerPath = path.resolve(projectRoot, 'node_modules/react-dom/server');
88
103
  const { renderToString } = await import(reactDomServerPath);
89
104
  // Extract routes from App.tsx
90
105
  const routes = await extractRoutes(projectRoot);
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ import { buildWithSSR } from './build.js';
3
+ async function main() {
4
+ try {
5
+ await buildWithSSR();
6
+ }
7
+ catch (err) {
8
+ console.error('Build failed:', err);
9
+ process.exit(1);
10
+ }
11
+ }
12
+ main();
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@webjourney/vite-plugins",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Vite plugins for Webjourney WYSIWYG editing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
+ "bin": {
9
+ "webjourney-build": "./dist/cli.js"
10
+ },
8
11
  "exports": {
9
12
  ".": {
10
13
  "import": "./dist/index.js",