@webjourney/vite-plugins 1.2.0 → 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":"AAKA,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
@@ -2,28 +2,46 @@ import { execSync } from 'node:child_process';
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { JSDOM } from 'jsdom';
5
- export async function buildWithSSR(options) {
6
- 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;
7
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
+ `;
8
16
  console.log('Building for production with SSR...\n');
9
- // Step 1: Type check
10
- console.log('1. Type checking...');
11
- execSync('tsc -b', { stdio: 'inherit', cwd: projectRoot });
12
- // Step 2: Build SSR bundle
13
- console.log('\n2. Building SSR bundle...');
14
- execSync(`vite build --ssr ${ssrEntry} --outDir dist-ssr`, { stdio: 'inherit', cwd: projectRoot });
15
- // Step 3: Build client bundle
16
- console.log('\n3. Building client bundle...');
17
- execSync(`vite build ${clientBuildOptions}`, { stdio: 'inherit', cwd: projectRoot });
18
- // Step 4: Pre-render HTML
19
- console.log('\n4. Pre-rendering HTML...');
20
- await prerender(projectRoot);
21
- 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
+ }
22
40
  }
23
41
  async function extractRoutes(projectRoot) {
24
42
  const toAbsolute = (p) => path.resolve(projectRoot, p);
25
43
  // Import App component from the built SSR bundle
26
- const entryServerPath = toAbsolute('dist-ssr/entry-server.js');
44
+ const entryServerPath = toAbsolute('dist-ssr/.webjourney-entry-server.js');
27
45
  const { App } = await import(entryServerPath);
28
46
  // Create a temporary React element to traverse
29
47
  const appElement = App();
@@ -78,7 +96,7 @@ async function prerender(projectRoot) {
78
96
  value: dom.window.document,
79
97
  });
80
98
  // Import the server entry after setting up globals
81
- const entryServerPath = toAbsolute('dist-ssr/entry-server.js');
99
+ const entryServerPath = toAbsolute('dist-ssr/.webjourney-entry-server.js');
82
100
  const { render } = await import(entryServerPath);
83
101
  // Dynamically import renderToString from the project's react-dom
84
102
  const reactDomServerPath = path.resolve(projectRoot, 'node_modules/react-dom/server');
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.0",
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",