vitrify 0.10.4 → 0.10.6

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,6 @@
1
1
  import fastifyStatic from '@fastify/static';
2
2
  import { readFileSync } from 'fs';
3
- import { componentsModules, collectCss } from '../../helpers/collect-css-ssr.js';
3
+ import { appendToHead } from '../../helpers/utils.js';
4
4
  const fastifySsrPlugin = async (fastify, options, done) => {
5
5
  options.baseUrl = options.baseUrl || '/';
6
6
  options.mode = options.mode || process.env.MODE || import.meta.env.MODE;
@@ -83,26 +83,23 @@ const fastifySsrPlugin = async (fastify, options, done) => {
83
83
  catch (e) {
84
84
  manifest = {};
85
85
  }
86
- const cssModules = [entryUrl];
87
- // // @ts-ignore
88
- // if (options.vite?.config.vitrify!.globalCss)
89
- // cssModules.push(...options.vite?.config.vitrify.globalCss)
90
- const matchedModules = componentsModules(cssModules, vite);
91
- const css = collectCss({
92
- mods: matchedModules
93
- });
86
+ // const cssModules = [entryUrl]
87
+ // const matchedModules = componentsModules(cssModules, vite!)
88
+ // const css = collectCss({
89
+ // mods: matchedModules
90
+ // })
94
91
  const [appHtml, preloadLinks] = await render(url, manifest, ssrContext);
95
92
  if (!ssrContext.initialState)
96
93
  ssrContext.initialState = {};
97
94
  ssrContext.initialState.provide = provide;
98
95
  let html = template
99
- .replace(`<!--preload-links-->`, preloadLinks)
100
96
  .replace(`<!--app-html-->`, appHtml)
101
97
  .replace('<!--product-name-->', options.productName || 'Product name')
102
- .replace('<!--dev-ssr-css-->', css)
98
+ // .replace('<!--dev-ssr-css-->', css)
103
99
  .replace('<!--initial-state-->', `<script>
104
100
  __INITIAL_STATE__ = '${JSON.stringify(ssrContext.initialState)}'
105
101
  </script>`);
102
+ html = appendToHead(preloadLinks, html);
106
103
  if (options.onRendered?.length) {
107
104
  for (const ssrFunction of options.onRendered) {
108
105
  html = ssrFunction(html, ssrContext);
@@ -144,12 +141,10 @@ const fastifySsrPlugin = async (fastify, options, done) => {
144
141
  if (!ssrContext.initialState)
145
142
  ssrContext.initialState = {};
146
143
  ssrContext.initialState.provide = provide;
147
- let html = template
148
- .replace(`<!--preload-links-->`, preloadLinks)
149
- .replace(`<!--app-html-->`, appHtml)
150
- .replace('<!--initial-state-->', `<script>
144
+ let html = template.replace(`<!--app-html-->`, appHtml).replace('<!--initial-state-->', `<script>
151
145
  __INITIAL_STATE__ = '${JSON.stringify(ssrContext.initialState)}'
152
146
  </script>`);
147
+ html = appendToHead(preloadLinks, html);
153
148
  if (options.onRendered?.length) {
154
149
  for (const ssrFunction of options.onRendered) {
155
150
  html = ssrFunction(html, ssrContext);
@@ -1,5 +1,6 @@
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();
@@ -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,30 @@ 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 css = `${globalCss
211
+ .map((css) => `@import '${css}';`)
212
+ .join('\n')}\n`;
213
+ const sass = [
214
+ ...Object.entries(sassVariables).map(([key, value]) => `${key}: ${value}`),
215
+ ...globalSass.map((sass) => `@import '${sass}'`)
216
+ ].join('\n');
217
+ code = code
218
+ .replace(/<style>(.*?)<\/style>/, '<style>' + css + '</style>')
219
+ .replace(/<style lang="sass">(.*?)<\/style>/, '<style lang="sass">' + sass + '</style>');
220
+ // code = code.replace(/<\/style>/, sass + '</style>')
221
+ }
222
+ return code;
223
+ }
224
+ },
201
225
  vuePlugin(),
202
226
  envPlugin(),
203
227
  ...frameworkPlugins,
@@ -233,13 +257,24 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
233
257
  return { id };
234
258
  return;
235
259
  },
236
- transform: (code, id) => {
237
- if (id.includes('main.ts') && id.includes('vitrify')) {
238
- code =
239
- `${globalCss.map((css) => `import '${css}'`).join('\n')}\n` + code;
240
- }
241
- return code;
242
- },
260
+ // transform: (code, id) => {
261
+ // if (['main.ts', 'vitrify'].every((val) => id.includes(val))) {
262
+ // code =
263
+ // `${globalCss.map((css) => `import '${css}'`).join('\n')}\n` + code
264
+ // }
265
+ // if (['RootComponent.vue', 'vitrify'].every((val) => id.includes(val))) {
266
+ // console.log('lksdflkjsdf')
267
+ // const sass = [
268
+ // ...Object.entries(sassVariables).map(
269
+ // ([key, value]) => `${key}: ${value}`
270
+ // ),
271
+ // ...globalSass.map((sass) => `@import '${sass}'`)
272
+ // ].join('\n')
273
+ // code = code.replace(/<\/style>/, sass + '</style>')
274
+ // console.log(code)
275
+ // }
276
+ // return code
277
+ // },
243
278
  load(id) {
244
279
  if (id === 'virtual:vitrify-hooks') {
245
280
  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.4",
3
+ "version": "0.10.6",
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?: (
@@ -124,14 +125,11 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
124
125
  manifest = {}
125
126
  }
126
127
 
127
- const cssModules = [entryUrl]
128
- // // @ts-ignore
129
- // if (options.vite?.config.vitrify!.globalCss)
130
- // cssModules.push(...options.vite?.config.vitrify.globalCss)
131
- const matchedModules = componentsModules(cssModules, vite!)
132
- const css = collectCss({
133
- mods: matchedModules
134
- })
128
+ // const cssModules = [entryUrl]
129
+ // const matchedModules = componentsModules(cssModules, vite!)
130
+ // const css = collectCss({
131
+ // mods: matchedModules
132
+ // })
135
133
 
136
134
  const [appHtml, preloadLinks] = await render(url, manifest, ssrContext)
137
135
 
@@ -139,10 +137,9 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
139
137
  ssrContext.initialState.provide = provide
140
138
 
141
139
  let html = template
142
- .replace(`<!--preload-links-->`, preloadLinks)
143
140
  .replace(`<!--app-html-->`, appHtml)
144
141
  .replace('<!--product-name-->', options.productName || 'Product name')
145
- .replace('<!--dev-ssr-css-->', css)
142
+ // .replace('<!--dev-ssr-css-->', css)
146
143
  .replace(
147
144
  '<!--initial-state-->',
148
145
  `<script>
@@ -150,6 +147,8 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
150
147
  </script>`
151
148
  )
152
149
 
150
+ html = appendToHead(preloadLinks, html)
151
+
153
152
  if (options.onRendered?.length) {
154
153
  for (const ssrFunction of options.onRendered) {
155
154
  html = ssrFunction(html, ssrContext)
@@ -204,15 +203,14 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
204
203
  if (!ssrContext.initialState) ssrContext.initialState = {}
205
204
  ssrContext.initialState.provide = provide
206
205
 
207
- let html = template
208
- .replace(`<!--preload-links-->`, preloadLinks)
209
- .replace(`<!--app-html-->`, appHtml)
210
- .replace(
211
- '<!--initial-state-->',
212
- `<script>
206
+ let html = template.replace(`<!--app-html-->`, appHtml).replace(
207
+ '<!--initial-state-->',
208
+ `<script>
213
209
  __INITIAL_STATE__ = '${JSON.stringify(ssrContext.initialState)}'
214
210
  </script>`
215
- )
211
+ )
212
+
213
+ html = appendToHead(preloadLinks, html)
216
214
 
217
215
  if (options.onRendered?.length) {
218
216
  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,
@@ -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,36 @@ 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 css = `${globalCss
283
+ .map((css) => `@import '${css}';`)
284
+ .join('\n')}\n`
285
+
286
+ const sass = [
287
+ ...Object.entries(sassVariables).map(
288
+ ([key, value]) => `${key}: ${value}`
289
+ ),
290
+ ...globalSass.map((sass) => `@import '${sass}'`)
291
+ ].join('\n')
292
+ code = code
293
+ .replace(/<style>(.*?)<\/style>/, '<style>' + css + '</style>')
294
+ .replace(
295
+ /<style lang="sass">(.*?)<\/style>/,
296
+ '<style lang="sass">' + sass + '</style>'
297
+ )
298
+ // code = code.replace(/<\/style>/, sass + '</style>')
299
+ }
300
+ return code
301
+ }
302
+ },
273
303
  vuePlugin(),
274
304
  envPlugin(),
275
305
  ...frameworkPlugins,
@@ -303,13 +333,24 @@ export const baseConfig = async ({
303
333
  if (VIRTUAL_MODULES.includes(id)) return { id }
304
334
  return
305
335
  },
306
- transform: (code, id) => {
307
- if (id.includes('main.ts') && id.includes('vitrify')) {
308
- code =
309
- `${globalCss.map((css) => `import '${css}'`).join('\n')}\n` + code
310
- }
311
- return code
312
- },
336
+ // transform: (code, id) => {
337
+ // if (['main.ts', 'vitrify'].every((val) => id.includes(val))) {
338
+ // code =
339
+ // `${globalCss.map((css) => `import '${css}'`).join('\n')}\n` + code
340
+ // }
341
+ // if (['RootComponent.vue', 'vitrify'].every((val) => id.includes(val))) {
342
+ // console.log('lksdflkjsdf')
343
+ // const sass = [
344
+ // ...Object.entries(sassVariables).map(
345
+ // ([key, value]) => `${key}: ${value}`
346
+ // ),
347
+ // ...globalSass.map((sass) => `@import '${sass}'`)
348
+ // ].join('\n')
349
+ // code = code.replace(/<\/style>/, sass + '</style>')
350
+ // console.log(code)
351
+ // }
352
+ // return code
353
+ // },
313
354
  load(id) {
314
355
  if (id === 'virtual:vitrify-hooks') {
315
356
  return `export const onBoot = [${onBootHooks
@@ -0,0 +1,28 @@
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></style>
28
+ <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 {