vitrify 0.5.10 → 0.6.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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { promises as fs } from 'fs';
|
|
2
2
|
import { routesToPaths } from '../../helpers/routes.js';
|
|
3
|
+
import Critters from 'critters';
|
|
3
4
|
export const prerender = async ({ outDir, templatePath, manifestPath, entryServerPath, onRenderedHooks }) => {
|
|
4
5
|
const promises = [];
|
|
5
6
|
const template = (await fs.readFile(templatePath)).toString();
|
|
@@ -7,6 +8,13 @@ export const prerender = async ({ outDir, templatePath, manifestPath, entryServe
|
|
|
7
8
|
const { render, getRoutes } = await import(entryServerPath);
|
|
8
9
|
const routes = await getRoutes();
|
|
9
10
|
const paths = routesToPaths(routes).filter((i) => !i.includes(':') && !i.includes('*'));
|
|
11
|
+
const critters = new Critters({
|
|
12
|
+
path: outDir,
|
|
13
|
+
logLevel: 'warn',
|
|
14
|
+
external: true,
|
|
15
|
+
inlineFonts: true,
|
|
16
|
+
preloadFonts: true
|
|
17
|
+
});
|
|
10
18
|
for (const url of paths) {
|
|
11
19
|
const filename = (url.endsWith('/') ? 'index' : url.replace(/^\//g, '')) + '.html';
|
|
12
20
|
console.log(`Generating ${filename}`);
|
|
@@ -18,6 +26,7 @@ export const prerender = async ({ outDir, templatePath, manifestPath, entryServe
|
|
|
18
26
|
let html = template
|
|
19
27
|
.replace(`<!--preload-links-->`, preloadLinks)
|
|
20
28
|
.replace(`<!--app-html-->`, appHtml);
|
|
29
|
+
html = await critters.process(html);
|
|
21
30
|
if (onRenderedHooks?.length) {
|
|
22
31
|
for (const ssrFunction of onRenderedHooks) {
|
|
23
32
|
html = ssrFunction(html, ssrContext);
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { promises as fs } from 'fs'
|
|
2
2
|
import { routesToPaths } from '../../helpers/routes.js'
|
|
3
3
|
import type { OnRenderedHook } from '../../vitrify-config.js'
|
|
4
|
+
import Critters from 'critters'
|
|
4
5
|
|
|
5
6
|
export const prerender = async ({
|
|
6
7
|
outDir,
|
|
@@ -23,6 +24,13 @@ export const prerender = async ({
|
|
|
23
24
|
const paths = routesToPaths(routes).filter(
|
|
24
25
|
(i) => !i.includes(':') && !i.includes('*')
|
|
25
26
|
)
|
|
27
|
+
const critters = new Critters({
|
|
28
|
+
path: outDir,
|
|
29
|
+
logLevel: 'warn',
|
|
30
|
+
external: true,
|
|
31
|
+
inlineFonts: true,
|
|
32
|
+
preloadFonts: true
|
|
33
|
+
})
|
|
26
34
|
for (const url of paths) {
|
|
27
35
|
const filename =
|
|
28
36
|
(url.endsWith('/') ? 'index' : url.replace(/^\//g, '')) + '.html'
|
|
@@ -37,6 +45,8 @@ export const prerender = async ({
|
|
|
37
45
|
.replace(`<!--preload-links-->`, preloadLinks)
|
|
38
46
|
.replace(`<!--app-html-->`, appHtml)
|
|
39
47
|
|
|
48
|
+
html = await critters.process(html)
|
|
49
|
+
|
|
40
50
|
if (onRenderedHooks?.length) {
|
|
41
51
|
for (const ssrFunction of onRenderedHooks) {
|
|
42
52
|
html = ssrFunction(html, ssrContext)
|