vite-react-ssg 0.6.2 → 0.6.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/LICENSE +21 -21
- package/README.md +555 -555
- package/bin/vite-react-ssg.js +3 -3
- package/dist/chunks/jsdomGlobal.cjs +80 -79
- package/dist/chunks/jsdomGlobal.mjs +80 -79
- package/dist/client/single-page.cjs +1 -1
- package/dist/client/single-page.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/node/cli.cjs +1 -1
- package/dist/node/cli.mjs +1 -1
- package/dist/node.cjs +5 -3
- package/dist/node.mjs +6 -4
- package/dist/shared/{vite-react-ssg.a009fbf1.mjs → vite-react-ssg.579feabb.mjs} +1 -1
- package/dist/shared/{vite-react-ssg.e6991406.cjs → vite-react-ssg.bee8a5a9.cjs} +1 -1
- package/package.json +8 -13
package/bin/vite-react-ssg.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict'
|
|
3
|
-
import('../dist/node/cli.mjs')
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict'
|
|
3
|
+
import('../dist/node/cli.mjs')
|
|
@@ -6,85 +6,86 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
6
6
|
|
|
7
7
|
const JSDOM__default = /*#__PURE__*/_interopDefaultCompat(JSDOM);
|
|
8
8
|
|
|
9
|
-
/*
|
|
10
|
-
MIT License
|
|
11
|
-
|
|
12
|
-
Copyright for portions of global-jsdom are held by Rico Sta. Cruz, 2016 as part of
|
|
13
|
-
jsdom-global. All other copyright for global-jsdom are held by jonathan schatz, 2017.
|
|
14
|
-
|
|
15
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
17
|
-
in the Software without restriction, including without limitation the rights
|
|
18
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
20
|
-
furnished to do so, subject to the following conditions:
|
|
21
|
-
|
|
22
|
-
The above copyright notice and this permission notice shall be included in all
|
|
23
|
-
copies or substantial portions of the Software.
|
|
24
|
-
|
|
25
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
-
SOFTWARE.
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const defaultHtml = '<!doctype html><html><head><meta charset="utf-8"></head><body></body></html>';
|
|
36
|
-
|
|
37
|
-
// define this here so that we only ever dynamically populate KEYS once.
|
|
38
|
-
|
|
39
|
-
const KEYS = [];
|
|
40
|
-
|
|
41
|
-
function jsdomGlobal(html = defaultHtml, options = {}) {
|
|
42
|
-
// Idempotency
|
|
43
|
-
if (global.navigator
|
|
44
|
-
&& global.navigator.userAgent
|
|
45
|
-
&& global.navigator.userAgent.includes('Node.js')
|
|
46
|
-
&& global.document
|
|
47
|
-
&& typeof global.document.destroy === 'function')
|
|
48
|
-
return global.document.destroy
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
const {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
global.
|
|
78
|
-
window
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
9
|
+
/*
|
|
10
|
+
MIT License
|
|
11
|
+
|
|
12
|
+
Copyright for portions of global-jsdom are held by Rico Sta. Cruz, 2016 as part of
|
|
13
|
+
jsdom-global. All other copyright for global-jsdom are held by jonathan schatz, 2017.
|
|
14
|
+
|
|
15
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
in the Software without restriction, including without limitation the rights
|
|
18
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
furnished to do so, subject to the following conditions:
|
|
21
|
+
|
|
22
|
+
The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
copies or substantial portions of the Software.
|
|
24
|
+
|
|
25
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
SOFTWARE.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
const defaultHtml = '<!doctype html><html><head><meta charset="utf-8"></head><body></body></html>';
|
|
36
|
+
|
|
37
|
+
// define this here so that we only ever dynamically populate KEYS once.
|
|
38
|
+
|
|
39
|
+
const KEYS = [];
|
|
40
|
+
|
|
41
|
+
function jsdomGlobal(html = defaultHtml, options = {}) {
|
|
42
|
+
// Idempotency
|
|
43
|
+
if (global.navigator
|
|
44
|
+
&& global.navigator.userAgent
|
|
45
|
+
&& global.navigator.userAgent.includes('Node.js')
|
|
46
|
+
&& global.document
|
|
47
|
+
&& typeof global.document.destroy === 'function') {
|
|
48
|
+
return global.document.destroy
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// set a default url if we don't get one - otherwise things explode when we copy localstorage keys
|
|
52
|
+
if (!('url' in options))
|
|
53
|
+
Object.assign(options, { url: 'http://localhost:3000' });
|
|
54
|
+
|
|
55
|
+
// enable pretendToBeVisual by default since react needs
|
|
56
|
+
// window.requestAnimationFrame, see https://github.com/jsdom/jsdom#pretending-to-be-a-visual-browser
|
|
57
|
+
if (!('pretendToBeVisual' in options))
|
|
58
|
+
Object.assign(options, { pretendToBeVisual: true });
|
|
59
|
+
|
|
60
|
+
const jsdom = new JSDOM__default.JSDOM(html, options);
|
|
61
|
+
const { window } = jsdom;
|
|
62
|
+
const { document } = window;
|
|
63
|
+
|
|
64
|
+
// generate our list of keys by enumerating document.window - this list may vary
|
|
65
|
+
// based on the jsdom version. filter out internal methods as well as anything
|
|
66
|
+
// that node already defines
|
|
67
|
+
|
|
68
|
+
if (KEYS.length === 0) {
|
|
69
|
+
KEYS.push(...Object.getOwnPropertyNames(window).filter(k => !k.startsWith('_')).filter(k => !(k in global)));
|
|
70
|
+
// going to add our jsdom instance, see below
|
|
71
|
+
KEYS.push('$jsdom');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
KEYS.forEach(key => global[key] = window[key]);
|
|
75
|
+
|
|
76
|
+
// setup document / window / window.console
|
|
77
|
+
global.document = document;
|
|
78
|
+
global.window = window;
|
|
79
|
+
window.console = global.console;
|
|
80
|
+
|
|
81
|
+
// add access to our jsdom instance
|
|
82
|
+
global.$jsdom = jsdom;
|
|
83
|
+
|
|
84
|
+
const cleanup = () => KEYS.forEach(key => delete global[key]);
|
|
85
|
+
|
|
86
|
+
document.destroy = cleanup;
|
|
87
|
+
|
|
88
|
+
return cleanup
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
exports.jsdomGlobal = jsdomGlobal;
|
|
@@ -1,84 +1,85 @@
|
|
|
1
1
|
import JSDOM from 'jsdom';
|
|
2
2
|
|
|
3
|
-
/*
|
|
4
|
-
MIT License
|
|
5
|
-
|
|
6
|
-
Copyright for portions of global-jsdom are held by Rico Sta. Cruz, 2016 as part of
|
|
7
|
-
jsdom-global. All other copyright for global-jsdom are held by jonathan schatz, 2017.
|
|
8
|
-
|
|
9
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
-
in the Software without restriction, including without limitation the rights
|
|
12
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
-
furnished to do so, subject to the following conditions:
|
|
15
|
-
|
|
16
|
-
The above copyright notice and this permission notice shall be included in all
|
|
17
|
-
copies or substantial portions of the Software.
|
|
18
|
-
|
|
19
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
-
SOFTWARE.
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const defaultHtml = '<!doctype html><html><head><meta charset="utf-8"></head><body></body></html>';
|
|
30
|
-
|
|
31
|
-
// define this here so that we only ever dynamically populate KEYS once.
|
|
32
|
-
|
|
33
|
-
const KEYS = [];
|
|
34
|
-
|
|
35
|
-
function jsdomGlobal(html = defaultHtml, options = {}) {
|
|
36
|
-
// Idempotency
|
|
37
|
-
if (global.navigator
|
|
38
|
-
&& global.navigator.userAgent
|
|
39
|
-
&& global.navigator.userAgent.includes('Node.js')
|
|
40
|
-
&& global.document
|
|
41
|
-
&& typeof global.document.destroy === 'function')
|
|
42
|
-
return global.document.destroy
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
const {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
global.
|
|
72
|
-
window
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
3
|
+
/*
|
|
4
|
+
MIT License
|
|
5
|
+
|
|
6
|
+
Copyright for portions of global-jsdom are held by Rico Sta. Cruz, 2016 as part of
|
|
7
|
+
jsdom-global. All other copyright for global-jsdom are held by jonathan schatz, 2017.
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
const defaultHtml = '<!doctype html><html><head><meta charset="utf-8"></head><body></body></html>';
|
|
30
|
+
|
|
31
|
+
// define this here so that we only ever dynamically populate KEYS once.
|
|
32
|
+
|
|
33
|
+
const KEYS = [];
|
|
34
|
+
|
|
35
|
+
function jsdomGlobal(html = defaultHtml, options = {}) {
|
|
36
|
+
// Idempotency
|
|
37
|
+
if (global.navigator
|
|
38
|
+
&& global.navigator.userAgent
|
|
39
|
+
&& global.navigator.userAgent.includes('Node.js')
|
|
40
|
+
&& global.document
|
|
41
|
+
&& typeof global.document.destroy === 'function') {
|
|
42
|
+
return global.document.destroy
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// set a default url if we don't get one - otherwise things explode when we copy localstorage keys
|
|
46
|
+
if (!('url' in options))
|
|
47
|
+
Object.assign(options, { url: 'http://localhost:3000' });
|
|
48
|
+
|
|
49
|
+
// enable pretendToBeVisual by default since react needs
|
|
50
|
+
// window.requestAnimationFrame, see https://github.com/jsdom/jsdom#pretending-to-be-a-visual-browser
|
|
51
|
+
if (!('pretendToBeVisual' in options))
|
|
52
|
+
Object.assign(options, { pretendToBeVisual: true });
|
|
53
|
+
|
|
54
|
+
const jsdom = new JSDOM.JSDOM(html, options);
|
|
55
|
+
const { window } = jsdom;
|
|
56
|
+
const { document } = window;
|
|
57
|
+
|
|
58
|
+
// generate our list of keys by enumerating document.window - this list may vary
|
|
59
|
+
// based on the jsdom version. filter out internal methods as well as anything
|
|
60
|
+
// that node already defines
|
|
61
|
+
|
|
62
|
+
if (KEYS.length === 0) {
|
|
63
|
+
KEYS.push(...Object.getOwnPropertyNames(window).filter(k => !k.startsWith('_')).filter(k => !(k in global)));
|
|
64
|
+
// going to add our jsdom instance, see below
|
|
65
|
+
KEYS.push('$jsdom');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
KEYS.forEach(key => global[key] = window[key]);
|
|
69
|
+
|
|
70
|
+
// setup document / window / window.console
|
|
71
|
+
global.document = document;
|
|
72
|
+
global.window = window;
|
|
73
|
+
window.console = global.console;
|
|
74
|
+
|
|
75
|
+
// add access to our jsdom instance
|
|
76
|
+
global.$jsdom = jsdom;
|
|
77
|
+
|
|
78
|
+
const cleanup = () => KEYS.forEach(key => delete global[key]);
|
|
79
|
+
|
|
80
|
+
document.destroy = cleanup;
|
|
81
|
+
|
|
82
|
+
return cleanup
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
export { jsdomGlobal };
|
|
@@ -4,7 +4,7 @@ const client = require('react-dom/client');
|
|
|
4
4
|
const reactHelmetAsync = require('react-helmet-async');
|
|
5
5
|
const React = require('react');
|
|
6
6
|
const ClientOnly = require('../shared/vite-react-ssg.c1d49976.cjs');
|
|
7
|
-
const state = require('../shared/vite-react-ssg.
|
|
7
|
+
const state = require('../shared/vite-react-ssg.bee8a5a9.cjs');
|
|
8
8
|
|
|
9
9
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
10
10
|
|
|
@@ -3,7 +3,7 @@ import { HelmetProvider } from 'react-helmet-async';
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { d as documentReady } from '../shared/vite-react-ssg.a292c181.mjs';
|
|
5
5
|
export { C as ClientOnly, H as Head } from '../shared/vite-react-ssg.a292c181.mjs';
|
|
6
|
-
import { d as deserializeState } from '../shared/vite-react-ssg.
|
|
6
|
+
import { d as deserializeState } from '../shared/vite-react-ssg.579feabb.mjs';
|
|
7
7
|
|
|
8
8
|
function ViteReactSSG(App, fn, options = {}) {
|
|
9
9
|
const {
|
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,7 @@ const client = require('react-dom/client');
|
|
|
5
5
|
const reactHelmetAsync = require('react-helmet-async');
|
|
6
6
|
const reactRouterDom = require('react-router-dom');
|
|
7
7
|
const ClientOnly = require('./shared/vite-react-ssg.c1d49976.cjs');
|
|
8
|
-
const state = require('./shared/vite-react-ssg.
|
|
8
|
+
const state = require('./shared/vite-react-ssg.bee8a5a9.cjs');
|
|
9
9
|
|
|
10
10
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
11
11
|
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { HelmetProvider } from 'react-helmet-async';
|
|
|
4
4
|
import { useLinkClickHandler, Link as Link$1, NavLink as NavLink$1, matchRoutes, createBrowserRouter, RouterProvider } from 'react-router-dom';
|
|
5
5
|
import { d as documentReady } from './shared/vite-react-ssg.a292c181.mjs';
|
|
6
6
|
export { C as ClientOnly, H as Head } from './shared/vite-react-ssg.a292c181.mjs';
|
|
7
|
-
import { d as deserializeState } from './shared/vite-react-ssg.
|
|
7
|
+
import { d as deserializeState } from './shared/vite-react-ssg.579feabb.mjs';
|
|
8
8
|
|
|
9
9
|
const Link = forwardRef((props, ref) => {
|
|
10
10
|
const {
|
package/dist/node/cli.cjs
CHANGED
|
@@ -10,7 +10,7 @@ require('node:module');
|
|
|
10
10
|
require('fs-extra');
|
|
11
11
|
require('vite');
|
|
12
12
|
require('jsdom');
|
|
13
|
-
require('../shared/vite-react-ssg.
|
|
13
|
+
require('../shared/vite-react-ssg.bee8a5a9.cjs');
|
|
14
14
|
require('node:fs');
|
|
15
15
|
require('react');
|
|
16
16
|
require('react-helmet-async');
|
package/dist/node/cli.mjs
CHANGED
package/dist/node.cjs
CHANGED
|
@@ -6,7 +6,7 @@ const kolorist = require('kolorist');
|
|
|
6
6
|
const fs = require('fs-extra');
|
|
7
7
|
const vite = require('vite');
|
|
8
8
|
const JSDOM = require('jsdom');
|
|
9
|
-
const state = require('./shared/vite-react-ssg.
|
|
9
|
+
const state = require('./shared/vite-react-ssg.bee8a5a9.cjs');
|
|
10
10
|
const node_fs = require('node:fs');
|
|
11
11
|
const React = require('react');
|
|
12
12
|
const reactHelmetAsync = require('react-helmet-async');
|
|
@@ -1093,7 +1093,7 @@ async function renderHTML({
|
|
|
1093
1093
|
return renderedOutput;
|
|
1094
1094
|
}
|
|
1095
1095
|
async function detectEntry(root) {
|
|
1096
|
-
const scriptSrcReg = /<script(?:.*?)src=["'](.+?)["'](?!<)(?:.*)\>(?:[\n\r\s]*?)(?:<\/script>)/
|
|
1096
|
+
const scriptSrcReg = /<script(?:.*?)src=["'](.+?)["'](?!<)(?:.*)\>(?:[\n\r\s]*?)(?:<\/script>)/gim;
|
|
1097
1097
|
const html = await fs__default.readFile(node_path.join(root, "index.html"), "utf-8");
|
|
1098
1098
|
const scripts = [...html.matchAll(scriptSrcReg)];
|
|
1099
1099
|
const [, entry] = scripts.find((matchResult) => {
|
|
@@ -1480,7 +1480,9 @@ ${err.stack}`
|
|
|
1480
1480
|
const transformed = await onPageRendered?.(url, renderedHTML, appCtx) || renderedHTML;
|
|
1481
1481
|
res.statusCode = 200;
|
|
1482
1482
|
res.setHeader("Content-Type", "text/html");
|
|
1483
|
-
|
|
1483
|
+
const isDev = "pluginContainer" in server;
|
|
1484
|
+
const headers = isDev ? server.config.server.headers : server.config.preview.headers;
|
|
1485
|
+
vite.send(req, res, transformed, "html", { headers });
|
|
1484
1486
|
} catch (e) {
|
|
1485
1487
|
viteServer.ssrFixStacktrace(e);
|
|
1486
1488
|
console.error(`[vite-react-ssg] error: ${e.stack}`);
|
package/dist/node.mjs
CHANGED
|
@@ -2,9 +2,9 @@ import { join, isAbsolute, parse, dirname } from 'node:path';
|
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import { gray, yellow, blue, dim, cyan, red, green, reset, bold, bgLightCyan } from 'kolorist';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
|
-
import { resolveConfig, build as build$1, mergeConfig, version as version$1, createServer } from 'vite';
|
|
5
|
+
import { resolveConfig, build as build$1, mergeConfig, version as version$1, createServer, send } from 'vite';
|
|
6
6
|
import { JSDOM } from 'jsdom';
|
|
7
|
-
import { s as serializeState } from './shared/vite-react-ssg.
|
|
7
|
+
import { s as serializeState } from './shared/vite-react-ssg.579feabb.mjs';
|
|
8
8
|
import { readFileSync } from 'node:fs';
|
|
9
9
|
import React from 'react';
|
|
10
10
|
import { HelmetProvider } from 'react-helmet-async';
|
|
@@ -1086,7 +1086,7 @@ async function renderHTML({
|
|
|
1086
1086
|
return renderedOutput;
|
|
1087
1087
|
}
|
|
1088
1088
|
async function detectEntry(root) {
|
|
1089
|
-
const scriptSrcReg = /<script(?:.*?)src=["'](.+?)["'](?!<)(?:.*)\>(?:[\n\r\s]*?)(?:<\/script>)/
|
|
1089
|
+
const scriptSrcReg = /<script(?:.*?)src=["'](.+?)["'](?!<)(?:.*)\>(?:[\n\r\s]*?)(?:<\/script>)/gim;
|
|
1090
1090
|
const html = await fs.readFile(join(root, "index.html"), "utf-8");
|
|
1091
1091
|
const scripts = [...html.matchAll(scriptSrcReg)];
|
|
1092
1092
|
const [, entry] = scripts.find((matchResult) => {
|
|
@@ -1473,7 +1473,9 @@ ${err.stack}`
|
|
|
1473
1473
|
const transformed = await onPageRendered?.(url, renderedHTML, appCtx) || renderedHTML;
|
|
1474
1474
|
res.statusCode = 200;
|
|
1475
1475
|
res.setHeader("Content-Type", "text/html");
|
|
1476
|
-
|
|
1476
|
+
const isDev = "pluginContainer" in server;
|
|
1477
|
+
const headers = isDev ? server.config.server.headers : server.config.preview.headers;
|
|
1478
|
+
send(req, res, transformed, "html", { headers });
|
|
1477
1479
|
} catch (e) {
|
|
1478
1480
|
viteServer.ssrFixStacktrace(e);
|
|
1479
1481
|
console.error(`[vite-react-ssg] error: ${e.stack}`);
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-react-ssg",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.6.
|
|
5
|
-
"packageManager": "pnpm@
|
|
4
|
+
"version": "0.6.3",
|
|
5
|
+
"packageManager": "pnpm@9.4.0",
|
|
6
6
|
"description": "",
|
|
7
7
|
"author": "Riri <Daydreamerriri@outlook.com>",
|
|
8
8
|
"license": "MIT",
|
|
@@ -77,7 +77,6 @@
|
|
|
77
77
|
"typecheck": "tsc --noEmit"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
|
-
"@childrentime/devcert": "*",
|
|
81
80
|
"critters": "^0.0.19",
|
|
82
81
|
"prettier": "*",
|
|
83
82
|
"react": "^18.0.0",
|
|
@@ -87,9 +86,6 @@
|
|
|
87
86
|
"vite": "^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0"
|
|
88
87
|
},
|
|
89
88
|
"peerDependenciesMeta": {
|
|
90
|
-
"@childrentime/devcert": {
|
|
91
|
-
"optional": true
|
|
92
|
-
},
|
|
93
89
|
"critters": {
|
|
94
90
|
"optional": true
|
|
95
91
|
},
|
|
@@ -108,14 +104,13 @@
|
|
|
108
104
|
"fs-extra": "^11.2.0",
|
|
109
105
|
"html-minifier": "^4.0.0",
|
|
110
106
|
"html5parser": "^2.0.2",
|
|
111
|
-
"jsdom": "^24.
|
|
107
|
+
"jsdom": "^24.1.0",
|
|
112
108
|
"kolorist": "^1.8.0",
|
|
113
109
|
"react-helmet-async": "^1.3.0",
|
|
114
110
|
"yargs": "^17.7.2"
|
|
115
111
|
},
|
|
116
112
|
"devDependencies": {
|
|
117
|
-
"@
|
|
118
|
-
"@ririd/eslint-config": "^1.1.0",
|
|
113
|
+
"@ririd/eslint-config": "^1.3.2",
|
|
119
114
|
"@types/fs-extra": "^11.0.1",
|
|
120
115
|
"@types/html-minifier": "^4.0.2",
|
|
121
116
|
"@types/jsdom": "^21.1.1",
|
|
@@ -135,10 +130,10 @@
|
|
|
135
130
|
"react-router-dom": "^6.15.0",
|
|
136
131
|
"rimraf": "5.0.1",
|
|
137
132
|
"styled-components": "6.0.5",
|
|
138
|
-
"typescript": "5.
|
|
133
|
+
"typescript": "^5.5.2",
|
|
139
134
|
"unbuild": "^2.0.0",
|
|
140
|
-
"vite": "^5.
|
|
135
|
+
"vite": "^5.3.1",
|
|
141
136
|
"vite-plugin-pwa": "^0.17.4",
|
|
142
|
-
"vitest": "1.0
|
|
137
|
+
"vitest": "1.6.0"
|
|
143
138
|
}
|
|
144
|
-
}
|
|
139
|
+
}
|