vitrify 0.25.9 → 0.26.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/dist/bin/cli.js CHANGED
@@ -3,8 +3,8 @@ import cac from 'cac';
3
3
  import { fileURLToPath } from 'url';
4
4
  import { getAppDir, parsePath } from '../app-urls.js';
5
5
  import { printHttpServerUrls, exitLogs } from '../helpers/logger.js';
6
- import { build as esbuild } from 'esbuild';
7
- import { readdir } from 'fs/promises';
6
+ import { minify } from 'rolldown/utils';
7
+ import { readdir, readFile, writeFile } from 'fs/promises';
8
8
  import { loadSSRAssets } from '../frameworks/vue/fastify-ssr-plugin.js';
9
9
  const cli = cac('vitrify');
10
10
  cli
@@ -172,21 +172,25 @@ cli.command('run <file>').action(async (file, options) => {
172
172
  await run(fileURLToPath(filePath));
173
173
  });
174
174
  cli.command('minify <dir>').action(async (dir, options) => {
175
- const files = await readdir(fileURLToPath(new URL(dir, `file://${process.cwd()}/`)));
175
+ const baseUrl = new URL(dir, `file://${process.cwd()}/`);
176
+ const files = await readdir(fileURLToPath(baseUrl));
176
177
  let counter = 0;
177
178
  for (const file of files) {
178
179
  if (file.endsWith('.mjs')) {
179
- await esbuild({
180
- absWorkingDir: fileURLToPath(new URL(dir, `file://${process.cwd()}/`)),
181
- entryPoints: [file],
182
- minify: true,
183
- minifyIdentifiers: true,
184
- minifySyntax: true,
185
- minifyWhitespace: true,
186
- outfile: file,
187
- allowOverwrite: true
180
+ const path = fileURLToPath(new URL(`${dir}/${file}`, `file://${process.cwd()}/`));
181
+ const content = await readFile(path, {
182
+ encoding: 'utf-8'
188
183
  });
189
- counter++;
184
+ const output = await minify(path, content, {
185
+ compress: true,
186
+ module: true,
187
+ mangle: true,
188
+ codegen: true
189
+ });
190
+ if (!output.errors.length) {
191
+ await writeFile(path, output.code);
192
+ counter++;
193
+ }
190
194
  }
191
195
  }
192
196
  console.log(`Minified ${counter} files`);
package/dist/bin/dev.js CHANGED
@@ -98,7 +98,11 @@ ssr, framework = 'vue', host, appDir, publicDir, vite }) {
98
98
  ? fileURLToPath(new URL('src/vite/fastify/entry.ts', cliDir))
99
99
  : fileURLToPath(new URL(`src/vite/${framework}/ssr/app.ts`, cliDir));
100
100
  const environment = vite.environments.ssr;
101
- ({ setup, onTemplateRendered, onAppRendered, vitrifyConfig } =
101
+ ({
102
+ setup,
103
+ hooks: { onTemplateRendered, onAppRendered },
104
+ vitrifyConfig
105
+ } =
102
106
  // @ts-expect-error missing types
103
107
  await environment.runner.import(entryUrl));
104
108
  app = fastify({
@@ -191,7 +191,7 @@ const loadSSRAssets = async ({ mode, distDir } = {
191
191
  const manifest = JSON.parse(readFileSync(manifestPath).toString());
192
192
  const entryServer = await import(entryServerPath);
193
193
  const { render, getRoutes } = entryServer;
194
- const { onTemplateRendered, onAppRendered } = await import(vitrifyHooksPath);
194
+ const { hooks: { onTemplateRendered, onAppRendered } } = await import(vitrifyHooksPath);
195
195
  return {
196
196
  template,
197
197
  manifest,
package/dist/index.js CHANGED
@@ -1,10 +1,8 @@
1
1
  import vuePlugin from '@vitejs/plugin-vue';
2
2
  import { findDepPkgJsonPath } from 'vitefu';
3
3
  import { mergeConfig } from 'vite';
4
- import { build } from 'esbuild';
4
+ import { transform } from 'rolldown/utils';
5
5
  import fs from 'fs';
6
- import path from 'path';
7
- import { pathToFileURL } from 'url';
8
6
  import { readFileSync } from 'fs';
9
7
  import { builtinModules } from 'node:module';
10
8
  import { visualizer } from 'rollup-plugin-visualizer';
@@ -33,8 +31,8 @@ const internalServerModules = [
33
31
  const manualChunkNames = [
34
32
  'prerender',
35
33
  'fastify-ssr-plugin',
36
- 'fastify-csr-plugin',
37
- 'server'
34
+ 'fastify-csr-plugin'
35
+ // 'server'
38
36
  ];
39
37
  const moduleChunks = {
40
38
  vue: [
@@ -55,28 +53,6 @@ const moduleChunks = {
55
53
  quasar: ['quasar'],
56
54
  atQuasar: ['@quasar']
57
55
  };
58
- const manualChunksFn = (manualChunkList) => {
59
- return (id) => {
60
- const matchedModule = Object.entries(moduleChunks).find(([chunkName, moduleNames]) => moduleNames.some((moduleName) => new RegExp(`\/${moduleName}\/`).test(id)));
61
- if (id.includes('vitrify/src/')) {
62
- const name = id.split('/').at(-1)?.split('.').at(0);
63
- if (name && manualChunkNames.includes(name))
64
- return name;
65
- }
66
- else if (VIRTUAL_MODULES.some((virtualModule) => id.includes(virtualModule))) {
67
- return VIRTUAL_MODULES.find((name) => id.includes(name));
68
- }
69
- else if (manualChunkList?.some((file) => id.includes(file))) {
70
- return manualChunkList.find((file) => id.includes(file));
71
- }
72
- else if (id.includes('node_modules')) {
73
- if (matchedModule) {
74
- return matchedModule[0];
75
- }
76
- return 'vendor';
77
- }
78
- };
79
- };
80
56
  export const VIRTUAL_MODULES = [
81
57
  'virtual:vitrify-hooks',
82
58
  'virtual:static-imports',
@@ -84,54 +60,41 @@ export const VIRTUAL_MODULES = [
84
60
  'vitrify.sass',
85
61
  'vitrify.css'
86
62
  ];
87
- async function bundleConfigFile(fileName, isESM = false) {
88
- const result = await build({
89
- absWorkingDir: process.cwd(),
90
- entryPoints: [fileName],
91
- outfile: 'out.js',
92
- write: false,
93
- platform: 'node',
94
- bundle: true,
95
- format: 'esm',
96
- sourcemap: 'inline',
97
- metafile: true,
98
- plugins: [
99
- {
100
- name: 'externalize-deps',
101
- setup(build) {
102
- build.onResolve({ filter: /.*/ }, (args) => {
103
- const id = args.path;
104
- if (id[0] !== '.' && !path.isAbsolute(id)) {
105
- return {
106
- external: true
107
- };
108
- }
109
- });
110
- }
111
- },
112
- {
113
- name: 'replace-import-meta',
114
- setup(build) {
115
- build.onLoad({ filter: /\.[jt]s$/ }, async (args) => {
116
- const contents = await fs.promises.readFile(args.path, 'utf8');
117
- return {
118
- loader: args.path.endsWith('.ts') ? 'ts' : 'js',
119
- contents: contents
120
- .replace(/\bimport\.meta\.url\b/g, JSON.stringify(pathToFileURL(args.path).href))
121
- .replace(/\b__dirname\b/g, JSON.stringify(path.dirname(args.path)))
122
- .replace(/\b__filename\b/g, JSON.stringify(args.path))
123
- };
124
- });
125
- }
126
- }
127
- ]
128
- });
129
- const { text } = result.outputFiles[0];
130
- return {
131
- code: text,
132
- dependencies: result.metafile ? Object.keys(result.metafile.inputs) : []
133
- };
134
- }
63
+ /**
64
+ * Advanced chunking may no longer be necessary.
65
+ * @param ssr
66
+ * @returns
67
+ */
68
+ const createCodeSplittingGroups = (ssr) => {
69
+ return [
70
+ ...VIRTUAL_MODULES.map((m) => ({
71
+ name: m,
72
+ test: new RegExp(m),
73
+ priority: 30
74
+ }))
75
+ // ...manualChunkNames.map((m) => ({
76
+ // name: m,
77
+ // test: new RegExp(m),
78
+ // priority: 20
79
+ // })),
80
+ // ...Object.entries(moduleChunks).map(([key, value]) => ({
81
+ // name: key,
82
+ // test: new RegExp(value.join('|')),
83
+ // priority: 20,
84
+ // maxSize: ssr === 'client' || ssr === 'ssg' ? 1000000 : Infinity
85
+ // })),
86
+ // {
87
+ // name: 'vendor',
88
+ // test: /node_modules/,
89
+ // priority: 1
90
+ // },
91
+ // {
92
+ // name: 'typst',
93
+ // test: /\.typ/,
94
+ // priority: 40
95
+ // }
96
+ ];
97
+ };
135
98
  export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command = 'build', mode = 'production', framework = 'vue', debug = false, productName }) => {
136
99
  const { getAppDir, getCliDir, getCliViteDir, getSrcDir, getCwd } = await import('./app-urls.js');
137
100
  if (!appDir) {
@@ -150,8 +113,11 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
150
113
  try {
151
114
  if (fs.existsSync(fileURLToPath(new URL('vitrify.config.ts', appDir)))) {
152
115
  const configPath = fileURLToPath(new URL('vitrify.config.ts', appDir));
153
- const bundledConfig = await bundleConfigFile(fileURLToPath(new URL('vitrify.config.ts', appDir)));
154
- fs.writeFileSync(configPath + '.js', bundledConfig.code);
116
+ const content = readFileSync(configPath, {
117
+ encoding: 'utf-8'
118
+ });
119
+ const output = await transform(configPath, content);
120
+ fs.writeFileSync(configPath + '.js', output.code);
155
121
  rawVitrifyConfig = (await import('file://' + configPath + '.js')).default;
156
122
  fs.unlinkSync(configPath + '.js');
157
123
  }
@@ -327,7 +293,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
327
293
  },
328
294
  load(id) {
329
295
  if (id === 'virtual:vitrify-hooks') {
330
- return `export const onAppMounted = [${onAppMountedHooks
296
+ return `const onAppMounted = [${onAppMountedHooks
331
297
  .map((fn) => `${String(fn)}`)
332
298
  .join(', ')}]
333
299
  ${onAppMountedFiles
@@ -343,7 +309,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
343
309
  return `import ${varName} from '${new URL(url, appDir).href}'; onAppMounted.push(${varName});`;
344
310
  })
345
311
  .join('\n')}
346
- export const onAppRendered = [${onAppRenderedHooks
312
+ const onAppRendered = [${onAppRenderedHooks
347
313
  .map((fn) => `${String(fn)}`)
348
314
  .join(', ')}]
349
315
  ${onAppRenderedFiles
@@ -359,7 +325,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
359
325
  return `import ${varName} from '${new URL(url, appDir).href}'; onAppRendered.push(${varName});`;
360
326
  })
361
327
  .join('\n')}
362
- export const onTemplateRendered = [${onTemplateRenderedHooks
328
+ const onTemplateRendered = [${onTemplateRenderedHooks
363
329
  .map((fn) => `${String(fn)}`)
364
330
  .join(', ')}]
365
331
  ${onTemplateRenderedFiles
@@ -375,7 +341,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
375
341
  return `import ${varName} from '${new URL(url, appDir).href}'; onTemplateRendered.push(${varName});`;
376
342
  })
377
343
  .join('\n')}
378
- export const onAppCreated = [${OnAppCreatedHooks.map((fn) => `${String(fn)}`).join(', ')}]
344
+ const onAppCreated = [${OnAppCreatedHooks.map((fn) => `${String(fn)}`).join(', ')}]
379
345
  ${onAppCreatedFiles
380
346
  .map((url, index) => {
381
347
  const varName = fileURLToPath(url)
@@ -389,7 +355,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
389
355
  return `import ${varName} from '${new URL(url, appDir).href}'; onAppCreated.push(${varName});`;
390
356
  })
391
357
  .join('\n')}
392
- export const onSetup = []
358
+ const onSetup = []
393
359
  ${onSetupFiles
394
360
  .map((url, index) => {
395
361
  const varName = fileURLToPath(url)
@@ -402,7 +368,14 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
402
368
  .replaceAll('+', '');
403
369
  return `import ${varName} from '${new URL(url, appDir).href}'; onSetup.push(${varName});`;
404
370
  })
405
- .join('\n')}`;
371
+ .join('\n')}
372
+ export const hooks = {
373
+ onAppMounted,
374
+ onAppRendered,
375
+ onAppCreated,
376
+ onTemplateRendered,
377
+ onSetup
378
+ }`;
406
379
  }
407
380
  else if (id === 'virtual:static-imports') {
408
381
  return `${Object.entries(staticImports)
@@ -569,7 +542,9 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
569
542
  entryFileNames: '[name].mjs',
570
543
  chunkFileNames: '[name].mjs',
571
544
  format: 'es',
572
- manualChunks: manualChunksFn(vitrifyConfig?.vitrify?.manualChunks)
545
+ codeSplitting: {
546
+ groups: createCodeSplittingGroups(ssr)
547
+ }
573
548
  }
574
549
  };
575
550
  // Create a SSR bundle
@@ -587,7 +562,9 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
587
562
  entryFileNames: '[name].mjs',
588
563
  chunkFileNames: '[name].mjs',
589
564
  format: 'es',
590
- manualChunks: manualChunksFn(vitrifyConfig?.vitrify?.manualChunks)
565
+ codeSplitting: {
566
+ groups: createCodeSplittingGroups(ssr)
567
+ }
591
568
  }
592
569
  };
593
570
  // Create a SSR bundle
@@ -604,7 +581,9 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
604
581
  entryFileNames: '[name].mjs',
605
582
  chunkFileNames: '[name].mjs',
606
583
  format: 'es',
607
- manualChunks: manualChunksFn(vitrifyConfig?.vitrify?.manualChunks)
584
+ codeSplitting: {
585
+ groups: createCodeSplittingGroups(ssr)
586
+ }
608
587
  }
609
588
  };
610
589
  }
@@ -7,4 +7,4 @@ export declare function build(opts: {
7
7
  publicDir?: URL;
8
8
  debug?: boolean;
9
9
  productName?: string;
10
- }): Promise<import("rollup").RollupOutput | import("rollup").RollupOutput[] | import("rollup").RollupWatcher>;
10
+ }): Promise<import("rolldown").RolldownOutput | import("rolldown").RolldownOutput[] | import("rolldown").RolldownWatcher>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitrify",
3
- "version": "0.25.9",
3
+ "version": "0.26.1",
4
4
  "license": "MIT",
5
5
  "author": "Stefan van Herwijnen",
6
6
  "description": "Vite as your Full Stack development tool",
@@ -52,71 +52,71 @@
52
52
  },
53
53
  "homepage": "https://github.com/simsustech/vitrify/tree/main/#readme",
54
54
  "dependencies": {
55
- "@fastify/middie": "^9.1.0",
55
+ "@fastify/middie": "^9.3.1",
56
56
  "@fastify/one-line-logger": "^2.1.0",
57
57
  "@fastify/static": "^9.0.0",
58
- "@unocss/core": "^66.6.2",
59
- "@unocss/preset-uno": "^66.6.2",
60
- "@unocss/preset-web-fonts": "66.6.2",
61
- "@unocss/preset-wind": "^66.6.2",
62
- "@vitejs/plugin-vue": "^6.0.4",
58
+ "@unocss/core": "^66.6.7",
59
+ "@unocss/preset-uno": "^66.6.7",
60
+ "@unocss/preset-web-fonts": "66.6.7",
61
+ "@unocss/preset-wind": "^66.6.7",
62
+ "@vitejs/plugin-vue": "^6.0.5",
63
63
  "ajv": "^8.18.0",
64
64
  "animated-unocss": "^0.0.6",
65
- "cac": "^6.7.14",
65
+ "cac": "^7.0.0",
66
66
  "chalk": "^5.6.2",
67
67
  "cross-env": "^10.1.0",
68
- "devalue": "^5.6.3",
69
- "esbuild": "^0.27.3",
70
- "fastify": "^5.7.4",
68
+ "devalue": "^5.6.4",
69
+ "fastify": "^5.8.2",
71
70
  "glob": "^13.0.6",
72
- "happy-dom": "^20.7.0",
71
+ "happy-dom": "^20.8.4",
73
72
  "is-port-reachable": "^4.0.0",
74
73
  "magic-string": "^0.30.21",
75
74
  "merge-deep": "^3.0.3",
76
75
  "readline": "^1.3.0",
77
- "rollup-plugin-visualizer": "^7.0.0",
78
- "sass": "1.97.3",
76
+ "rolldown": "1.0.0-rc.9",
77
+ "rollup-plugin-visualizer": "^7.0.1",
78
+ "sass": "1.98.0",
79
79
  "stringify-object": "^6.0.0",
80
80
  "ts-node": "^10.9.2",
81
- "unocss": "^66.6.2",
81
+ "unocss": "^66.6.7",
82
82
  "unplugin-vue-components": "^31.0.0",
83
- "vite": "^7.3.1",
83
+ "vite": "^8.0.0",
84
84
  "vite-plugin-pwa": "^1.2.0",
85
85
  "vitefu": "^1.1.2",
86
- "vitest": "^4.0.18",
86
+ "vitest": "^4.1.0",
87
87
  "workbox-window": "^7.4.0"
88
88
  },
89
89
  "devDependencies": {
90
90
  "@iconify-json/mdi": "^1.2.3",
91
- "@pinia/colada": "^0.21.5",
91
+ "@pinia/colada": "^1.0.0",
92
92
  "@quasar/extras": "^1.17.0",
93
93
  "@quasar/quasar-ui-qmarkdown": "^2.0.5",
94
94
  "@quasar/quasar-ui-qmediaplayer": "^2.0.0-beta.0",
95
95
  "@types/connect": "^3.4.38",
96
96
  "@types/glob": "^9.0.0",
97
97
  "@types/merge-deep": "^3.0.3",
98
- "@types/node": "^25.3.1",
98
+ "@types/node": "^25.5.0",
99
99
  "@types/stringify-object": "^4.0.5",
100
100
  "@types/ws": "^8.18.1",
101
- "@unocss/preset-icons": "^66.6.2",
102
- "@vue/runtime-core": "^3.5.29",
101
+ "@unocss/preset-icons": "^66.6.7",
102
+ "@vue/runtime-core": "^3.5.30",
103
103
  "beasties": "^0.4.1",
104
104
  "css": "^3.0.0",
105
105
  "css-to-tailwind-translator": "^1.2.8",
106
106
  "pinia": "^3.0.4",
107
- "quasar": "^2.18.6",
107
+ "quasar": "^2.18.7",
108
108
  "rollup": "^4.59.0",
109
109
  "typescript": "^5.9.3",
110
- "vue": "^3.5.29",
110
+ "vue": "^3.5.30",
111
111
  "vue-router": "^5.0.3"
112
112
  },
113
113
  "peerDependencies": {
114
114
  "@fastify/static": "^9.0.0",
115
- "@pinia/colada": "^0.21.5",
116
- "fastify": "^5.7.4",
115
+ "@pinia/colada": "^1.0.0",
116
+ "fastify": "^5.8.2",
117
117
  "pinia": "^3.0.4",
118
- "quasar": "^2.18.6",
119
- "vue": "^3.5.29",
118
+ "quasar": "^2.18.7",
119
+ "vue": "^3.5.30",
120
120
  "vue-router": "^5.0.3"
121
121
  },
122
122
  "publishConfig": {
@@ -3,11 +3,11 @@ import cac from 'cac'
3
3
  import { fileURLToPath } from 'url'
4
4
  import { getAppDir, parsePath } from '../app-urls.js'
5
5
  import { printHttpServerUrls, exitLogs } from '../helpers/logger.js'
6
- import { build as esbuild } from 'esbuild'
6
+ import { minify } from 'rolldown/utils'
7
7
  import type { ResolvedConfig, ViteDevServer } from 'vite'
8
8
  import type { Server } from 'net'
9
9
  import type { FastifyInstance } from 'fastify'
10
- import { readdir } from 'fs/promises'
10
+ import { readdir, readFile, writeFile } from 'fs/promises'
11
11
  import { loadSSRAssets } from '../frameworks/vue/fastify-ssr-plugin.js'
12
12
 
13
13
  const cli = cac('vitrify')
@@ -199,23 +199,27 @@ cli.command('run <file>').action(async (file, options) => {
199
199
  })
200
200
 
201
201
  cli.command('minify <dir>').action(async (dir, options) => {
202
- const files = await readdir(
203
- fileURLToPath(new URL(dir, `file://${process.cwd()}/`))
204
- )
202
+ const baseUrl = new URL(dir, `file://${process.cwd()}/`)
203
+ const files = await readdir(fileURLToPath(baseUrl))
205
204
  let counter = 0
206
205
  for (const file of files) {
207
206
  if (file.endsWith('.mjs')) {
208
- await esbuild({
209
- absWorkingDir: fileURLToPath(new URL(dir, `file://${process.cwd()}/`)),
210
- entryPoints: [file],
211
- minify: true,
212
- minifyIdentifiers: true,
213
- minifySyntax: true,
214
- minifyWhitespace: true,
215
- outfile: file,
216
- allowOverwrite: true
207
+ const path = fileURLToPath(
208
+ new URL(`${dir}/${file}`, `file://${process.cwd()}/`)
209
+ )
210
+ const content = await readFile(path, {
211
+ encoding: 'utf-8'
212
+ })
213
+ const output = await minify(path, content, {
214
+ compress: true,
215
+ module: true,
216
+ mangle: true,
217
+ codegen: true
217
218
  })
218
- counter++
219
+ if (!output.errors.length) {
220
+ await writeFile(path, output.code)
221
+ counter++
222
+ }
219
223
  }
220
224
  }
221
225
  console.log(`Minified ${counter} files`)
@@ -177,7 +177,11 @@ export async function createServer({
177
177
  : fileURLToPath(new URL(`src/vite/${framework}/ssr/app.ts`, cliDir))
178
178
 
179
179
  const environment = vite.environments.ssr
180
- ;({ setup, onTemplateRendered, onAppRendered, vitrifyConfig } =
180
+ ;({
181
+ setup,
182
+ hooks: { onTemplateRendered, onAppRendered },
183
+ vitrifyConfig
184
+ } =
181
185
  // @ts-expect-error missing types
182
186
  await environment.runner.import(entryUrl))
183
187
 
@@ -307,7 +307,9 @@ const loadSSRAssets = async (
307
307
  const manifest = JSON.parse(readFileSync(manifestPath).toString())
308
308
  const entryServer = await import(entryServerPath)
309
309
  const { render, getRoutes } = entryServer
310
- const { onTemplateRendered, onAppRendered } = await import(vitrifyHooksPath)
310
+ const {
311
+ hooks: { onTemplateRendered, onAppRendered }
312
+ } = await import(vitrifyHooksPath)
311
313
 
312
314
  return {
313
315
  template,
package/src/node/index.ts CHANGED
@@ -7,10 +7,8 @@ import type {
7
7
  } from 'vite'
8
8
  import { findDepPkgJsonPath } from 'vitefu'
9
9
  import { mergeConfig } from 'vite'
10
- import { build } from 'esbuild'
10
+ import { transform } from 'rolldown/utils'
11
11
  import fs from 'fs'
12
- import path from 'path'
13
- import { pathToFileURL } from 'url'
14
12
  import { readFileSync } from 'fs'
15
13
  import { builtinModules } from 'node:module'
16
14
  import { visualizer } from 'rollup-plugin-visualizer'
@@ -36,12 +34,12 @@ import type {
36
34
  import type { VitrifyContext } from './bin/run.js'
37
35
  import type { VitrifyPlugin } from './plugins/index.js'
38
36
  import { resolve } from './app-urls.js'
39
- import type { ManualChunksOption, RollupOptions } from 'rollup'
40
37
  import { addOrReplaceTitle, appendToBody } from './helpers/utils.js'
41
38
  import Components from 'unplugin-vue-components/vite'
42
39
  import { VitePWA } from 'vite-plugin-pwa'
43
40
  import UnoCSS from 'unocss/vite'
44
41
  import { searchForWorkspaceRoot } from 'vite'
42
+ import { CodeSplittingGroup, RolldownOptions } from 'rolldown'
45
43
 
46
44
  const internalServerModules = [
47
45
  'util',
@@ -62,8 +60,8 @@ const internalServerModules = [
62
60
  const manualChunkNames = [
63
61
  'prerender',
64
62
  'fastify-ssr-plugin',
65
- 'fastify-csr-plugin',
66
- 'server'
63
+ 'fastify-csr-plugin'
64
+ // 'server'
67
65
  ]
68
66
 
69
67
  const moduleChunks = {
@@ -85,31 +83,6 @@ const moduleChunks = {
85
83
  quasar: ['quasar'],
86
84
  atQuasar: ['@quasar']
87
85
  }
88
- const manualChunksFn = (manualChunkList?: string[]): ManualChunksOption => {
89
- return (id: string) => {
90
- const matchedModule = Object.entries(moduleChunks).find(
91
- ([chunkName, moduleNames]) =>
92
- moduleNames.some((moduleName) =>
93
- new RegExp(`\/${moduleName}\/`).test(id)
94
- )
95
- )
96
- if (id.includes('vitrify/src/')) {
97
- const name = id.split('/').at(-1)?.split('.').at(0)
98
- if (name && manualChunkNames.includes(name)) return name
99
- } else if (
100
- VIRTUAL_MODULES.some((virtualModule) => id.includes(virtualModule))
101
- ) {
102
- return VIRTUAL_MODULES.find((name) => id.includes(name))
103
- } else if (manualChunkList?.some((file) => id.includes(file))) {
104
- return manualChunkList.find((file) => id.includes(file))
105
- } else if (id.includes('node_modules')) {
106
- if (matchedModule) {
107
- return matchedModule[0]
108
- }
109
- return 'vendor'
110
- }
111
- }
112
- }
113
86
 
114
87
  export const VIRTUAL_MODULES = [
115
88
  'virtual:vitrify-hooks',
@@ -119,62 +92,42 @@ export const VIRTUAL_MODULES = [
119
92
  'vitrify.css'
120
93
  ]
121
94
 
122
- async function bundleConfigFile(
123
- fileName: string,
124
- isESM = false
125
- ): Promise<{ code: string; dependencies: string[] }> {
126
- const result = await build({
127
- absWorkingDir: process.cwd(),
128
- entryPoints: [fileName],
129
- outfile: 'out.js',
130
- write: false,
131
- platform: 'node',
132
- bundle: true,
133
- format: 'esm',
134
- sourcemap: 'inline',
135
- metafile: true,
136
- plugins: [
137
- {
138
- name: 'externalize-deps',
139
- setup(build) {
140
- build.onResolve({ filter: /.*/ }, (args) => {
141
- const id = args.path
142
- if (id[0] !== '.' && !path.isAbsolute(id)) {
143
- return {
144
- external: true
145
- }
146
- }
147
- })
148
- }
149
- },
150
- {
151
- name: 'replace-import-meta',
152
- setup(build) {
153
- build.onLoad({ filter: /\.[jt]s$/ }, async (args) => {
154
- const contents = await fs.promises.readFile(args.path, 'utf8')
155
- return {
156
- loader: args.path.endsWith('.ts') ? 'ts' : 'js',
157
- contents: contents
158
- .replace(
159
- /\bimport\.meta\.url\b/g,
160
- JSON.stringify(pathToFileURL(args.path).href)
161
- )
162
- .replace(
163
- /\b__dirname\b/g,
164
- JSON.stringify(path.dirname(args.path))
165
- )
166
- .replace(/\b__filename\b/g, JSON.stringify(args.path))
167
- }
168
- })
169
- }
170
- }
171
- ]
172
- })
173
- const { text } = result.outputFiles[0]
174
- return {
175
- code: text,
176
- dependencies: result.metafile ? Object.keys(result.metafile.inputs) : []
177
- }
95
+ /**
96
+ * Advanced chunking may no longer be necessary.
97
+ * @param ssr
98
+ * @returns
99
+ */
100
+ const createCodeSplittingGroups = (
101
+ ssr?: VitrifySSRModes
102
+ ): CodeSplittingGroup[] => {
103
+ return [
104
+ ...VIRTUAL_MODULES.map((m) => ({
105
+ name: m,
106
+ test: new RegExp(m),
107
+ priority: 30
108
+ }))
109
+ // ...manualChunkNames.map((m) => ({
110
+ // name: m,
111
+ // test: new RegExp(m),
112
+ // priority: 20
113
+ // })),
114
+ // ...Object.entries(moduleChunks).map(([key, value]) => ({
115
+ // name: key,
116
+ // test: new RegExp(value.join('|')),
117
+ // priority: 20,
118
+ // maxSize: ssr === 'client' || ssr === 'ssg' ? 1000000 : Infinity
119
+ // })),
120
+ // {
121
+ // name: 'vendor',
122
+ // test: /node_modules/,
123
+ // priority: 1
124
+ // },
125
+ // {
126
+ // name: 'typst',
127
+ // test: /\.typ/,
128
+ // priority: 40
129
+ // }
130
+ ]
178
131
  }
179
132
 
180
133
  export const baseConfig = async ({
@@ -218,10 +171,12 @@ export const baseConfig = async ({
218
171
  try {
219
172
  if (fs.existsSync(fileURLToPath(new URL('vitrify.config.ts', appDir)))) {
220
173
  const configPath = fileURLToPath(new URL('vitrify.config.ts', appDir))
221
- const bundledConfig = await bundleConfigFile(
222
- fileURLToPath(new URL('vitrify.config.ts', appDir))
223
- )
224
- fs.writeFileSync(configPath + '.js', bundledConfig.code)
174
+
175
+ const content = readFileSync(configPath, {
176
+ encoding: 'utf-8'
177
+ })
178
+ const output = await transform(configPath, content)
179
+ fs.writeFileSync(configPath + '.js', output.code)
225
180
 
226
181
  rawVitrifyConfig = (await import('file://' + configPath + '.js')).default
227
182
  fs.unlinkSync(configPath + '.js')
@@ -416,7 +371,7 @@ export const baseConfig = async ({
416
371
  },
417
372
  load(id) {
418
373
  if (id === 'virtual:vitrify-hooks') {
419
- return `export const onAppMounted = [${onAppMountedHooks
374
+ return `const onAppMounted = [${onAppMountedHooks
420
375
  .map((fn) => `${String(fn)}`)
421
376
  .join(', ')}]
422
377
  ${onAppMountedFiles
@@ -435,7 +390,7 @@ export const baseConfig = async ({
435
390
  }'; onAppMounted.push(${varName});`
436
391
  })
437
392
  .join('\n')}
438
- export const onAppRendered = [${onAppRenderedHooks
393
+ const onAppRendered = [${onAppRenderedHooks
439
394
  .map((fn) => `${String(fn)}`)
440
395
  .join(', ')}]
441
396
  ${onAppRenderedFiles
@@ -454,7 +409,7 @@ export const baseConfig = async ({
454
409
  }'; onAppRendered.push(${varName});`
455
410
  })
456
411
  .join('\n')}
457
- export const onTemplateRendered = [${onTemplateRenderedHooks
412
+ const onTemplateRendered = [${onTemplateRenderedHooks
458
413
  .map((fn) => `${String(fn)}`)
459
414
  .join(', ')}]
460
415
  ${onTemplateRenderedFiles
@@ -473,7 +428,7 @@ export const baseConfig = async ({
473
428
  }'; onTemplateRendered.push(${varName});`
474
429
  })
475
430
  .join('\n')}
476
- export const onAppCreated = [${OnAppCreatedHooks.map(
431
+ const onAppCreated = [${OnAppCreatedHooks.map(
477
432
  (fn) => `${String(fn)}`
478
433
  ).join(', ')}]
479
434
  ${onAppCreatedFiles
@@ -492,7 +447,7 @@ export const baseConfig = async ({
492
447
  }'; onAppCreated.push(${varName});`
493
448
  })
494
449
  .join('\n')}
495
- export const onSetup = []
450
+ const onSetup = []
496
451
  ${onSetupFiles
497
452
  .map((url, index) => {
498
453
  const varName = fileURLToPath(url)
@@ -508,7 +463,14 @@ export const baseConfig = async ({
508
463
  new URL(url, appDir).href
509
464
  }'; onSetup.push(${varName});`
510
465
  })
511
- .join('\n')}`
466
+ .join('\n')}
467
+ export const hooks = {
468
+ onAppMounted,
469
+ onAppRendered,
470
+ onAppCreated,
471
+ onTemplateRendered,
472
+ onSetup
473
+ }`
512
474
  } else if (id === 'virtual:static-imports') {
513
475
  return `${Object.entries(staticImports)
514
476
  .map(([key, value]) => {
@@ -681,7 +643,7 @@ export const baseConfig = async ({
681
643
  replacement: fileURLToPath(new URL(await resolve('vitest', cliDir)))
682
644
  })
683
645
 
684
- let rollupOptions: RollupOptions = {}
646
+ let rollupOptions: RolldownOptions = {}
685
647
  let noExternal: RegExp[] | string[] = [
686
648
  new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
687
649
  ]
@@ -702,7 +664,9 @@ export const baseConfig = async ({
702
664
  entryFileNames: '[name].mjs',
703
665
  chunkFileNames: '[name].mjs',
704
666
  format: 'es',
705
- manualChunks: manualChunksFn(vitrifyConfig?.vitrify?.manualChunks)
667
+ codeSplitting: {
668
+ groups: createCodeSplittingGroups(ssr)
669
+ }
706
670
  }
707
671
  }
708
672
  // Create a SSR bundle
@@ -719,7 +683,9 @@ export const baseConfig = async ({
719
683
  entryFileNames: '[name].mjs',
720
684
  chunkFileNames: '[name].mjs',
721
685
  format: 'es',
722
- manualChunks: manualChunksFn(vitrifyConfig?.vitrify?.manualChunks)
686
+ codeSplitting: {
687
+ groups: createCodeSplittingGroups(ssr)
688
+ }
723
689
  }
724
690
  }
725
691
  // Create a SSR bundle
@@ -735,7 +701,9 @@ export const baseConfig = async ({
735
701
  entryFileNames: '[name].mjs',
736
702
  chunkFileNames: '[name].mjs',
737
703
  format: 'es',
738
- manualChunks: manualChunksFn(vitrifyConfig?.vitrify?.manualChunks)
704
+ codeSplitting: {
705
+ groups: createCodeSplittingGroups(ssr)
706
+ }
739
707
  }
740
708
  }
741
709
  }
@@ -1,12 +1,14 @@
1
1
  import type { FastifyInstance } from 'fastify'
2
- import { onSetup } from 'virtual:vitrify-hooks'
2
+ import { hooks } from 'virtual:vitrify-hooks'
3
3
  export { default as vitrifyConfig } from 'virtual:vitrify-config'
4
4
 
5
5
  export const setup = async ({ fastify }: { fastify: FastifyInstance }) => {
6
- if (onSetup?.length) {
7
- for (const setup of onSetup) {
6
+ if (hooks.onSetup?.length) {
7
+ for (const setup of hooks.onSetup) {
8
8
  await setup(fastify)
9
9
  }
10
10
  }
11
11
  return fastify
12
12
  }
13
+
14
+ export { hooks }
@@ -8,15 +8,17 @@ import {
8
8
  onMounted as onMountedVue,
9
9
  getCurrentInstance
10
10
  } from 'vue'
11
- import { onAppMounted } from 'virtual:vitrify-hooks'
11
+ import { hooks } from 'virtual:vitrify-hooks'
12
12
  import App from 'src/App.vue'
13
13
  // import 'vitrify.sass'
14
14
  const instance = getCurrentInstance()
15
15
  const props = defineProps()
16
16
 
17
17
  onMountedVue(async () => {
18
- for (let fn of onAppMounted) {
19
- await fn({ instance })
18
+ if (hooks.onAppMounted) {
19
+ for (let fn of hooks.onAppMounted) {
20
+ await fn({ instance })
21
+ }
20
22
  }
21
23
  })
22
24
 
@@ -1,7 +1,7 @@
1
1
  import { createApp } from '../../../node/frameworks/vue/server.js'
2
2
  import { getAppDir } from '../../../node/app-urls.js'
3
3
  // import { setup } from 'virtual:fastify-setup'
4
- import { onSetup } from 'virtual:vitrify-hooks'
4
+ import { hooks } from 'virtual:vitrify-hooks'
5
5
  import { fastifyCsrPlugin } from './fastify-csr-plugin'
6
6
 
7
7
  // const appDir = getPkgJsonDir(import.meta.url)
@@ -12,7 +12,7 @@ const appDir = getAppDir()
12
12
  export const setupApp = async () => {
13
13
  // const vitrifyDir = new URL('../', await resolve('vitrify', new URL(import.meta.url)))
14
14
  return createApp({
15
- onSetup,
15
+ onSetup: hooks.onSetup,
16
16
  appDir,
17
17
  baseUrl,
18
18
  fastifyPlugin: fastifyCsrPlugin,
@@ -1,6 +1,6 @@
1
1
  import createRouter from 'src/router'
2
2
  import { App, createSSRApp, createApp as createVueApp, ref } from 'vue'
3
- import { onBoot, onAppCreated } from 'virtual:vitrify-hooks'
3
+ import { hooks } from 'virtual:vitrify-hooks'
4
4
  import routes from 'src/router/routes'
5
5
  import * as staticImports from 'virtual:static-imports'
6
6
  import 'virtual:uno.css'
@@ -69,8 +69,10 @@ export async function createApp(
69
69
  const router = createRouter()
70
70
  app.use(router)
71
71
 
72
- for (const fn of onAppCreated) {
73
- await fn({ app, router, ctx, initialState, ssrContext, staticImports })
72
+ if (hooks.onAppCreated) {
73
+ for (const fn of hooks.onAppCreated) {
74
+ await fn({ app, router, ctx, initialState, ssrContext, staticImports })
75
+ }
74
76
  }
75
77
 
76
78
  // Workaround to fix hydration errors when serving html files directly
@@ -1,10 +1,6 @@
1
1
  import { createApp } from '../../../node/frameworks/vue/server.js'
2
2
  import { getAppDir } from '../../../node/app-urls.js'
3
- import {
4
- onSetup,
5
- onAppRendered,
6
- onTemplateRendered
7
- } from 'virtual:vitrify-hooks'
3
+ import { hooks } from 'virtual:vitrify-hooks'
8
4
  import { fastifySsrPlugin } from './fastify-ssr-plugin.js'
9
5
 
10
6
  const getString = (str?: string) => str
@@ -13,15 +9,15 @@ const appDir = getAppDir()
13
9
 
14
10
  export const setupApp = async () => {
15
11
  return createApp({
16
- onSetup,
12
+ onSetup: hooks.onSetup,
17
13
  appDir,
18
14
  baseUrl,
19
15
  fastifyPlugin: fastifySsrPlugin,
20
- onAppRendered,
21
- onTemplateRendered,
16
+ onAppRendered: hooks.onAppRendered,
17
+ onTemplateRendered: hooks.onTemplateRendered,
22
18
  mode: import.meta.env.MODE
23
19
  })
24
20
  }
25
21
 
26
22
  export { default as vitrifyConfig } from 'virtual:vitrify-config'
27
- export { onAppRendered, onTemplateRendered }
23
+ export { hooks }
@@ -1,4 +1,4 @@
1
1
  import { prerender } from '../../../node/frameworks/vue/prerender.js'
2
- import { onTemplateRendered } from 'virtual:vitrify-hooks'
2
+ import { hooks } from 'virtual:vitrify-hooks'
3
3
 
4
- export { prerender, onTemplateRendered }
4
+ export { prerender, hooks }
@@ -1,4 +1,5 @@
1
1
  import { setupApp } from './app'
2
+ import { hooks } from 'virtual:vitrify-hooks'
2
3
 
3
4
  const app = await setupApp()
4
5
 
@@ -6,3 +7,5 @@ app.listen({
6
7
  port: Number(process.env.PORT || 3000),
7
8
  host: process.env.HOST || 'localhost'
8
9
  })
10
+
11
+ export { hooks }