1
- TODO:
2
-
3
- - CLI & args
1
+ ## TODO:
2
+
3
+ - tag v1
4
+ - CLI: --no-http-server
5
+ - Remove sitemap output dir???? + rename sitemap option to be a single one for
6
+ enabling and cannonicalUrl
7
+ - Publish npm package 0.9
8
+
9
+ # ` prerender-spa-ultra `
10
+
11
+ Converts your ` JavaScript ` -powered
12
+ [ SPA] ( https://developer.mozilla.org/en-US/docs/Glossary/SPA ' Single Page Application ')
13
+ web application into individual ` *.html ` documents (_ one for each unique ` URL `
14
+ your app has_ ) filled with the content that your ` JavaScript ` generated for
15
+ them.
16
+
17
+ ### When is this useful?
18
+
19
+ 1 . When you use ` /deep/link/to/a/page ` and you want to get a nice preview of
20
+ that page when its ` URL ` is shared.
21
+
22
+ Link sharing over most channels like messaging apps, social networks or other
23
+ websites will not run ` JavaScript ` , so they will preview your ` URL ` based on
24
+ your static ` *.html ` (_ which is likely empty_ ). So if you want to preview
25
+ meaningful things that are shown with JavaScript like the the page main
26
+ image, or the correct page title you want to ` prerender ` and convert that
27
+ empty static html to multiple files (_ one per unique URL_ ) filled with the
28
+ corresponding content.
29
+
30
+ 2 . When you expect slow connection to your website or huge size of your
31
+ JavaScript. Instead of making your users wait staring at a blank page you can
32
+ ` prerender ` that page, so that the html that gets loaded includes the
33
+ corresponding content and only make the users wait for ` JavaScript `
34
+
35
+ ## Usage
36
+
37
+ 1 . As a ` github action ` ([ _ see all settings_ ] ( #github-action ) ):
38
+ ``` yaml
39
+ uses : antitoxic/prerender-spa-ultra@v1
40
+ with :
41
+ website_root : ' path/to/your/spa/dist'
42
+ ` ` `
43
+ 2. As ` CLI` ([_see options_](#cli)):
44
+ 1. serve your
45
+ [SPA](https://developer.mozilla.org/en-US/docs/Glossary/SPA 'Single Page Application')
46
+ static files :
47
+ ` ` ` shell
48
+ cd <path/to/your/output/dir>
49
+ ` ` `
50
+ And then you can pick one of 2 options :
51
+
52
+ 1. using a python 3 file included in `prerender-spa-ultra`
53
+ ` ` ` shell
54
+ python <path/to/node_modules>/prerender-spa-ultra/src/http-server.py
55
+ ` ` `
56
+ 2. using the `node-static` package
57
+ ` ` ` shell
58
+ npx node-static --spa
59
+ npx http-server --proxy "http://localhost:8080?"
60
+ npx serve --single
61
+ ` ` `
62
+ 2. run prerender :
63
+ ` ` ` shell
64
+ npx prerender-spa-ultra <path/to/your/output/dir>
65
+ ` ` `
66
+ 3. As an `npm` package ([_see all settings_](#github-action)):
67
+
68
+ ` ` ` typescript
69
+ import { preRenderSite } from 'prerender-spa-ultra';
70
+ await preRenderSite({
71
+ outputDir: 'path/to/output',
72
+ startingUrl: 'http://localhost:8000',
73
+ });
74
+ ` ` `
4
75
5
- 1 . Start local http server in your output dir using:
76
+ 4 . Start local http server in your web root (_also output_) dir using :
6
77
` ` ` shell
7
78
cd <path/to/your/output/dir>
8
79
python <path/to/node_modules>/prerender-spa-ultra/src/http-server.py
9
80
` ` `
10
- 2 . use this domain when pre-rendering
81
+ 5 . use this domain when pre-rendering
11
82
12
- # Goals
83
+ # # Goals
13
84
14
85
- **Simplest prerender out there**
15
86
- Single dependency (`puppeteer-core`), nothing else. This also means saving
44
115
45
116
` ` ` shell
46
117
PRERENDER_SPA_ULTRA_DEBUG=1 npx prerender-spa-ultra ....
47
- PRERENDER_SPA_ULTRA_DEBUG=1 < your command that uses this package>
118
+ # or
119
+ PRERENDER_SPA_ULTRA_DEBUG=1 <your command that uses this package programatically>
48
120
` ` `
49
121
50
122
# # Non-goals
@@ -66,7 +138,7 @@ PRERENDER_SPA_ULTRA_DEBUG=1 <your command that uses this package>
66
138
installed. Otherwise you can use the OS package manager to install or use
67
139
` node-chromium` (`npm install chromium`)
68
140
69
- # Prior art
141
+ # # Prior art
70
142
71
143
- https://github.com/egoist/presite
72
144
- https://github.com/stereobooster/react-snap
@@ -75,32 +147,36 @@ PRERENDER_SPA_ULTRA_DEBUG=1 <your command that uses this package>
75
147
- https://github.com/sPavl0v/react-spa-prenderer
76
148
- https://github.com/chrisvfritz/prerender-spa-plugin
77
149
78
- # External Pre-render Services available
150
+ # # External Pre-render Services available
79
151
80
152
- https://webprerender.io/pricing/
81
153
- https://prerender.io/
82
154
83
- # Marketing locations
155
+ # # Marketing locations
84
156
85
157
- https://github.com/automata/awesome-jamstack
86
158
- (old) https://www.tnd.dev/tool/
87
159
88
160
# Limitations & Caveats
89
161
90
- 1 . This library shares a limitation that any pre-rendering intended for use by a
91
- static file server: it doesn't work with hash-based routing of SPAs (i.e.
92
- ` example.com/#route ` ). This is because the server never sees the ` #... ` part
93
- of the url so it can't find a file based it. If you are in this scenario you
94
- can try migrating to html5 push history
162
+ 1. This library shares 2 limitations that any other pre-rendering lib has :
163
+ 1. It doesn't work with hash-based routing of SPAs (i.e.
164
+ ` example.com/#route` ). This is because the server never sees the `#...`
165
+ part of the url so it can't find a file based it. If you are in this
166
+ scenario you can try migrating to html5 push history.
167
+ 2. Your assets (_media files, `*.js`, `*.css`_) should not be linked as
168
+ relative paths since pre-rendering creates a nested folder structure to
169
+ match the urls you have. Instead, those should be linked from your URL
170
+ root (`/...`).
95
171
2. The library will ignore query params and consider all urls having matching
96
172
` pathname` to be one and the same url. You can override this by providing a
97
- custom ` cleanUrl ` and ` getFilename ` functions to ` prerenderSite `
173
+ custom `cleanUrl` and `getFilename` functions to `preRenderSite `
98
174
3. The default `cleanUrl` trims any slashes, which means `some/url/path/` and
99
175
` some/url/path` will be considered the same
100
176
101
177
# Background & References
102
178
103
- - Cannot use JSDOM since it can't safely execute ` <script/> ` s
179
+ - Not ideal to use JSDOM since it can't safely execute `<script/>`s
104
180
- Good jam-stack intro video : https://vimeo.com/163522126 and the rest:
105
181
https://jamstack.org/resources/videos/
106
182
- Available binary packages in various CI/CD pre-build images :
@@ -112,3 +188,15 @@ PRERENDER_SPA_ULTRA_DEBUG=1 <your command that uses this package>
112
188
- Github actions running locally :
113
189
- https://stackoverflow.com/questions/59241249/how-to-run-github-actions-workflows-locally
114
190
- https://github.com/nektos/act
191
+
192
+ # # Cloudflare integration
193
+
194
+ https://developers.cloudflare.com/workers/wrangler/ci-cd/
195
+
196
+ To use cloudflare cli (`wrangler`) from CI like github actions you need to
197
+ create `CLOUDFLARE_API_TOKEN` and add it as a secret in that CI environment
198
+
199
+ Maybe you will need to set `CLOUDFLARE_ACCOUNT_ID` if you have more than 1
200
+ accounts associated with this API token.
201
+
202
+ Must expose github secret as ENV variable (not done by default)
0 commit comments