vite-react-ssg 0.1.2 → 0.2.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/README.md CHANGED
@@ -6,8 +6,6 @@ Static-site generation for React on Vite.
6
6
 
7
7
  ## Install
8
8
 
9
- > **This library requires Node.js version >= 17**
10
- > or `Request` is available
11
9
  <pre>
12
10
  <b>npm i -D vite-react-ssg</b> <em>react-router-dom</em>
13
11
  </pre>
@@ -176,11 +174,14 @@ Use the `getStyleCollector` option to specify an SSR/SSG style collector. Curren
176
174
 
177
175
  ```tsx
178
176
  import { ViteReactSSG } from 'vite-react-ssg'
179
- import { getStyledComponentsCollector } from 'vite-react-ssg/style-collectors'
177
+ import getStyledComponentsCollector from 'vite-react-ssg/style-collectors/styled-components'
180
178
  import { routes } from './App.js'
181
179
  import './index.css'
182
180
 
183
- export const createRoot = ViteReactSSG({ routes }, () => {}, { getStyleCollector: getStyledComponentsCollector })
181
+ export const createRoot = ViteReactSSG(
182
+ { routes },
183
+ () => { },
184
+ { getStyleCollector: getStyledComponentsCollector })
184
185
  ```
185
186
 
186
187
  You can provide your own by looking at the [implementation](./src/style-collectors/) of any of the existing collectors.
package/dist/node/cli.cjs CHANGED
@@ -3,6 +3,7 @@
3
3
  const kolorist = require('kolorist');
4
4
  const yargs = require('yargs');
5
5
  const helpers = require('yargs/helpers');
6
+ const webFetch = require('@remix-run/web-fetch');
6
7
  const dev = require('../shared/vite-react-ssg.b0fd1823.cjs');
7
8
  require('node:path');
8
9
  require('node:module');
@@ -22,6 +23,44 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
22
23
 
23
24
  const yargs__default = /*#__PURE__*/_interopDefaultCompat(yargs);
24
25
 
26
+ class NodeRequest extends webFetch.Request {
27
+ constructor(info, init) {
28
+ super(info, init);
29
+ }
30
+ get headers() {
31
+ return super.headers;
32
+ }
33
+ clone() {
34
+ return new NodeRequest(this);
35
+ }
36
+ }
37
+ class NodeResponse extends webFetch.Response {
38
+ get headers() {
39
+ return super.headers;
40
+ }
41
+ clone() {
42
+ return super.clone();
43
+ }
44
+ }
45
+ const fetch = (info, init) => {
46
+ init = {
47
+ // Disable compression handling so people can return the result of a fetch
48
+ // directly in the loader without messing with the Content-Encoding header.
49
+ compress: false,
50
+ ...init
51
+ };
52
+ return webFetch.fetch(info, init);
53
+ };
54
+
55
+ function installGlobals() {
56
+ global.Headers = webFetch.Headers;
57
+ global.Request = NodeRequest;
58
+ global.Response = NodeResponse;
59
+ global.fetch = fetch;
60
+ global.FormData = webFetch.FormData;
61
+ }
62
+
63
+ installGlobals();
25
64
  yargs__default(helpers.hideBin(process.argv)).scriptName("vite-react-ssg").usage("$0 [args]").command(
26
65
  "build",
27
66
  "Build SSG",
package/dist/node/cli.mjs CHANGED
@@ -1,6 +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 { Request, Response, fetch as fetch$1, Headers, FormData } from '@remix-run/web-fetch';
4
5
  import { b as build, d as dev } from '../shared/vite-react-ssg.b83f6ed3.mjs';
5
6
  import 'node:path';
6
7
  import 'node:module';
@@ -16,6 +17,44 @@ import 'react-router-dom/server.js';
16
17
  import 'node:stream';
17
18
  import 'react-dom/server';
18
19
 
20
+ class NodeRequest extends Request {
21
+ constructor(info, init) {
22
+ super(info, init);
23
+ }
24
+ get headers() {
25
+ return super.headers;
26
+ }
27
+ clone() {
28
+ return new NodeRequest(this);
29
+ }
30
+ }
31
+ class NodeResponse extends Response {
32
+ get headers() {
33
+ return super.headers;
34
+ }
35
+ clone() {
36
+ return super.clone();
37
+ }
38
+ }
39
+ const fetch = (info, init) => {
40
+ init = {
41
+ // Disable compression handling so people can return the result of a fetch
42
+ // directly in the loader without messing with the Content-Encoding header.
43
+ compress: false,
44
+ ...init
45
+ };
46
+ return fetch$1(info, init);
47
+ };
48
+
49
+ function installGlobals() {
50
+ global.Headers = Headers;
51
+ global.Request = NodeRequest;
52
+ global.Response = NodeResponse;
53
+ global.fetch = fetch;
54
+ global.FormData = FormData;
55
+ }
56
+
57
+ installGlobals();
19
58
  yargs(hideBin(process.argv)).scriptName("vite-react-ssg").usage("$0 [args]").command(
20
59
  "build",
21
60
  "Build SSG",
@@ -1,8 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ const styledComponents = require('styled-components');
4
+
3
5
  async function ssrCollector() {
4
- const { ServerStyleSheet } = await import('styled-components');
5
- const sheet = new ServerStyleSheet();
6
+ const sheet = new styledComponents.ServerStyleSheet();
6
7
  return {
7
8
  collect(app) {
8
9
  return sheet.collectStyles(app);
@@ -15,6 +16,5 @@ async function ssrCollector() {
15
16
  }
16
17
  };
17
18
  }
18
- const styledComponents = undefined.SSR ? ssrCollector : null;
19
19
 
20
- exports.getStyledComponentsCollector = styledComponents;
20
+ module.exports = ssrCollector;
@@ -5,6 +5,5 @@ declare function ssrCollector(): Promise<{
5
5
  toString(): string;
6
6
  cleanup(): void;
7
7
  }>;
8
- declare const _default: typeof ssrCollector | null;
9
8
 
10
- export { _default as getStyledComponentsCollector };
9
+ export { ssrCollector as default };
@@ -1,5 +1,6 @@
1
+ import { ServerStyleSheet } from 'styled-components';
2
+
1
3
  async function ssrCollector() {
2
- const { ServerStyleSheet } = await import('styled-components');
3
4
  const sheet = new ServerStyleSheet();
4
5
  return {
5
6
  collect(app) {
@@ -13,6 +14,5 @@ async function ssrCollector() {
13
14
  }
14
15
  };
15
16
  }
16
- const styledComponents = import.meta.env.SSR ? ssrCollector : null;
17
17
 
18
- export { styledComponents as getStyledComponentsCollector };
18
+ export { ssrCollector as default };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-react-ssg",
3
3
  "type": "module",
4
- "version": "0.1.2",
4
+ "version": "0.2.0",
5
5
  "packageManager": "pnpm@8.6.6",
6
6
  "description": "",
7
7
  "author": "Riri <Daydreamerriri@outlook.com>",
@@ -31,10 +31,10 @@
31
31
  "require": "./dist/node.cjs",
32
32
  "import": "./dist/node.mjs"
33
33
  },
34
- "./style-collectors": {
35
- "types": "./dist/style-collectors.d.ts",
36
- "require": "./dist/style-collectors.cjs",
37
- "import": "./dist/style-collectors.mjs"
34
+ "./style-collectors/styled-components": {
35
+ "types": "./dist/style-collectors/styled-components.d.ts",
36
+ "require": "./dist/style-collectors/styled-components.cjs",
37
+ "import": "./dist/style-collectors/styled-components.mjs"
38
38
  }
39
39
  },
40
40
  "main": "./dist/index.mjs",
@@ -45,8 +45,8 @@
45
45
  "node": [
46
46
  "./dist/node.d.ts"
47
47
  ],
48
- "style-collectors": [
49
- "./dist/style-collectors.d.ts"
48
+ "style-collectors/styled-components": [
49
+ "./dist/style-collectors/styled-components.d.ts"
50
50
  ]
51
51
  }
52
52
  },
@@ -87,6 +87,7 @@
87
87
  }
88
88
  },
89
89
  "dependencies": {
90
+ "@remix-run/web-fetch": "^4.3.5",
90
91
  "express": "^4.18.2",
91
92
  "fs-extra": "^11.1.1",
92
93
  "html-minifier": "^4.0.0",