vite-react-ssg 0.0.3 → 0.1.0
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 +292 -238
- package/bin/vite-react-ssg.js +3 -3
- package/dist/chunks/jsdomGlobal.cjs +79 -79
- package/dist/chunks/jsdomGlobal.mjs +79 -79
- package/dist/index.cjs +37 -2
- package/dist/index.d.ts +9 -3
- package/dist/index.mjs +44 -10
- package/dist/node/cli.cjs +29 -5
- package/dist/node/cli.mjs +28 -4
- package/dist/node.cjs +5 -2
- package/dist/node.d.ts +4 -2
- package/dist/node.mjs +3 -1
- package/dist/shared/{vite-react-ssg.524ba00d.mjs → vite-react-ssg.7ee042ba.mjs} +279 -65
- package/dist/shared/{vite-react-ssg.a5dfecac.cjs → vite-react-ssg.823b31c9.cjs} +279 -63
- package/dist/{types-82f34756.d.ts → types-25b96ed0.d.ts} +8 -0
- package/package.json +4 -2
|
@@ -6,85 +6,85 @@ 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
|
-
// set a default url if we don't get one - otherwise things explode when we copy localstorage keys
|
|
51
|
-
if (!('url' in options))
|
|
52
|
-
Object.assign(options, { url: 'http://localhost:3000' });
|
|
53
|
-
|
|
54
|
-
// enable pretendToBeVisual by default since react needs
|
|
55
|
-
// window.requestAnimationFrame, see https://github.com/jsdom/jsdom#pretending-to-be-a-visual-browser
|
|
56
|
-
if (!('pretendToBeVisual' in options))
|
|
57
|
-
Object.assign(options, { pretendToBeVisual: true });
|
|
58
|
-
|
|
59
|
-
const jsdom = new JSDOM__default.JSDOM(html, options);
|
|
60
|
-
const { window } = jsdom;
|
|
61
|
-
const { document } = window;
|
|
62
|
-
|
|
63
|
-
// generate our list of keys by enumerating document.window - this list may vary
|
|
64
|
-
// based on the jsdom version. filter out internal methods as well as anything
|
|
65
|
-
// that node already defines
|
|
66
|
-
|
|
67
|
-
if (KEYS.length === 0) {
|
|
68
|
-
KEYS.push(...Object.getOwnPropertyNames(window).filter(k => !k.startsWith('_')).filter(k => !(k in global)));
|
|
69
|
-
// going to add our jsdom instance, see below
|
|
70
|
-
KEYS.push('$jsdom');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
KEYS.forEach(key => global[key] = window[key]);
|
|
74
|
-
|
|
75
|
-
// setup document / window / window.console
|
|
76
|
-
global.document = document;
|
|
77
|
-
global.window = window;
|
|
78
|
-
window.console = global.console;
|
|
79
|
-
|
|
80
|
-
// add access to our jsdom instance
|
|
81
|
-
global.$jsdom = jsdom;
|
|
82
|
-
|
|
83
|
-
const cleanup = () => KEYS.forEach(key => delete global[key]);
|
|
84
|
-
|
|
85
|
-
document.destroy = cleanup;
|
|
86
|
-
|
|
87
|
-
return cleanup
|
|
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
|
+
// set a default url if we don't get one - otherwise things explode when we copy localstorage keys
|
|
51
|
+
if (!('url' in options))
|
|
52
|
+
Object.assign(options, { url: 'http://localhost:3000' });
|
|
53
|
+
|
|
54
|
+
// enable pretendToBeVisual by default since react needs
|
|
55
|
+
// window.requestAnimationFrame, see https://github.com/jsdom/jsdom#pretending-to-be-a-visual-browser
|
|
56
|
+
if (!('pretendToBeVisual' in options))
|
|
57
|
+
Object.assign(options, { pretendToBeVisual: true });
|
|
58
|
+
|
|
59
|
+
const jsdom = new JSDOM__default.JSDOM(html, options);
|
|
60
|
+
const { window } = jsdom;
|
|
61
|
+
const { document } = window;
|
|
62
|
+
|
|
63
|
+
// generate our list of keys by enumerating document.window - this list may vary
|
|
64
|
+
// based on the jsdom version. filter out internal methods as well as anything
|
|
65
|
+
// that node already defines
|
|
66
|
+
|
|
67
|
+
if (KEYS.length === 0) {
|
|
68
|
+
KEYS.push(...Object.getOwnPropertyNames(window).filter(k => !k.startsWith('_')).filter(k => !(k in global)));
|
|
69
|
+
// going to add our jsdom instance, see below
|
|
70
|
+
KEYS.push('$jsdom');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
KEYS.forEach(key => global[key] = window[key]);
|
|
74
|
+
|
|
75
|
+
// setup document / window / window.console
|
|
76
|
+
global.document = document;
|
|
77
|
+
global.window = window;
|
|
78
|
+
window.console = global.console;
|
|
79
|
+
|
|
80
|
+
// add access to our jsdom instance
|
|
81
|
+
global.$jsdom = jsdom;
|
|
82
|
+
|
|
83
|
+
const cleanup = () => KEYS.forEach(key => delete global[key]);
|
|
84
|
+
|
|
85
|
+
document.destroy = cleanup;
|
|
86
|
+
|
|
87
|
+
return cleanup
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
exports.jsdomGlobal = jsdomGlobal;
|
|
@@ -1,84 +1,84 @@
|
|
|
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
|
-
// set a default url if we don't get one - otherwise things explode when we copy localstorage keys
|
|
45
|
-
if (!('url' in options))
|
|
46
|
-
Object.assign(options, { url: 'http://localhost:3000' });
|
|
47
|
-
|
|
48
|
-
// enable pretendToBeVisual by default since react needs
|
|
49
|
-
// window.requestAnimationFrame, see https://github.com/jsdom/jsdom#pretending-to-be-a-visual-browser
|
|
50
|
-
if (!('pretendToBeVisual' in options))
|
|
51
|
-
Object.assign(options, { pretendToBeVisual: true });
|
|
52
|
-
|
|
53
|
-
const jsdom = new JSDOM.JSDOM(html, options);
|
|
54
|
-
const { window } = jsdom;
|
|
55
|
-
const { document } = window;
|
|
56
|
-
|
|
57
|
-
// generate our list of keys by enumerating document.window - this list may vary
|
|
58
|
-
// based on the jsdom version. filter out internal methods as well as anything
|
|
59
|
-
// that node already defines
|
|
60
|
-
|
|
61
|
-
if (KEYS.length === 0) {
|
|
62
|
-
KEYS.push(...Object.getOwnPropertyNames(window).filter(k => !k.startsWith('_')).filter(k => !(k in global)));
|
|
63
|
-
// going to add our jsdom instance, see below
|
|
64
|
-
KEYS.push('$jsdom');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
KEYS.forEach(key => global[key] = window[key]);
|
|
68
|
-
|
|
69
|
-
// setup document / window / window.console
|
|
70
|
-
global.document = document;
|
|
71
|
-
global.window = window;
|
|
72
|
-
window.console = global.console;
|
|
73
|
-
|
|
74
|
-
// add access to our jsdom instance
|
|
75
|
-
global.$jsdom = jsdom;
|
|
76
|
-
|
|
77
|
-
const cleanup = () => KEYS.forEach(key => delete global[key]);
|
|
78
|
-
|
|
79
|
-
document.destroy = cleanup;
|
|
80
|
-
|
|
81
|
-
return cleanup
|
|
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
|
+
// set a default url if we don't get one - otherwise things explode when we copy localstorage keys
|
|
45
|
+
if (!('url' in options))
|
|
46
|
+
Object.assign(options, { url: 'http://localhost:3000' });
|
|
47
|
+
|
|
48
|
+
// enable pretendToBeVisual by default since react needs
|
|
49
|
+
// window.requestAnimationFrame, see https://github.com/jsdom/jsdom#pretending-to-be-a-visual-browser
|
|
50
|
+
if (!('pretendToBeVisual' in options))
|
|
51
|
+
Object.assign(options, { pretendToBeVisual: true });
|
|
52
|
+
|
|
53
|
+
const jsdom = new JSDOM.JSDOM(html, options);
|
|
54
|
+
const { window } = jsdom;
|
|
55
|
+
const { document } = window;
|
|
56
|
+
|
|
57
|
+
// generate our list of keys by enumerating document.window - this list may vary
|
|
58
|
+
// based on the jsdom version. filter out internal methods as well as anything
|
|
59
|
+
// that node already defines
|
|
60
|
+
|
|
61
|
+
if (KEYS.length === 0) {
|
|
62
|
+
KEYS.push(...Object.getOwnPropertyNames(window).filter(k => !k.startsWith('_')).filter(k => !(k in global)));
|
|
63
|
+
// going to add our jsdom instance, see below
|
|
64
|
+
KEYS.push('$jsdom');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
KEYS.forEach(key => global[key] = window[key]);
|
|
68
|
+
|
|
69
|
+
// setup document / window / window.console
|
|
70
|
+
global.document = document;
|
|
71
|
+
global.window = window;
|
|
72
|
+
window.console = global.console;
|
|
73
|
+
|
|
74
|
+
// add access to our jsdom instance
|
|
75
|
+
global.$jsdom = jsdom;
|
|
76
|
+
|
|
77
|
+
const cleanup = () => KEYS.forEach(key => delete global[key]);
|
|
78
|
+
|
|
79
|
+
document.destroy = cleanup;
|
|
80
|
+
|
|
81
|
+
return cleanup
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
export { jsdomGlobal };
|
package/dist/index.cjs
CHANGED
|
@@ -19,10 +19,34 @@ function documentReady(_passThrough) {
|
|
|
19
19
|
return Promise.resolve(_passThrough);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
function useIsClient() {
|
|
23
|
+
const [isBrowser, setIsBrowser] = React.useState(false);
|
|
24
|
+
React.useEffect(() => {
|
|
25
|
+
setIsBrowser(true);
|
|
26
|
+
}, []);
|
|
27
|
+
return isBrowser;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function ClientOnly({
|
|
31
|
+
children,
|
|
32
|
+
fallback
|
|
33
|
+
}) {
|
|
34
|
+
const isBrowser = useIsClient();
|
|
35
|
+
if (isBrowser) {
|
|
36
|
+
if (typeof children !== "function" && process.env.NODE_ENV === "development") {
|
|
37
|
+
throw new Error(`vite-react-ssg error: The children of <ClientOnly> must be a "render function", e.g. <ClientOnly>{() => <span>{window.location.href}</span>}</ClientOnly>.
|
|
38
|
+
Current type: ${React.isValidElement(children) ? "React element" : typeof children}`);
|
|
39
|
+
}
|
|
40
|
+
return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, children?.());
|
|
41
|
+
}
|
|
42
|
+
return fallback ?? null;
|
|
43
|
+
}
|
|
44
|
+
|
|
22
45
|
function ViteReactSSG(routerOptions, fn, options = {}) {
|
|
23
46
|
const {
|
|
24
47
|
transformState,
|
|
25
|
-
rootContainer = "#root"
|
|
48
|
+
rootContainer = "#root",
|
|
49
|
+
ssrWhenDev = true
|
|
26
50
|
} = options;
|
|
27
51
|
const isClient = typeof window !== "undefined";
|
|
28
52
|
async function createRoot(client = false, routePath) {
|
|
@@ -64,11 +88,22 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
|
|
|
64
88
|
(async () => {
|
|
65
89
|
const container = typeof rootContainer === "string" ? document.querySelector(rootContainer) : rootContainer;
|
|
66
90
|
const { router } = await createRoot(true);
|
|
67
|
-
|
|
91
|
+
const app = /* @__PURE__ */ React__default.createElement(reactHelmetAsync.HelmetProvider, null, /* @__PURE__ */ React__default.createElement(SiteMetadataDefaults.SiteMetadataDefaults, null), /* @__PURE__ */ React__default.createElement(reactRouterDom.RouterProvider, { router }));
|
|
92
|
+
if (!ssrWhenDev && undefined.DEV) {
|
|
93
|
+
const root = client.createRoot(container);
|
|
94
|
+
React__default.startTransition(() => {
|
|
95
|
+
root.render(app);
|
|
96
|
+
});
|
|
97
|
+
} else {
|
|
98
|
+
React__default.startTransition(() => {
|
|
99
|
+
client.hydrateRoot(container, app);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
68
102
|
})();
|
|
69
103
|
}
|
|
70
104
|
return createRoot;
|
|
71
105
|
}
|
|
72
106
|
|
|
73
107
|
exports.Head = SiteMetadataDefaults.Head;
|
|
108
|
+
exports.ClientOnly = ClientOnly;
|
|
74
109
|
exports.ViteReactSSG = ViteReactSSG;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as RouterOptions, V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from './types-
|
|
2
|
-
export { I as IndexRouteRecord, N as NonIndexRouteRecord, c as RouteRecord, b as ViteReactSSGOptions } from './types-
|
|
1
|
+
import { R as RouterOptions, V as ViteReactSSGContext, a as ViteReactSSGClientOptions } from './types-25b96ed0.js';
|
|
2
|
+
export { I as IndexRouteRecord, N as NonIndexRouteRecord, c as RouteRecord, b as ViteReactSSGOptions } from './types-25b96ed0.js';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
4
|
import { HelmetProps } from 'react-helmet-async';
|
|
5
5
|
import 'critters';
|
|
@@ -10,6 +10,12 @@ type Props = HelmetProps & {
|
|
|
10
10
|
};
|
|
11
11
|
declare function Head(props: Props): JSX.Element;
|
|
12
12
|
|
|
13
|
+
interface ClientOnlyProps {
|
|
14
|
+
children?: () => JSX.Element;
|
|
15
|
+
fallback?: JSX.Element;
|
|
16
|
+
}
|
|
17
|
+
declare function ClientOnly({ children, fallback, }: ClientOnlyProps): JSX.Element | null;
|
|
18
|
+
|
|
13
19
|
declare function ViteReactSSG(routerOptions: RouterOptions, fn?: (context: ViteReactSSGContext<true>) => Promise<void> | void, options?: ViteReactSSGClientOptions): (client?: boolean, routePath?: string) => Promise<ViteReactSSGContext<true>>;
|
|
14
20
|
|
|
15
|
-
export { Head, RouterOptions, ViteReactSSG, ViteReactSSGClientOptions, ViteReactSSGContext };
|
|
21
|
+
export { ClientOnly, Head, RouterOptions, ViteReactSSG, ViteReactSSGClientOptions, ViteReactSSGContext };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { hydrateRoot } from 'react-dom/client';
|
|
1
|
+
import React, { useState, useEffect, isValidElement } from 'react';
|
|
2
|
+
import { createRoot, hydrateRoot } from 'react-dom/client';
|
|
3
3
|
import { HelmetProvider } from 'react-helmet-async';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
|
|
5
|
+
import { d as deserializeState, S as SiteMetadataDefaults } from './shared/vite-react-ssg.9d005d5e.mjs';
|
|
6
6
|
export { H as Head } from './shared/vite-react-ssg.9d005d5e.mjs';
|
|
7
7
|
|
|
8
8
|
function documentReady(_passThrough) {
|
|
@@ -14,13 +14,37 @@ function documentReady(_passThrough) {
|
|
|
14
14
|
return Promise.resolve(_passThrough);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
function useIsClient() {
|
|
18
|
+
const [isBrowser, setIsBrowser] = useState(false);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
setIsBrowser(true);
|
|
21
|
+
}, []);
|
|
22
|
+
return isBrowser;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function ClientOnly({
|
|
26
|
+
children,
|
|
27
|
+
fallback
|
|
28
|
+
}) {
|
|
29
|
+
const isBrowser = useIsClient();
|
|
30
|
+
if (isBrowser) {
|
|
31
|
+
if (typeof children !== "function" && process.env.NODE_ENV === "development") {
|
|
32
|
+
throw new Error(`vite-react-ssg error: The children of <ClientOnly> must be a "render function", e.g. <ClientOnly>{() => <span>{window.location.href}</span>}</ClientOnly>.
|
|
33
|
+
Current type: ${isValidElement(children) ? "React element" : typeof children}`);
|
|
34
|
+
}
|
|
35
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, children?.());
|
|
36
|
+
}
|
|
37
|
+
return fallback ?? null;
|
|
38
|
+
}
|
|
39
|
+
|
|
17
40
|
function ViteReactSSG(routerOptions, fn, options = {}) {
|
|
18
41
|
const {
|
|
19
42
|
transformState,
|
|
20
|
-
rootContainer = "#root"
|
|
43
|
+
rootContainer = "#root",
|
|
44
|
+
ssrWhenDev = true
|
|
21
45
|
} = options;
|
|
22
46
|
const isClient = typeof window !== "undefined";
|
|
23
|
-
async function createRoot(client = false, routePath) {
|
|
47
|
+
async function createRoot$1(client = false, routePath) {
|
|
24
48
|
const browserRouter = client ? createBrowserRouter(routerOptions.routes) : void 0;
|
|
25
49
|
const appRenderCallbacks = [];
|
|
26
50
|
const onSSRAppRendered = client ? () => {
|
|
@@ -58,11 +82,21 @@ function ViteReactSSG(routerOptions, fn, options = {}) {
|
|
|
58
82
|
if (isClient) {
|
|
59
83
|
(async () => {
|
|
60
84
|
const container = typeof rootContainer === "string" ? document.querySelector(rootContainer) : rootContainer;
|
|
61
|
-
const { router } = await createRoot(true);
|
|
62
|
-
|
|
85
|
+
const { router } = await createRoot$1(true);
|
|
86
|
+
const app = /* @__PURE__ */ React.createElement(HelmetProvider, null, /* @__PURE__ */ React.createElement(SiteMetadataDefaults, null), /* @__PURE__ */ React.createElement(RouterProvider, { router }));
|
|
87
|
+
if (!ssrWhenDev && import.meta.env.DEV) {
|
|
88
|
+
const root = createRoot(container);
|
|
89
|
+
React.startTransition(() => {
|
|
90
|
+
root.render(app);
|
|
91
|
+
});
|
|
92
|
+
} else {
|
|
93
|
+
React.startTransition(() => {
|
|
94
|
+
hydrateRoot(container, app);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
63
97
|
})();
|
|
64
98
|
}
|
|
65
|
-
return createRoot;
|
|
99
|
+
return createRoot$1;
|
|
66
100
|
}
|
|
67
101
|
|
|
68
|
-
export { ViteReactSSG };
|
|
102
|
+
export { ClientOnly, ViteReactSSG };
|
package/dist/node/cli.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const kolorist = require('kolorist');
|
|
4
4
|
const yargs = require('yargs');
|
|
5
5
|
const helpers = require('yargs/helpers');
|
|
6
|
-
const
|
|
6
|
+
const dev = require('../shared/vite-react-ssg.823b31c9.cjs');
|
|
7
7
|
require('node:path');
|
|
8
8
|
require('node:module');
|
|
9
9
|
require('fs-extra');
|
|
@@ -12,6 +12,8 @@ require('jsdom');
|
|
|
12
12
|
require('../shared/vite-react-ssg.4ca822c0.cjs');
|
|
13
13
|
require('react');
|
|
14
14
|
require('react-helmet-async');
|
|
15
|
+
require('express');
|
|
16
|
+
require('node:fs');
|
|
15
17
|
require('react-router-dom/server.js');
|
|
16
18
|
require('node:stream');
|
|
17
19
|
require('react-dom/server');
|
|
@@ -20,7 +22,7 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
20
22
|
|
|
21
23
|
const yargs__default = /*#__PURE__*/_interopDefaultCompat(yargs);
|
|
22
24
|
|
|
23
|
-
yargs__default(helpers.hideBin(process.argv)).scriptName("vite-ssg").usage("$0 [args]").command(
|
|
25
|
+
yargs__default(helpers.hideBin(process.argv)).scriptName("vite-react-ssg").usage("$0 [args]").command(
|
|
24
26
|
"build",
|
|
25
27
|
"Build SSG",
|
|
26
28
|
(args) => args.option("script", {
|
|
@@ -40,11 +42,33 @@ yargs__default(helpers.hideBin(process.argv)).scriptName("vite-ssg").usage("$0 [
|
|
|
40
42
|
}),
|
|
41
43
|
async (args) => {
|
|
42
44
|
const { config: configFile = void 0, ...ssgOptions } = args;
|
|
43
|
-
await
|
|
45
|
+
await dev.build(ssgOptions, { configFile });
|
|
46
|
+
}
|
|
47
|
+
).command(
|
|
48
|
+
"dev",
|
|
49
|
+
"Dev SSG",
|
|
50
|
+
(args) => args.option("script", {
|
|
51
|
+
choices: ["sync", "async", "defer", "async defer"],
|
|
52
|
+
describe: "Rewrites script loading timing"
|
|
53
|
+
}).option("mock", {
|
|
54
|
+
type: "boolean",
|
|
55
|
+
describe: "Mock browser globals (window, document, etc.) for SSG"
|
|
56
|
+
}).option("config", {
|
|
57
|
+
alias: "c",
|
|
58
|
+
type: "string",
|
|
59
|
+
describe: "The vite config file to use"
|
|
60
|
+
}).option("base", {
|
|
61
|
+
alias: "b",
|
|
62
|
+
type: "string",
|
|
63
|
+
describe: "The base path to render"
|
|
64
|
+
}),
|
|
65
|
+
async (args) => {
|
|
66
|
+
const { config: configFile = void 0, ...ssgOptions } = args;
|
|
67
|
+
await dev.dev(ssgOptions, { configFile });
|
|
44
68
|
}
|
|
45
69
|
).fail((msg, err, yargs2) => {
|
|
46
70
|
console.error(`
|
|
47
|
-
${kolorist.gray("[vite-ssg]")} ${kolorist.bold(kolorist.red("An internal error occurred."))}`);
|
|
48
|
-
console.error(`${kolorist.gray("[vite-ssg]")} ${kolorist.reset(`Please report an issue, if none already exists: ${kolorist.underline("https://github.com/
|
|
71
|
+
${kolorist.gray("[vite-react-ssg]")} ${kolorist.bold(kolorist.red("An internal error occurred."))}`);
|
|
72
|
+
console.error(`${kolorist.gray("[vite-react-ssg]")} ${kolorist.reset(`Please report an issue, if none already exists: ${kolorist.underline("https://github.com/daydreamer-riri/vite-react-ssg/issues")}`)}`);
|
|
49
73
|
yargs2.exit(1, err);
|
|
50
74
|
}).showHelpOnFail(false).help().argv;
|
package/dist/node/cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { gray, bold, red, reset, underline } from 'kolorist';
|
|
2
2
|
import yargs from 'yargs';
|
|
3
3
|
import { hideBin } from 'yargs/helpers';
|
|
4
|
-
import { b as build } from '../shared/vite-react-ssg.
|
|
4
|
+
import { b as build, d as dev } from '../shared/vite-react-ssg.7ee042ba.mjs';
|
|
5
5
|
import 'node:path';
|
|
6
6
|
import 'node:module';
|
|
7
7
|
import 'fs-extra';
|
|
@@ -10,11 +10,13 @@ import 'jsdom';
|
|
|
10
10
|
import '../shared/vite-react-ssg.9d005d5e.mjs';
|
|
11
11
|
import 'react';
|
|
12
12
|
import 'react-helmet-async';
|
|
13
|
+
import 'express';
|
|
14
|
+
import 'node:fs';
|
|
13
15
|
import 'react-router-dom/server.js';
|
|
14
16
|
import 'node:stream';
|
|
15
17
|
import 'react-dom/server';
|
|
16
18
|
|
|
17
|
-
yargs(hideBin(process.argv)).scriptName("vite-ssg").usage("$0 [args]").command(
|
|
19
|
+
yargs(hideBin(process.argv)).scriptName("vite-react-ssg").usage("$0 [args]").command(
|
|
18
20
|
"build",
|
|
19
21
|
"Build SSG",
|
|
20
22
|
(args) => args.option("script", {
|
|
@@ -36,9 +38,31 @@ yargs(hideBin(process.argv)).scriptName("vite-ssg").usage("$0 [args]").command(
|
|
|
36
38
|
const { config: configFile = void 0, ...ssgOptions } = args;
|
|
37
39
|
await build(ssgOptions, { configFile });
|
|
38
40
|
}
|
|
41
|
+
).command(
|
|
42
|
+
"dev",
|
|
43
|
+
"Dev SSG",
|
|
44
|
+
(args) => args.option("script", {
|
|
45
|
+
choices: ["sync", "async", "defer", "async defer"],
|
|
46
|
+
describe: "Rewrites script loading timing"
|
|
47
|
+
}).option("mock", {
|
|
48
|
+
type: "boolean",
|
|
49
|
+
describe: "Mock browser globals (window, document, etc.) for SSG"
|
|
50
|
+
}).option("config", {
|
|
51
|
+
alias: "c",
|
|
52
|
+
type: "string",
|
|
53
|
+
describe: "The vite config file to use"
|
|
54
|
+
}).option("base", {
|
|
55
|
+
alias: "b",
|
|
56
|
+
type: "string",
|
|
57
|
+
describe: "The base path to render"
|
|
58
|
+
}),
|
|
59
|
+
async (args) => {
|
|
60
|
+
const { config: configFile = void 0, ...ssgOptions } = args;
|
|
61
|
+
await dev(ssgOptions, { configFile });
|
|
62
|
+
}
|
|
39
63
|
).fail((msg, err, yargs2) => {
|
|
40
64
|
console.error(`
|
|
41
|
-
${gray("[vite-ssg]")} ${bold(red("An internal error occurred."))}`);
|
|
42
|
-
console.error(`${gray("[vite-ssg]")} ${reset(`Please report an issue, if none already exists: ${underline("https://github.com/
|
|
65
|
+
${gray("[vite-react-ssg]")} ${bold(red("An internal error occurred."))}`);
|
|
66
|
+
console.error(`${gray("[vite-react-ssg]")} ${reset(`Please report an issue, if none already exists: ${underline("https://github.com/daydreamer-riri/vite-react-ssg/issues")}`)}`);
|
|
43
67
|
yargs2.exit(1, err);
|
|
44
68
|
}).showHelpOnFail(false).help().argv;
|
package/dist/node.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const dev = require('./shared/vite-react-ssg.823b31c9.cjs');
|
|
4
4
|
require('node:path');
|
|
5
5
|
require('node:module');
|
|
6
6
|
require('kolorist');
|
|
@@ -10,10 +10,13 @@ require('jsdom');
|
|
|
10
10
|
require('./shared/vite-react-ssg.4ca822c0.cjs');
|
|
11
11
|
require('react');
|
|
12
12
|
require('react-helmet-async');
|
|
13
|
+
require('express');
|
|
14
|
+
require('node:fs');
|
|
13
15
|
require('react-router-dom/server.js');
|
|
14
16
|
require('node:stream');
|
|
15
17
|
require('react-dom/server');
|
|
16
18
|
|
|
17
19
|
|
|
18
20
|
|
|
19
|
-
exports.build =
|
|
21
|
+
exports.build = dev.build;
|
|
22
|
+
exports.dev = dev.dev;
|
package/dist/node.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { InlineConfig } from 'vite';
|
|
2
|
-
import { b as ViteReactSSGOptions } from './types-
|
|
2
|
+
import { b as ViteReactSSGOptions } from './types-25b96ed0.js';
|
|
3
3
|
import 'critters';
|
|
4
4
|
import 'react-router-dom';
|
|
5
5
|
|
|
6
6
|
declare function build(ssgOptions?: Partial<ViteReactSSGOptions>, viteConfig?: InlineConfig): Promise<void>;
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
declare function dev(ssgOptions?: Partial<ViteReactSSGOptions>, viteConfig?: InlineConfig): Promise<void>;
|
|
9
|
+
|
|
10
|
+
export { build, dev };
|