vitrify 0.10.3 → 0.10.5

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/dist/bin/dev.js CHANGED
@@ -38,7 +38,9 @@ ssr, framework = 'vue', host, appDir, publicDir, base }) {
38
38
  __HOST__: `'${host}'`
39
39
  };
40
40
  const wsPort = await getFirstOpenPort(24678);
41
- exitLogs.push(`[warning] HTTPS mode enabled. Visit https://{hostname}:${wsPort} to enable a security exception for HMR.`);
41
+ if (config.server?.https) {
42
+ exitLogs.push(`[warning] HTTPS mode enabled. Visit https://{hostname}:${wsPort} to enable a security exception for HMR.`);
43
+ }
42
44
  config.server = {
43
45
  https: config.server?.https,
44
46
  hmr: {
@@ -1,6 +1,7 @@
1
1
  import fastifyStatic from '@fastify/static';
2
2
  import { readFileSync } from 'fs';
3
3
  import { componentsModules, collectCss } from '../../helpers/collect-css-ssr.js';
4
+ import { appendToHead } from '../../helpers/utils.js';
4
5
  const fastifySsrPlugin = async (fastify, options, done) => {
5
6
  options.baseUrl = options.baseUrl || '/';
6
7
  options.mode = options.mode || process.env.MODE || import.meta.env.MODE;
@@ -96,13 +97,13 @@ const fastifySsrPlugin = async (fastify, options, done) => {
96
97
  ssrContext.initialState = {};
97
98
  ssrContext.initialState.provide = provide;
98
99
  let html = template
99
- .replace(`<!--preload-links-->`, preloadLinks)
100
100
  .replace(`<!--app-html-->`, appHtml)
101
101
  .replace('<!--product-name-->', options.productName || 'Product name')
102
102
  .replace('<!--dev-ssr-css-->', css)
103
103
  .replace('<!--initial-state-->', `<script>
104
104
  __INITIAL_STATE__ = '${JSON.stringify(ssrContext.initialState)}'
105
105
  </script>`);
106
+ html = appendToHead(preloadLinks, html);
106
107
  if (options.onRendered?.length) {
107
108
  for (const ssrFunction of options.onRendered) {
108
109
  html = ssrFunction(html, ssrContext);
@@ -144,12 +145,10 @@ const fastifySsrPlugin = async (fastify, options, done) => {
144
145
  if (!ssrContext.initialState)
145
146
  ssrContext.initialState = {};
146
147
  ssrContext.initialState.provide = provide;
147
- let html = template
148
- .replace(`<!--preload-links-->`, preloadLinks)
149
- .replace(`<!--app-html-->`, appHtml)
150
- .replace('<!--initial-state-->', `<script>
148
+ let html = template.replace(`<!--app-html-->`, appHtml).replace('<!--initial-state-->', `<script>
151
149
  __INITIAL_STATE__ = '${JSON.stringify(ssrContext.initialState)}'
152
150
  </script>`);
151
+ html = appendToHead(preloadLinks, html);
153
152
  if (options.onRendered?.length) {
154
153
  for (const ssrFunction of options.onRendered) {
155
154
  html = ssrFunction(html, ssrContext);
@@ -1,9 +1,10 @@
1
1
  import { promises as fs } from 'fs';
2
2
  import { routesToPaths } from '../../helpers/routes.js';
3
+ import { appendToHead } from '../../helpers/utils.js';
3
4
  export const prerender = async ({ outDir, templatePath, manifestPath, entryServerPath, onRendered }) => {
4
5
  const promises = [];
5
6
  const template = (await fs.readFile(templatePath)).toString();
6
- const manifest = await fs.readFile(manifestPath);
7
+ const manifest = JSON.parse((await fs.readFile(manifestPath)).toString());
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('*'));
@@ -12,8 +13,7 @@ export const prerender = async ({ outDir, templatePath, manifestPath, entryServe
12
13
  logLevel: 'warn',
13
14
  external: true,
14
15
  inlineFonts: true,
15
- preloadFonts: true,
16
- preload: 'swap'
16
+ preloadFonts: true
17
17
  });
18
18
  for (const url of paths) {
19
19
  const filename = (url.endsWith('/') ? 'index' : url.replace(/^\//g, '')) + '.html';
@@ -23,9 +23,9 @@ export const prerender = async ({ outDir, templatePath, manifestPath, entryServe
23
23
  res: {}
24
24
  };
25
25
  const [appHtml, preloadLinks] = await render(url, manifest, ssrContext);
26
- let html = template
27
- .replace(`<!--preload-links-->`, preloadLinks)
28
- .replace(`<!--app-html-->`, appHtml);
26
+ let html = template.replace(`<!--app-html-->`, appHtml);
27
+ html = appendToHead(preloadLinks, html);
28
+ // html = appendToBody(preloadLinks, html)
29
29
  if (onRendered?.length) {
30
30
  for (const ssrFunction of onRendered) {
31
31
  html = ssrFunction(html, ssrContext);
@@ -22,3 +22,5 @@ export function resolveHostname(optionsHost) {
22
22
  : host;
23
23
  return { host, name };
24
24
  }
25
+ export const appendToHead = (preloadLinks, html) => html.replace(/<\/head>/, preloadLinks + '</head>');
26
+ export const appendToBody = (links, html) => html.replace(/<\/body>/, links + '</body>');
package/dist/index.js CHANGED
@@ -198,6 +198,25 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
198
198
  ...vitrifyConfig.vitrify.ssr.serverModules
199
199
  ];
200
200
  const plugins = [
201
+ {
202
+ name: 'vitrify-transforms',
203
+ enforce: 'pre',
204
+ transform: (code, id) => {
205
+ if (['main.ts', 'vitrify'].every((val) => id.includes(val))) {
206
+ code =
207
+ `${globalCss.map((css) => `import '${css}'`).join('\n')}\n` + code;
208
+ }
209
+ if (['RootComponent.vue', 'vitrify'].every((val) => id.includes(val))) {
210
+ const sass = [
211
+ ...Object.entries(sassVariables).map(([key, value]) => `${key}: ${value}`),
212
+ ...globalSass.map((sass) => `@import '${sass}'`)
213
+ ].join('\n');
214
+ code = code.replace(/<style lang="sass">(.*?)<\/style>/, '<style lang="sass">' + sass + '</style>');
215
+ // code = code.replace(/<\/style>/, sass + '</style>')
216
+ }
217
+ return code;
218
+ }
219
+ },
201
220
  vuePlugin(),
202
221
  envPlugin(),
203
222
  ...frameworkPlugins,
@@ -233,13 +252,24 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
233
252
  return { id };
234
253
  return;
235
254
  },
236
- transform: (code, id) => {
237
- if (id.endsWith('main.ts') && id.includes('vitrify')) {
238
- code =
239
- `${globalCss.map((css) => `import '${css}'`).join('\n')}\n` + code;
240
- }
241
- return code;
242
- },
255
+ // transform: (code, id) => {
256
+ // if (['main.ts', 'vitrify'].every((val) => id.includes(val))) {
257
+ // code =
258
+ // `${globalCss.map((css) => `import '${css}'`).join('\n')}\n` + code
259
+ // }
260
+ // if (['RootComponent.vue', 'vitrify'].every((val) => id.includes(val))) {
261
+ // console.log('lksdflkjsdf')
262
+ // const sass = [
263
+ // ...Object.entries(sassVariables).map(
264
+ // ([key, value]) => `${key}: ${value}`
265
+ // ),
266
+ // ...globalSass.map((sass) => `@import '${sass}'`)
267
+ // ].join('\n')
268
+ // code = code.replace(/<\/style>/, sass + '</style>')
269
+ // console.log(code)
270
+ // }
271
+ // return code
272
+ // },
243
273
  load(id) {
244
274
  if (id === 'virtual:vitrify-hooks') {
245
275
  return `export const onBoot = [${onBootHooks
@@ -1,6 +1,6 @@
1
1
  import type { FastifyPluginCallback, FastifyRequest, FastifyReply } from 'fastify';
2
2
  import type { ViteDevServer } from 'vite';
3
- import type { OnRenderedHook } from 'src/node/vitrify-config.js';
3
+ import type { OnRenderedHook } from '../../vitrify-config.js';
4
4
  export interface FastifySsrOptions {
5
5
  baseUrl?: string;
6
6
  provide?: (req: FastifyRequest, res: FastifyReply) => Promise<Record<string, unknown | {
@@ -3,3 +3,5 @@ export interface Hostname {
3
3
  name: string;
4
4
  }
5
5
  export declare function resolveHostname(optionsHost: string | boolean | undefined): Hostname;
6
+ export declare const appendToHead: (preloadLinks: string, html: string) => string;
7
+ export declare const appendToBody: (links: string, html: string) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitrify",
3
- "version": "0.10.3",
3
+ "version": "0.10.5",
4
4
  "license": "MIT",
5
5
  "author": "Stefan van Herwijnen",
6
6
  "description": "Vite as your Full Stack development tool",
@@ -66,10 +66,11 @@ export async function createVitrifyDevServer({
66
66
  }
67
67
 
68
68
  const wsPort = await getFirstOpenPort(24678)
69
- exitLogs.push(
70
- `[warning] HTTPS mode enabled. Visit https://{hostname}:${wsPort} to enable a security exception for HMR.`
71
- )
72
-
69
+ if (config.server?.https) {
70
+ exitLogs.push(
71
+ `[warning] HTTPS mode enabled. Visit https://{hostname}:${wsPort} to enable a security exception for HMR.`
72
+ )
73
+ }
73
74
  config.server = {
74
75
  https: config.server?.https,
75
76
  hmr: {
@@ -6,8 +6,9 @@ import type {
6
6
  import fastifyStatic from '@fastify/static'
7
7
  import { readFileSync } from 'fs'
8
8
  import { componentsModules, collectCss } from '../../helpers/collect-css-ssr.js'
9
+ import { appendToHead } from '../../helpers/utils.js'
9
10
  import type { ViteDevServer } from 'vite'
10
- import type { OnRenderedHook } from 'src/node/vitrify-config.js'
11
+ import type { OnRenderedHook } from '../../vitrify-config.js'
11
12
  export interface FastifySsrOptions {
12
13
  baseUrl?: string
13
14
  provide?: (
@@ -139,7 +140,6 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
139
140
  ssrContext.initialState.provide = provide
140
141
 
141
142
  let html = template
142
- .replace(`<!--preload-links-->`, preloadLinks)
143
143
  .replace(`<!--app-html-->`, appHtml)
144
144
  .replace('<!--product-name-->', options.productName || 'Product name')
145
145
  .replace('<!--dev-ssr-css-->', css)
@@ -150,6 +150,8 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
150
150
  </script>`
151
151
  )
152
152
 
153
+ html = appendToHead(preloadLinks, html)
154
+
153
155
  if (options.onRendered?.length) {
154
156
  for (const ssrFunction of options.onRendered) {
155
157
  html = ssrFunction(html, ssrContext)
@@ -204,15 +206,14 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
204
206
  if (!ssrContext.initialState) ssrContext.initialState = {}
205
207
  ssrContext.initialState.provide = provide
206
208
 
207
- let html = template
208
- .replace(`<!--preload-links-->`, preloadLinks)
209
- .replace(`<!--app-html-->`, appHtml)
210
- .replace(
211
- '<!--initial-state-->',
212
- `<script>
209
+ let html = template.replace(`<!--app-html-->`, appHtml).replace(
210
+ '<!--initial-state-->',
211
+ `<script>
213
212
  __INITIAL_STATE__ = '${JSON.stringify(ssrContext.initialState)}'
214
213
  </script>`
215
- )
214
+ )
215
+
216
+ html = appendToHead(preloadLinks, html)
216
217
 
217
218
  if (options.onRendered?.length) {
218
219
  for (const ssrFunction of options.onRendered) {
@@ -1,6 +1,7 @@
1
1
  import { promises as fs } from 'fs'
2
2
  import type { OnRenderedHook } from 'src/node/vitrify-config.js'
3
3
  import { routesToPaths } from '../../helpers/routes.js'
4
+ import { appendToHead, appendToBody } from '../../helpers/utils.js'
4
5
 
5
6
  export const prerender = async ({
6
7
  outDir,
@@ -17,7 +18,7 @@ export const prerender = async ({
17
18
  }) => {
18
19
  const promises = []
19
20
  const template = (await fs.readFile(templatePath)).toString()
20
- const manifest = await fs.readFile(manifestPath)
21
+ const manifest = JSON.parse((await fs.readFile(manifestPath)).toString())
21
22
  const { render, getRoutes } = await import(entryServerPath)
22
23
  const routes = await getRoutes()
23
24
  const paths = routesToPaths(routes).filter(
@@ -28,8 +29,7 @@ export const prerender = async ({
28
29
  logLevel: 'warn',
29
30
  external: true,
30
31
  inlineFonts: true,
31
- preloadFonts: true,
32
- preload: 'swap'
32
+ preloadFonts: true
33
33
  })
34
34
  for (const url of paths) {
35
35
  const filename =
@@ -41,9 +41,10 @@ export const prerender = async ({
41
41
  }
42
42
  const [appHtml, preloadLinks] = await render(url, manifest, ssrContext)
43
43
 
44
- let html = template
45
- .replace(`<!--preload-links-->`, preloadLinks)
46
- .replace(`<!--app-html-->`, appHtml)
44
+ let html = template.replace(`<!--app-html-->`, appHtml)
45
+
46
+ html = appendToHead(preloadLinks, html)
47
+ // html = appendToBody(preloadLinks, html)
47
48
 
48
49
  if (onRendered?.length) {
49
50
  for (const ssrFunction of onRendered) {
@@ -35,3 +35,9 @@ export function resolveHostname(
35
35
 
36
36
  return { host, name }
37
37
  }
38
+
39
+ export const appendToHead = (preloadLinks: string, html: string) =>
40
+ html.replace(/<\/head>/, preloadLinks + '</head>')
41
+
42
+ export const appendToBody = (links: string, html: string) =>
43
+ html.replace(/<\/body>/, links + '</body>')
package/src/node/index.ts CHANGED
@@ -270,6 +270,30 @@ export const baseConfig = async ({
270
270
  ]
271
271
 
272
272
  const plugins: UserConfig['plugins'] = [
273
+ {
274
+ name: 'vitrify-transforms',
275
+ enforce: 'pre',
276
+ transform: (code, id) => {
277
+ if (['main.ts', 'vitrify'].every((val) => id.includes(val))) {
278
+ code =
279
+ `${globalCss.map((css) => `import '${css}'`).join('\n')}\n` + code
280
+ }
281
+ if (['RootComponent.vue', 'vitrify'].every((val) => id.includes(val))) {
282
+ const sass = [
283
+ ...Object.entries(sassVariables).map(
284
+ ([key, value]) => `${key}: ${value}`
285
+ ),
286
+ ...globalSass.map((sass) => `@import '${sass}'`)
287
+ ].join('\n')
288
+ code = code.replace(
289
+ /<style lang="sass">(.*?)<\/style>/,
290
+ '<style lang="sass">' + sass + '</style>'
291
+ )
292
+ // code = code.replace(/<\/style>/, sass + '</style>')
293
+ }
294
+ return code
295
+ }
296
+ },
273
297
  vuePlugin(),
274
298
  envPlugin(),
275
299
  ...frameworkPlugins,
@@ -303,13 +327,24 @@ export const baseConfig = async ({
303
327
  if (VIRTUAL_MODULES.includes(id)) return { id }
304
328
  return
305
329
  },
306
- transform: (code, id) => {
307
- if (id.endsWith('main.ts') && id.includes('vitrify')) {
308
- code =
309
- `${globalCss.map((css) => `import '${css}'`).join('\n')}\n` + code
310
- }
311
- return code
312
- },
330
+ // transform: (code, id) => {
331
+ // if (['main.ts', 'vitrify'].every((val) => id.includes(val))) {
332
+ // code =
333
+ // `${globalCss.map((css) => `import '${css}'`).join('\n')}\n` + code
334
+ // }
335
+ // if (['RootComponent.vue', 'vitrify'].every((val) => id.includes(val))) {
336
+ // console.log('lksdflkjsdf')
337
+ // const sass = [
338
+ // ...Object.entries(sassVariables).map(
339
+ // ([key, value]) => `${key}: ${value}`
340
+ // ),
341
+ // ...globalSass.map((sass) => `@import '${sass}'`)
342
+ // ].join('\n')
343
+ // code = code.replace(/<\/style>/, sass + '</style>')
344
+ // console.log(code)
345
+ // }
346
+ // return code
347
+ // },
313
348
  load(id) {
314
349
  if (id === 'virtual:vitrify-hooks') {
315
350
  return `export const onBoot = [${onBootHooks
@@ -0,0 +1,27 @@
1
+ <template>
2
+ <render></render>
3
+ </template>
4
+ <script setup lang="ts">
5
+ import {
6
+ defineProps,
7
+ h,
8
+ onMounted as onMountedVue,
9
+ getCurrentInstance
10
+ } from 'vue'
11
+ import { onBoot, onMounted } from 'virtual:vitrify-hooks'
12
+ import * as staticImports from 'virtual:static-imports'
13
+ import App from 'src/App.vue'
14
+ // import 'vitrify.sass'
15
+ const instance = getCurrentInstance()
16
+ const props = defineProps()
17
+
18
+ onMountedVue(async () => {
19
+ for (let fn of onMounted) {
20
+ await fn(instance, staticImports)
21
+ }
22
+ })
23
+
24
+ const render = () => h(App, props)
25
+ </script>
26
+
27
+ <style lang="sass"></style>
@@ -1,4 +1,4 @@
1
- import 'vitrify.sass'
1
+ // import 'vitrify.sass'
2
2
  import createRouter from 'src/router'
3
3
  import {
4
4
  createSSRApp,
@@ -12,7 +12,7 @@ import { onBoot, onMounted } from 'virtual:vitrify-hooks'
12
12
  import routes from 'src/router/routes'
13
13
  import * as staticImports from 'virtual:static-imports'
14
14
  import App from 'src/App.vue'
15
-
15
+ import RootComponent from './RootComponent.vue'
16
16
  interface ssrContext {
17
17
  ssr: boolean
18
18
  provide?: Record<string, unknown>
@@ -28,20 +28,20 @@ export async function createApp(
28
28
  ssrContext?: ssrContext
29
29
  ) {
30
30
  let app
31
- const RootComponent = {
32
- name: 'AppWrapper',
33
- setup(props) {
34
- const instance = getCurrentInstance()
31
+ // const RootComponent = {
32
+ // name: 'AppWrapper',
33
+ // setup(props) {
34
+ // const instance = getCurrentInstance()
35
35
 
36
- onMountedVue(async () => {
37
- for (let fn of onMounted) {
38
- await fn(instance, staticImports)
39
- }
40
- })
36
+ // onMountedVue(async () => {
37
+ // for (let fn of onMounted) {
38
+ // await fn(instance, staticImports)
39
+ // }
40
+ // })
41
41
 
42
- return () => h(App, props)
43
- }
44
- }
42
+ // return () => h(App, props)
43
+ // }
44
+ // }
45
45
  if (ssr) {
46
46
  app = createSSRApp(RootComponent)
47
47
  } else {