@webjourney/vite-plugins 1.2.1 → 1.2.3

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":"AAMA,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
@@ -3,28 +3,46 @@ import { createRequire } from 'node:module';
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
5
5
  import { JSDOM } from 'jsdom';
6
- export async function buildWithSSR(options) {
7
- const { projectRoot, ssrEntry = 'src/entry-server.tsx', clientBuildOptions = '--base=\'./\'' } = options;
6
+ export async function buildWithSSR(options = {}) {
7
+ const { projectRoot = process.cwd(), appPath = 'src/App.tsx', clientBuildOptions = '--base=\'./\'' } = options;
8
8
  const toAbsolute = (p) => path.resolve(projectRoot, p);
9
+ // Auto-generate entry-server.tsx
10
+ const generatedEntryServer = toAbsolute('.webjourney-entry-server.tsx');
11
+ const entryServerContent = `import { createServerRenderer } from '@webjourney/vite-plugins/entry-server';
12
+ import App from './${appPath.replace(/\.tsx?$/, '')}';
13
+
14
+ export { App };
15
+ export const render = createServerRenderer(App);
16
+ `;
9
17
  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!');
18
+ try {
19
+ // Write temporary entry-server file
20
+ fs.writeFileSync(generatedEntryServer, entryServerContent);
21
+ // Step 1: Type check
22
+ console.log('1. Type checking...');
23
+ execSync('tsc -b', { stdio: 'inherit', cwd: projectRoot });
24
+ // Step 2: Build SSR bundle
25
+ console.log('\n2. Building SSR bundle...');
26
+ execSync(`vite build --ssr .webjourney-entry-server.tsx --outDir dist-ssr`, { stdio: 'inherit', cwd: projectRoot });
27
+ // Step 3: Build client bundle
28
+ console.log('\n3. Building client bundle...');
29
+ execSync(`vite build ${clientBuildOptions}`, { stdio: 'inherit', cwd: projectRoot });
30
+ // Step 4: Pre-render HTML
31
+ console.log('\n4. Pre-rendering HTML...');
32
+ await prerender(projectRoot);
33
+ console.log('\n✓ Build complete!');
34
+ }
35
+ finally {
36
+ // Clean up temporary entry-server file
37
+ if (fs.existsSync(generatedEntryServer)) {
38
+ fs.unlinkSync(generatedEntryServer);
39
+ }
40
+ }
23
41
  }
24
42
  async function extractRoutes(projectRoot) {
25
43
  const toAbsolute = (p) => path.resolve(projectRoot, p);
26
44
  // Import App component from the built SSR bundle
27
- const entryServerPath = toAbsolute('dist-ssr/entry-server.js');
45
+ const entryServerPath = toAbsolute('dist-ssr/.webjourney-entry-server.js');
28
46
  const { App } = await import(entryServerPath);
29
47
  // Create a temporary React element to traverse
30
48
  const appElement = App();
@@ -79,9 +97,8 @@ async function prerender(projectRoot) {
79
97
  value: dom.window.document,
80
98
  });
81
99
  // Import the server entry after setting up globals
82
- const entryServerPath = toAbsolute('dist-ssr/entry-server.js');
100
+ const entryServerPath = toAbsolute('dist-ssr/.webjourney-entry-server.js');
83
101
  const { render } = await import(entryServerPath);
84
- // Dynamically import renderToString from the project's react-dom
85
102
  // Use createRequire to properly resolve in hoisted workspaces
86
103
  const require = createRequire(path.join(projectRoot, 'package.json'));
87
104
  const reactDomServerPath = require.resolve('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.1",
3
+ "version": "1.2.3",
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",