vitrify 0.6.17 → 0.7.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitrify",
3
- "version": "0.6.17",
3
+ "version": "0.7.1",
4
4
  "license": "MIT",
5
5
  "author": "Stefan van Herwijnen",
6
6
  "description": "Pre-configured Vite CLI for your framework",
@@ -57,47 +57,47 @@
57
57
  },
58
58
  "dependencies": {
59
59
  "@fastify/middie": "^8.0.0",
60
- "@fastify/static": "^6.4.0",
61
- "@quasar/extras": "^1.14.2",
62
- "@vitejs/plugin-vue": "^3.0.0-alpha.1",
60
+ "@fastify/static": "^6.5.0",
61
+ "@quasar/extras": "^1.15.1",
62
+ "@vitejs/plugin-vue": "^3.0.1",
63
63
  "builtin-modules": "^3.3.0",
64
64
  "cac": "^6.7.12",
65
65
  "chalk": "^5.0.1",
66
66
  "critters": "^0.0.16",
67
67
  "cross-env": "^7.0.3",
68
- "esbuild": "^0.14.48",
69
- "fastify": "^4.2.0",
68
+ "esbuild": "^0.14.53",
69
+ "fastify": "^4.3.0",
70
70
  "glob": "^8.0.3",
71
- "happy-dom": "^6.0.0",
71
+ "happy-dom": "^6.0.4",
72
72
  "magic-string": "^0.26.2",
73
73
  "merge-deep": "^3.0.3",
74
74
  "readline": "^1.3.0",
75
- "rollup-plugin-visualizer": "^5.6.0",
76
- "sass": "1.53.0",
77
- "ts-node": "^10.8.2",
78
- "unplugin-vue-components": "^0.21.0",
79
- "vite": "3.0.0-beta.6",
80
- "vitest": "^0.17.0"
75
+ "rollup-plugin-visualizer": "^5.7.1",
76
+ "sass": "1.54.2",
77
+ "ts-node": "^10.9.1",
78
+ "unplugin-vue-components": "^0.22.0",
79
+ "vite": "^3.0.4",
80
+ "vitest": "^0.20.3"
81
81
  },
82
82
  "devDependencies": {
83
83
  "@types/connect": "^3.4.35",
84
84
  "@types/glob": "^7.2.0",
85
85
  "@types/merge-deep": "^3.0.0",
86
- "@types/node": "^18.0.1",
86
+ "@types/node": "^18.6.3",
87
87
  "@types/ws": "^8.5.3",
88
88
  "@vue/runtime-core": "^3.2.37",
89
- "quasar": "^2.7.5",
90
- "rollup": "^2.75.7",
89
+ "quasar": "^2.7.7",
90
+ "rollup": "^2.77.2",
91
91
  "typescript": "^4.7.4",
92
92
  "vue": "^3.2.37",
93
- "vue-router": "^4.1.0"
93
+ "vue-router": "^4.1.3"
94
94
  },
95
95
  "peerDependencies": {
96
- "@fastify/static": "^6.4.0",
97
- "fastify": "^4.2.0",
98
- "quasar": "^2.7.5",
96
+ "@fastify/static": "^6.5.0",
97
+ "fastify": "^4.3.0",
98
+ "quasar": "^2.7.7",
99
99
  "vue": "^3.2.37",
100
- "vue-router": "^4.1.0"
100
+ "vue-router": "^4.1.3"
101
101
  },
102
102
  "publishConfig": {
103
103
  "access": "public",
@@ -88,7 +88,7 @@ cli
88
88
  ;({ prerender, onRendered } = await import(
89
89
  new URL('ssr/server/prerender.mjs', baseOutDir).pathname
90
90
  ))
91
- console.log(onRendered)
91
+
92
92
  prerender({
93
93
  outDir: new URL('static/', baseOutDir).pathname,
94
94
  templatePath: new URL('static/index.html', baseOutDir).pathname,
@@ -1,13 +1,11 @@
1
1
  import type { LogLevel, InlineConfig } from 'vite'
2
- import { ViteDevServer, mergeConfig } from 'vite'
3
2
  import { searchForWorkspaceRoot } from 'vite'
4
3
  import { baseConfig } from '../index.js'
5
4
  import type { Server } from 'net'
6
- import type { FastifyInstance } from 'fastify/types/instance'
7
5
  import fastify from 'fastify'
6
+ import type { FastifyServerOptions } from 'fastify'
8
7
  import { fastifySsrPlugin } from '../frameworks/vue/fastify-ssr-plugin.js'
9
- import type { ServerOptions } from 'https'
10
- import type { OnRenderedHook } from '../vitrify-config.js'
8
+ import type { OnRenderedHook, VitrifyConfig } from '../vitrify-config.js'
11
9
 
12
10
  export async function createVitrifyDevServer({
13
11
  port = 3000,
@@ -130,6 +128,7 @@ export async function createServer({
130
128
  let setup
131
129
  let server: Server
132
130
  let onRendered: OnRenderedHook[]
131
+ let vitrifyConfig: VitrifyConfig
133
132
 
134
133
  console.log(`Development mode: ${ssr ? ssr : 'csr'}`)
135
134
  if (ssr) {
@@ -138,11 +137,12 @@ export async function createServer({
138
137
  ? new URL('src/vite/fastify/entry.ts', cliDir).pathname
139
138
  : new URL(`src/vite/${framework}/ssr/app.ts`, cliDir).pathname
140
139
 
141
- ;({ setup, onRendered } = await vite.ssrLoadModule(entryUrl))
140
+ ;({ setup, onRendered, vitrifyConfig } = await vite.ssrLoadModule(entryUrl))
142
141
  const app = fastify({
143
142
  logger: false,
144
- https: vite.config.server.https as ServerOptions
145
- })
143
+ https: vite.config.server.https,
144
+ ...vitrifyConfig.vitrify?.ssr?.fastify
145
+ } as FastifyServerOptions)
146
146
  if (process.env) process.env.MODE = 'development'
147
147
  if (setup) {
148
148
  await setup({
@@ -15,7 +15,7 @@ export const createApp = ({
15
15
  vitrifyDir,
16
16
  mode
17
17
  }: {
18
- onSetup: OnSetupFile[]
18
+ onSetup: ((fastify: FastifyInstance) => void)[]
19
19
  appDir: URL
20
20
  baseUrl?: string
21
21
  fastifyPlugin: FastifySsrPlugin | FastifyCsrPlugin
@@ -35,11 +35,11 @@ export const createApp = ({
35
35
  mode
36
36
  })
37
37
 
38
- // if (onSetup?.length) {
39
- // for (const setup of onSetup) {
40
- // setup(app)
41
- // }
42
- // }
38
+ if (onSetup?.length) {
39
+ for (const setup of onSetup) {
40
+ setup(app)
41
+ }
42
+ }
43
43
 
44
44
  return app
45
45
  }
package/src/node/index.ts CHANGED
@@ -21,7 +21,7 @@ import type {
21
21
  } from './vitrify-config.js'
22
22
  import type { VitrifyContext } from './bin/run.js'
23
23
  import type { VitrifyPlugin } from './plugins/index.js'
24
- import { getPkgJsonDir, resolve } from './app-urls.js'
24
+ import { resolve } from './app-urls.js'
25
25
  import type { ManualChunksOption, RollupOptions } from 'rollup'
26
26
 
27
27
  const internalServerModules = [
@@ -75,8 +75,8 @@ const manualChunks: ManualChunksOption = (id: string) => {
75
75
 
76
76
  export const VIRTUAL_MODULES = [
77
77
  'virtual:vitrify-hooks',
78
- 'virtual:global-css',
79
78
  'virtual:static-imports',
79
+ 'virtual:vitrify-config',
80
80
  'vitrify.sass',
81
81
  'vitrify.css'
82
82
  ]
@@ -237,13 +237,6 @@ export const baseConfig = async ({
237
237
  console.error('package.json not found')
238
238
  }
239
239
 
240
- const ssrTransformCustomDir = () => {
241
- return {
242
- props: [],
243
- needRuntime: true
244
- }
245
- }
246
-
247
240
  const frameworkPlugins = []
248
241
  for (const framework of Object.keys(configPluginMap)) {
249
242
  if (Object.keys(vitrifyConfig).includes(framework)) {
@@ -261,7 +254,7 @@ export const baseConfig = async ({
261
254
  let onRenderedHooks: OnRenderedHook[]
262
255
  let onMountedHooks: OnMountedHook[]
263
256
  let onSetupFiles: OnSetupFile[]
264
- let globalCss: string[]
257
+ let globalCss: string[] = []
265
258
  let staticImports: StaticImports
266
259
  let sassVariables: Record<string, string>
267
260
  let additionalData: string[]
@@ -275,32 +268,12 @@ export const baseConfig = async ({
275
268
  ]
276
269
 
277
270
  const plugins: UserConfig['plugins'] = [
278
- vuePlugin({
279
- // compiler: await import('vue/compiler-sfc'),
280
- // template: {
281
- // ssr: !!ssr,
282
- // compilerOptions: {
283
- // directiveTransforms: {
284
- // 'close-popup': ssrTransformCustomDir,
285
- // intersection: ssrTransformCustomDir,
286
- // ripple: ssrTransformCustomDir,
287
- // mutation: ssrTransformCustomDir,
288
- // morph: ssrTransformCustomDir,
289
- // scroll: ssrTransformCustomDir,
290
- // 'scroll-fire': ssrTransformCustomDir,
291
- // 'touch-hold': ssrTransformCustomDir,
292
- // 'touch-pan': ssrTransformCustomDir,
293
- // 'touch-repeat': ssrTransformCustomDir,
294
- // 'touch-swipe': ssrTransformCustomDir
295
- // }
296
- // }
297
- // }
298
- }),
271
+ vuePlugin(),
299
272
  ...frameworkPlugins,
300
273
  {
301
274
  name: 'vitrify-setup',
302
275
  enforce: 'post',
303
- config: async (config: VitrifyConfig, env) => {
276
+ config: (config: VitrifyConfig, env) => {
304
277
  onBootHooks = config.vitrify?.hooks?.onBoot || []
305
278
  onRenderedHooks = config.vitrify?.hooks?.onRendered || []
306
279
  onMountedHooks = config.vitrify?.hooks?.onMounted || []
@@ -310,27 +283,17 @@ export const baseConfig = async ({
310
283
  sassVariables = config.vitrify?.sass?.variables || {}
311
284
  globalSass = config.vitrify?.sass?.global || []
312
285
  additionalData = config.vitrify?.sass?.additionalData || []
313
-
314
- return {
315
- css: {
316
- preprocessorOptions: {
317
- // sass: {
318
- // additionalData: [
319
- // ...Object.entries(sassVariables).map(
320
- // ([key, value]) => `${key}: ${value}`
321
- // )
322
- // // ...additionalData
323
- // // config.css?.preprocessorOptions?.sass.additionalData
324
- // ].join('\n')
325
- // }
326
- }
327
- }
328
- }
286
+ return
287
+ },
288
+ configureServer(server) {
289
+ server.middlewares.use('/', (req, res, next) => {
290
+ if (req.url?.endsWith('.html')) req.url = req.url.replace('.html', '')
291
+ next()
292
+ })
329
293
  },
330
294
  configResolved: (config) => {
331
295
  if (process.env.DEBUG) {
332
- console.log(config.css?.preprocessorOptions?.sass.additionalData)
333
- console.log(config.optimizeDeps)
296
+ console.log(config)
334
297
  }
335
298
  },
336
299
  resolveId(id) {
@@ -357,30 +320,20 @@ export const baseConfig = async ({
357
320
  .join(', ')}]
358
321
  export const onSetup = []
359
322
  ${onSetupFiles
360
- .map(
361
- (url, index) =>
362
- `import ${url.pathname
363
- .replaceAll('/', '')
364
- .replaceAll('.', '')} from '${
365
- url.pathname
366
- }'; onSetup.push(${url.pathname
367
- .replaceAll('/', '')
368
- .replaceAll('.', '')})`
369
- )
323
+ .map((url, index) => {
324
+ const varName = url.pathname
325
+ .replaceAll('/', '')
326
+ .replaceAll('.', '')
327
+ .replaceAll('-', '')
328
+ return `import ${varName} from '${url.pathname}'; onSetup.push(${varName})`
329
+ })
370
330
  .join('\n')}`
371
- // export const onSetup = [${onSetupHooks
372
- // .map((fn) => `${String(fn)}`)
373
- // .join(', ')}]`
374
- /**
375
- * CSS imports in virtual files do not seem to work. Using transform() instead
376
- */
377
- // } else if (id === 'virtual:global-css') {
378
- // return `${globalCss.map((css) => `import '${css}'`).join('\n')}`
379
331
  } else if (id === 'virtual:static-imports') {
380
332
  return `${Object.entries(staticImports)
381
- .map(
382
- ([key, value]) => `export { ${value.join(',')} } from '${key}';`
383
- )
333
+ .map(([key, value]) => {
334
+ const deduped = [...new Set(value)]
335
+ return `export { ${deduped.join(',')} } from '${key}';`
336
+ })
384
337
  .join('\n')}`
385
338
  } else if (id === 'vitrify.sass') {
386
339
  return [
@@ -390,7 +343,9 @@ export const baseConfig = async ({
390
343
  ...globalSass.map((sass) => `@import '${sass}'`)
391
344
  ].join('\n')
392
345
  } else if (id === 'vitrify.css') {
393
- return `${globalCss.map((css) => `import '${css}'`).join('\n')}`
346
+ return `${globalCss.map((css) => `@import '${css}'`).join('\n')}`
347
+ } else if (id === 'virtual:vitrify-config') {
348
+ return `export default ${JSON.stringify(vitrifyConfig)}`
394
349
  }
395
350
  return null
396
351
  }
@@ -400,16 +355,16 @@ export const baseConfig = async ({
400
355
  plugins.unshift({
401
356
  name: 'html-transform',
402
357
  enforce: 'pre',
403
- transform: (code, id) => {
404
- if (id.endsWith('App.vue')) {
405
- code =
406
- code +
407
- `<style lang="sass">
408
- // do not remove, required for additionalData import
409
- </style>`
410
- }
411
- return code
412
- },
358
+ // transform: (code, id) => {
359
+ // if (id.endsWith('App.vue')) {
360
+ // code =
361
+ // code +
362
+ // `<style lang="sass">
363
+ // // do not remove, required for additionalData import
364
+ // </style>`
365
+ // }
366
+ // return code
367
+ // },
413
368
  transformIndexHtml: {
414
369
  enforce: 'pre',
415
370
  transform: (html) => {
@@ -441,6 +396,7 @@ export const baseConfig = async ({
441
396
  config: (config: VitrifyConfig, env) => {
442
397
  if (config.vitrify?.productName)
443
398
  productName = config.vitrify?.productName
399
+ return
444
400
  },
445
401
  transformIndexHtml: {
446
402
  enforce: 'post',
@@ -471,10 +427,6 @@ export const baseConfig = async ({
471
427
  packageUrls['vue']
472
428
  ).pathname
473
429
  },
474
- // {
475
- // find: new RegExp('^vue/server-renderer$'),
476
- // replacement: 'vue/server-renderer/index.mjs'
477
- // },
478
430
  {
479
431
  find: new RegExp('^vue-router$'),
480
432
  replacement: new URL(
@@ -482,9 +434,6 @@ export const baseConfig = async ({
482
434
  packageUrls['vue-router']
483
435
  ).pathname
484
436
  }
485
- // { find: 'vue', replacement: packageUrls['vue'].pathname },
486
- // { find: 'vue-router', replacement: packageUrls['vue-router'].pathname },
487
- // { find: 'vitrify', replacement: cliDir.pathname }
488
437
  ]
489
438
  if (mode === 'development' && vitrifyConfig.vitrify?.dev?.alias)
490
439
  alias.push(...vitrifyConfig.vitrify.dev.alias)
@@ -511,25 +460,16 @@ export const baseConfig = async ({
511
460
  ],
512
461
  external,
513
462
  output: {
514
- minifyInternalExports: !debug,
463
+ minifyInternalExports: false,
515
464
  entryFileNames: '[name].mjs',
516
465
  chunkFileNames: '[name].mjs',
517
466
  format: 'es',
518
467
  manualChunks
519
- // manualChunks: (id) => {
520
- // if (id.includes('vitrify/src/vite/')) {
521
- // const name = id.split('/').at(-1)?.split('.').at(0)
522
- // if (name && manualChunks.includes(name)) return name
523
- // } else if (id.includes('node_modules')) {
524
- // return 'vendor'
525
- // }
526
- // }
527
468
  }
528
469
  }
529
470
  // Create a SSR bundle
530
471
  noExternal = [
531
472
  new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
532
- // new RegExp(`^(?!.*(${[...builtinModules, ...serverModules].join('|')}))`)
533
473
  ]
534
474
  } else if (ssr === 'fastify') {
535
475
  rollupOptions = {
@@ -542,14 +482,6 @@ export const baseConfig = async ({
542
482
  chunkFileNames: '[name].mjs',
543
483
  format: 'es',
544
484
  manualChunks
545
- // manualChunks: (id) => {
546
- // if (id.includes('vitrify/src/vite/')) {
547
- // const name = id.split('/').at(-1)?.split('.').at(0)
548
- // if (name && manualChunks.includes(name)) return name
549
- // } else if (id.includes('node_modules')) {
550
- // return 'vendor'
551
- // }
552
- // }
553
485
  }
554
486
  }
555
487
  // Create a SSR bundle
@@ -559,13 +491,9 @@ export const baseConfig = async ({
559
491
  } else {
560
492
  rollupOptions = {
561
493
  ...rollupOptions,
562
- // input: [
563
- // new URL('index.html', frameworkDir).pathname
564
- // // new URL('csr/server.ts', frameworkDir).pathname
565
- // ],
566
494
  external,
567
495
  output: {
568
- minifyInternalExports: !debug,
496
+ minifyInternalExports: false,
569
497
  entryFileNames: '[name].mjs',
570
498
  chunkFileNames: '[name].mjs',
571
499
  format: 'es',
@@ -575,7 +503,6 @@ export const baseConfig = async ({
575
503
  }
576
504
 
577
505
  const config = {
578
- // root: ssr === 'fastify' ? appDir.pathname : frameworkDir.pathname,
579
506
  root: appDir.pathname,
580
507
  publicDir: publicDir.pathname,
581
508
  base,
@@ -603,33 +530,6 @@ export const baseConfig = async ({
603
530
  ssr: ssr === 'server' || ssr === 'fastify' ? true : false,
604
531
  ssrManifest: ssr === 'client' || ssr === 'ssg',
605
532
  rollupOptions
606
- // ssr === 'server'
607
- // ? {
608
- // input: [
609
- // new URL('ssr/entry-server.ts', frameworkDir).pathname,
610
- // new URL('ssr/prerender.ts', frameworkDir).pathname,
611
- // new URL('ssr/server.ts', frameworkDir).pathname
612
- // ],
613
- // output: {
614
- // minifyInternalExports: false,
615
- // entryFileNames: '[name].mjs',
616
- // chunkFileNames: '[name].mjs',
617
- // format: 'es',
618
- // manualChunks: (id) => {
619
- // if (id.includes('vitrify/src/vite/')) {
620
- // const name = id.split('/').at(-1)?.split('.').at(0)
621
- // if (name && manualChunks.includes(name)) return name
622
- // } else if (id.includes('node_modules')) {
623
- // return 'vendor'
624
- // }
625
- // }
626
- // }
627
- // }
628
- // : {
629
- // output: {
630
- // format: 'es'
631
- // }
632
- // }
633
533
  },
634
534
  ssr: {
635
535
  // Create a SSR bundle