@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 +3 -3
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +35 -18
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +12 -0
- package/package.json +4 -1
package/dist/build.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export interface BuildOptions {
|
|
2
|
-
projectRoot
|
|
3
|
-
|
|
2
|
+
projectRoot?: string;
|
|
3
|
+
appPath?: string;
|
|
4
4
|
clientBuildOptions?: string;
|
|
5
5
|
}
|
|
6
|
-
export declare function buildWithSSR(options
|
|
6
|
+
export declare function buildWithSSR(options?: BuildOptions): Promise<void>;
|
|
7
7
|
//# sourceMappingURL=build.d.ts.map
|
package/dist/build.d.ts.map
CHANGED
|
@@ -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;
|
|
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,
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
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
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webjourney/vite-plugins",
|
|
3
|
-
"version": "1.2.
|
|
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",
|