vitrify 0.2.5 → 0.5.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.
Files changed (54) hide show
  1. package/README.md +2 -2
  2. package/dist/app-urls.js +1 -2
  3. package/dist/bin/build.js +9 -51
  4. package/dist/bin/cli.js +31 -9
  5. package/dist/bin/dev.js +72 -70
  6. package/dist/frameworks/vue/fastify-csr-plugin.js +38 -0
  7. package/dist/frameworks/vue/fastify-ssr-plugin.js +83 -25
  8. package/dist/frameworks/vue/prerender.js +3 -3
  9. package/dist/frameworks/vue/server.js +10 -11
  10. package/dist/helpers/collect-css-ssr.js +61 -0
  11. package/dist/helpers/logger.js +0 -72
  12. package/dist/index.js +310 -130
  13. package/dist/plugins/quasar.js +34 -111
  14. package/dist/types/bin/build.d.ts +2 -2
  15. package/dist/types/bin/dev.d.ts +42 -4
  16. package/dist/types/frameworks/vue/fastify-csr-plugin.d.ts +17 -0
  17. package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +6 -3
  18. package/dist/types/frameworks/vue/prerender.d.ts +3 -3
  19. package/dist/types/frameworks/vue/server.d.ts +10 -5
  20. package/dist/types/helpers/collect-css-ssr.d.ts +14 -0
  21. package/dist/types/helpers/logger.d.ts +0 -19
  22. package/dist/types/helpers/routes.d.ts +1 -1
  23. package/dist/types/index.d.ts +4 -2
  24. package/dist/types/plugins/index.d.ts +1 -1
  25. package/dist/types/vitrify-config.d.ts +33 -17
  26. package/package.json +33 -32
  27. package/src/node/app-urls.ts +1 -2
  28. package/src/node/bin/build.ts +11 -57
  29. package/src/node/bin/cli.ts +38 -10
  30. package/src/node/bin/dev.ts +106 -80
  31. package/src/node/bin/test.ts +0 -3
  32. package/src/node/frameworks/vue/fastify-csr-plugin.ts +72 -0
  33. package/src/node/frameworks/vue/fastify-ssr-plugin.ts +99 -28
  34. package/src/node/frameworks/vue/prerender.ts +5 -5
  35. package/src/node/frameworks/vue/server.ts +24 -17
  36. package/src/node/helpers/collect-css-ssr.ts +85 -0
  37. package/src/node/helpers/logger.ts +0 -87
  38. package/src/node/index.ts +353 -146
  39. package/src/node/plugins/index.ts +1 -1
  40. package/src/node/plugins/quasar.ts +39 -116
  41. package/src/node/vitrify-config.ts +44 -17
  42. package/src/vite/fastify/entry.ts +11 -0
  43. package/src/vite/fastify/server.ts +12 -0
  44. package/src/vite/vue/csr/app.ts +25 -0
  45. package/src/vite/vue/csr/fastify-csr-plugin.ts +3 -0
  46. package/src/vite/vue/csr/server.ts +8 -0
  47. package/src/vite/vue/index.html +1 -0
  48. package/src/vite/vue/main.ts +5 -20
  49. package/src/vite/vue/ssr/app.ts +25 -0
  50. package/src/vite/vue/ssr/entry-server.ts +13 -1
  51. package/src/vite/vue/ssr/fastify-ssr-plugin.ts +2 -118
  52. package/src/vite/vue/ssr/prerender.ts +2 -2
  53. package/src/vite/vue/ssr/server.ts +24 -15
  54. package/src/node/helpers/ssr.ts.bak +0 -52
package/dist/index.js CHANGED
@@ -1,23 +1,118 @@
1
1
  import vuePlugin from '@vitejs/plugin-vue';
2
2
  import { mergeConfig } from 'vite';
3
+ import { build } from 'esbuild';
4
+ import fs from 'fs';
5
+ import path from 'path';
6
+ import { pathToFileURL } from 'url';
3
7
  import { readFileSync } from 'fs';
4
8
  import builtinModules from 'builtin-modules';
5
9
  import { resolve } from 'import-meta-resolve';
6
10
  import { getPkgJsonDir } from './app-urls.js';
7
- const serverModules = ['fastify', 'middie'];
11
+ const internalServerModules = [
12
+ // 'fs',
13
+ // 'path',
14
+ // 'url',
15
+ // 'module',
16
+ // 'crypto',
17
+ // 'node:fs',
18
+ 'util',
19
+ 'node:url',
20
+ 'node:util',
21
+ 'node:fs',
22
+ 'node:process',
23
+ 'vitrify',
24
+ 'vitrify/dev',
25
+ // 'import-meta-resolve',
26
+ 'vite',
27
+ 'fastify',
28
+ '@fastify',
29
+ 'node'
30
+ // 'middie',
31
+ // 'knex',
32
+ // 'bcrypt',
33
+ // 'objection',
34
+ // '@fastify/formbody',
35
+ // '@fastify/static',
36
+ // '@fastify/cors',
37
+ // '@fastify/cookie',
38
+ // 'mercurius',
39
+ // 'jose',
40
+ // 'oidc-provider',
41
+ // 'node-fetch'
42
+ ];
8
43
  const configPluginMap = {
9
44
  quasar: () => import('./plugins/quasar.js').then((module) => module.QuasarPlugin)
10
45
  };
11
- const manualChunks = ['prerender', 'fastify-ssr-plugin', 'server'];
46
+ const manualChunkNames = [
47
+ 'prerender',
48
+ 'fastify-ssr-plugin',
49
+ 'fastify-csr-plugin',
50
+ 'server'
51
+ ];
52
+ const manualChunks = (id) => {
53
+ if (id.includes('vitrify/src/vite/')) {
54
+ const name = id.split('/').at(-1)?.split('.').at(0);
55
+ if (name && manualChunkNames.includes(name))
56
+ return name;
57
+ }
58
+ else if (id.includes('node_modules')) {
59
+ return 'vendor';
60
+ }
61
+ };
12
62
  export const VIRTUAL_MODULES = [
13
- 'virtual:fastify-setup',
14
- 'virtual:boot-functions',
15
- 'virtual:ssr-functions',
16
- 'virtual:on-mounted-hooks',
63
+ 'virtual:vitrify-hooks',
17
64
  'virtual:global-css',
18
65
  'virtual:static-imports'
19
66
  ];
20
- export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mode = 'production', framework = 'vue', pwa = false }) => {
67
+ async function bundleConfigFile(fileName, isESM = false) {
68
+ const result = await build({
69
+ absWorkingDir: process.cwd(),
70
+ entryPoints: [fileName],
71
+ outfile: 'out.js',
72
+ write: false,
73
+ platform: 'node',
74
+ bundle: true,
75
+ format: 'esm',
76
+ sourcemap: 'inline',
77
+ metafile: true,
78
+ plugins: [
79
+ {
80
+ name: 'externalize-deps',
81
+ setup(build) {
82
+ build.onResolve({ filter: /.*/ }, (args) => {
83
+ const id = args.path;
84
+ if (id[0] !== '.' && !path.isAbsolute(id)) {
85
+ return {
86
+ external: true
87
+ };
88
+ }
89
+ });
90
+ }
91
+ },
92
+ {
93
+ name: 'replace-import-meta',
94
+ setup(build) {
95
+ build.onLoad({ filter: /\.[jt]s$/ }, async (args) => {
96
+ const contents = await fs.promises.readFile(args.path, 'utf8');
97
+ return {
98
+ loader: args.path.endsWith('.ts') ? 'ts' : 'js',
99
+ contents: contents
100
+ .replace(/\bimport\.meta\.url\b/g, JSON.stringify(pathToFileURL(args.path).href))
101
+ .replace(/\b__dirname\b/g, JSON.stringify(path.dirname(args.path)))
102
+ .replace(/\b__filename\b/g, JSON.stringify(args.path))
103
+ };
104
+ });
105
+ }
106
+ }
107
+ ]
108
+ });
109
+ const { text } = result.outputFiles[0];
110
+ return {
111
+ code: text,
112
+ dependencies: result.metafile ? Object.keys(result.metafile.inputs) : []
113
+ };
114
+ }
115
+ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command = 'build', mode = 'production', framework = 'vue', pwa = false }) => {
21
116
  const { getAppDir, getCliDir, getCliViteDir, getSrcDir, getCwd } = await import('./app-urls.js');
22
117
  if (!appDir) {
23
118
  appDir = getAppDir();
@@ -26,37 +121,8 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
26
121
  const cwd = getCwd();
27
122
  const cliDir = getCliDir();
28
123
  const cliViteDir = getCliViteDir(cliDir);
29
- // const {
30
- // appDir: tempAppDir,
31
- // cliDir,
32
- // cliViteDir,
33
- // srcDir
34
- // } = await import('./app-urls.js')
35
- // const cwd = appDir || tempAppDir
36
124
  const frameworkDir = new URL(`${framework}/`, cliViteDir);
37
- // const localPackages = ['vue', 'vue-router', 'quasar']
38
- const localPackages = ['vue', 'vue-router'];
39
- const cliPackages = ['vitest'];
40
- const packageUrls = {};
41
- await (async () => {
42
- for (const val of localPackages)
43
- packageUrls[val] = getPkgJsonDir(new URL(await resolve(val, appDir.href)));
44
- })();
45
- await (async () => {
46
- for (const val of cliPackages)
47
- packageUrls[val] = getPkgJsonDir(new URL(await resolve(val, cliDir.href)));
48
- })();
49
- // if (appDir) {
50
- // srcDir = new URL('src/', appDir);
51
- // quasarDir = new URL(await resolve('quasar/', appDir.href));
52
- // ({ appDir: cwd, cliDir } = await import('./app-urls.js'))
53
- // } else {
54
- // ({ appDir, cliDir, srcDir, quasarDir } = await import('./app-urls.js'))
55
- // cwd = appDir
56
- // }
57
- // vueDir = new URL('./', await resolve('vue', appDir.href));
58
- // vueRouterDir = new URL('../', await resolve('vue-router', appDir.href));
59
- // vitestDir = new URL('../', await resolve('vitest', cliDir.href));
125
+ const fastifyDir = new URL('fastify/', cliViteDir);
60
126
  if (!publicDir)
61
127
  publicDir = new URL('public/', appDir);
62
128
  /**
@@ -64,19 +130,46 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
64
130
  */
65
131
  let vitrifyConfig;
66
132
  try {
67
- vitrifyConfig = (await import(new URL('vitrify.config.js', appDir).pathname)).default;
133
+ if (fs.existsSync(new URL('vitrify.config.ts', appDir).pathname)) {
134
+ const configPath = new URL('vitrify.config.ts', appDir).pathname;
135
+ const bundledConfig = await bundleConfigFile(new URL('vitrify.config.ts', appDir).pathname);
136
+ fs.writeFileSync(configPath + '.js', bundledConfig.code);
137
+ vitrifyConfig = (await import(configPath + '.js')).default;
138
+ fs.unlinkSync(configPath + '.js');
139
+ }
140
+ else {
141
+ vitrifyConfig = (await import(new URL('vitrify.config.js', appDir).pathname)).default;
142
+ }
68
143
  if (typeof vitrifyConfig === 'function')
69
- vitrifyConfig = vitrifyConfig({ mode, command });
144
+ vitrifyConfig = await vitrifyConfig({ mode, command });
70
145
  }
71
146
  catch (e) {
72
- console.error(e);
73
- console.log('No vitrify.config.js file found, using defaults');
147
+ console.log('No vitrify.config.(ts|js) file found, using defaults');
74
148
  vitrifyConfig = {};
75
149
  }
76
- let { productName = 'Product name' } = JSON.parse(readFileSync(new URL('package.json', appDir).pathname, {
77
- encoding: 'utf-8'
78
- }));
79
- const fastifySetup = vitrifyConfig.vitrify?.fastify?.setup || ((fastify) => { });
150
+ const localPackages = ['vue', 'vue-router'];
151
+ const cliPackages = [];
152
+ const packageUrls = vitrifyConfig.vitrify?.urls?.packages || {};
153
+ await (async () => {
154
+ for (const val of localPackages)
155
+ packageUrls[val] = getPkgJsonDir(new URL(await resolve(val, appDir.href)));
156
+ })();
157
+ // await (async () => {
158
+ // for (const val of cliPackages)
159
+ // packageUrls[val] = getPkgJsonDir(
160
+ // new URL(await resolve(val, cliDir!.href))
161
+ // )
162
+ // })()
163
+ let productName = 'Product name';
164
+ try {
165
+ ;
166
+ ({ productName } = JSON.parse(readFileSync(new URL('package.json', appDir).pathname, {
167
+ encoding: 'utf-8'
168
+ })));
169
+ }
170
+ catch (e) {
171
+ console.error('package.json not found');
172
+ }
80
173
  const ssrTransformCustomDir = () => {
81
174
  return {
82
175
  props: [],
@@ -93,15 +186,23 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
93
186
  }));
94
187
  }
95
188
  }
96
- let bootFunctions;
97
- let ssrFunctions;
189
+ let onBootHooks;
190
+ let onRenderedHooks;
98
191
  let onMountedHooks;
192
+ let onSetupFiles;
99
193
  let globalCss;
100
194
  let staticImports;
101
195
  let sassVariables;
102
196
  let additionalData;
197
+ let serverModules = internalServerModules;
198
+ if (vitrifyConfig.vitrify?.ssr?.serverModules)
199
+ serverModules = [
200
+ ...serverModules,
201
+ ...vitrifyConfig.vitrify.ssr.serverModules
202
+ ];
103
203
  const plugins = [
104
204
  vuePlugin({
205
+ compiler: await import('vue/compiler-sfc'),
105
206
  template: {
106
207
  ssr: !!ssr,
107
208
  compilerOptions: {
@@ -122,18 +223,14 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
122
223
  }
123
224
  }),
124
225
  ...frameworkPlugins,
125
- // await QuasarPlugin({
126
- // ssr: ssr,
127
- // pwa: pwa
128
- // // quasarDir: packageUrls.quasar
129
- // }),
130
226
  {
131
227
  name: 'vitrify-setup',
132
228
  enforce: 'post',
133
229
  config: async (config, env) => {
134
- bootFunctions = config.vitrify?.bootFunctions || [];
135
- ssrFunctions = config.vitrify?.ssrFunctions || [];
230
+ onBootHooks = config.vitrify?.hooks?.onBoot || [];
231
+ onRenderedHooks = config.vitrify?.hooks?.onRendered || [];
136
232
  onMountedHooks = config.vitrify?.hooks?.onMounted || [];
233
+ onSetupFiles = config?.vitrify?.hooks?.onSetup || [];
137
234
  globalCss = config.vitrify?.globalCss || [];
138
235
  staticImports = config.vitrify?.staticImports || {};
139
236
  sassVariables = config.vitrify?.sass?.variables || {};
@@ -160,30 +257,43 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
160
257
  },
161
258
  resolveId(id) {
162
259
  if (VIRTUAL_MODULES.includes(id))
163
- return id;
260
+ return { id, moduleSideEffects: false };
164
261
  return;
165
262
  },
166
- load(id) {
167
- if (id === 'virtual:fastify-setup') {
168
- return `export const setup = ${String(fastifySetup)}`;
263
+ transform: (code, id) => {
264
+ if (id.endsWith('main.ts') && id.includes('vitrify')) {
265
+ code =
266
+ `${globalCss.map((css) => `import '${css}'`).join('\n')}\n` + code;
169
267
  }
170
- else if (id === 'virtual:boot-functions') {
171
- return `export default [${bootFunctions
268
+ return code;
269
+ },
270
+ load(id) {
271
+ if (id === 'virtual:vitrify-hooks') {
272
+ return `export const onBoot = [${onBootHooks
172
273
  .map((fn) => `${String(fn)}`)
173
- .join(', ')}]`;
174
- }
175
- else if (id === 'virtual:ssr-functions') {
176
- return `export default [${ssrFunctions
274
+ .join(', ')}]
275
+ export const onMounted = [${onMountedHooks
177
276
  .map((fn) => `${String(fn)}`)
178
- .join(', ')}]`;
179
- }
180
- else if (id === 'virtual:on-mounted-hooks') {
181
- return `export default [${onMountedHooks
277
+ .join(', ')}]
278
+ export const onRendered = [${onRenderedHooks
182
279
  .map((fn) => `${String(fn)}`)
183
- .join(', ')}]`;
184
- }
185
- else if (id === 'virtual:global-css') {
186
- return `${globalCss.map((css) => `import '${css}'`).join('\n')}`;
280
+ .join(', ')}]
281
+ export const onSetup = []
282
+ ${onSetupFiles
283
+ .map((url, index) => `import ${url.pathname
284
+ .replaceAll('/', '')
285
+ .replaceAll('.', '')} from '${url.pathname}'; onSetup.push(${url.pathname
286
+ .replaceAll('/', '')
287
+ .replaceAll('.', '')})`)
288
+ .join('\n')}`;
289
+ // export const onSetup = [${onSetupHooks
290
+ // .map((fn) => `${String(fn)}`)
291
+ // .join(', ')}]`
292
+ /**
293
+ * CSS imports in virtual files do not seem to work. Using transform() instead
294
+ */
295
+ // } else if (id === 'virtual:global-css') {
296
+ // return `${globalCss.map((css) => `import '${css}'`).join('\n')}`
187
297
  }
188
298
  else if (id === 'virtual:static-imports') {
189
299
  return `${Object.entries(staticImports)
@@ -218,6 +328,9 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
218
328
  case 'client':
219
329
  entry = new URL('ssr/entry-client.ts', frameworkDir).pathname;
220
330
  break;
331
+ case 'fastify':
332
+ entry = new URL('entry.ts', fastifyDir).pathname;
333
+ break;
221
334
  default:
222
335
  entry = new URL('csr/entry.ts', frameworkDir).pathname;
223
336
  }
@@ -251,25 +364,105 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
251
364
  { find: 'cwd', replacement: cwd.pathname },
252
365
  { find: 'boot', replacement: new URL('boot/', srcDir).pathname },
253
366
  { find: 'assets', replacement: new URL('assets/', srcDir).pathname },
254
- // ...Object.entries(packageUrls).map(([key, value]) => ({
255
- // find: key, replacement: value.pathname
256
- // })),
257
- { find: 'vue', replacement: packageUrls['vue'].pathname },
258
- { find: 'vue-router', replacement: packageUrls['vue-router'].pathname },
259
- { find: 'vitrify', replacement: cliDir.pathname }
367
+ ...Object.entries(packageUrls).map(([key, value]) => ({
368
+ find: key,
369
+ replacement: value.pathname
370
+ }))
371
+ // { find: 'vue', replacement: packageUrls['vue'].pathname },
372
+ // { find: 'vue-router', replacement: packageUrls['vue-router'].pathname },
373
+ // { find: 'vitrify', replacement: cliDir.pathname }
260
374
  ];
375
+ if (mode === 'development' && vitrifyConfig.vitrify?.dev?.alias)
376
+ alias.push(...vitrifyConfig.vitrify.dev.alias);
261
377
  if (command === 'test')
262
378
  alias.push({
263
379
  find: 'vitest',
264
- replacement: packageUrls.vitest.pathname
380
+ replacement: new URL(await resolve('vitest', cliDir.href)).pathname
265
381
  });
382
+ let rollupOptions = {};
383
+ let noExternal = [
384
+ new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
385
+ ];
386
+ const external = [...builtinModules, ...serverModules];
387
+ if (ssr === 'server') {
388
+ rollupOptions = {
389
+ input: [
390
+ new URL('ssr/entry-server.ts', frameworkDir).pathname,
391
+ new URL('ssr/prerender.ts', frameworkDir).pathname,
392
+ new URL('ssr/server.ts', frameworkDir).pathname
393
+ ],
394
+ external,
395
+ output: {
396
+ minifyInternalExports: false,
397
+ entryFileNames: '[name].mjs',
398
+ chunkFileNames: '[name].mjs',
399
+ format: 'es',
400
+ manualChunks
401
+ // manualChunks: (id) => {
402
+ // if (id.includes('vitrify/src/vite/')) {
403
+ // const name = id.split('/').at(-1)?.split('.').at(0)
404
+ // if (name && manualChunks.includes(name)) return name
405
+ // } else if (id.includes('node_modules')) {
406
+ // return 'vendor'
407
+ // }
408
+ // }
409
+ }
410
+ };
411
+ // Create a SSR bundle
412
+ noExternal = [
413
+ new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
414
+ // new RegExp(`^(?!.*(${[...builtinModules, ...serverModules].join('|')}))`)
415
+ ];
416
+ }
417
+ else if (ssr === 'fastify') {
418
+ rollupOptions = {
419
+ input: [new URL('server.ts', fastifyDir).pathname],
420
+ external,
421
+ output: {
422
+ minifyInternalExports: false,
423
+ entryFileNames: '[name].mjs',
424
+ chunkFileNames: '[name].mjs',
425
+ format: 'es',
426
+ manualChunks
427
+ // manualChunks: (id) => {
428
+ // if (id.includes('vitrify/src/vite/')) {
429
+ // const name = id.split('/').at(-1)?.split('.').at(0)
430
+ // if (name && manualChunks.includes(name)) return name
431
+ // } else if (id.includes('node_modules')) {
432
+ // return 'vendor'
433
+ // }
434
+ // }
435
+ }
436
+ };
437
+ // Create a SSR bundle
438
+ noExternal = [
439
+ new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
440
+ ];
441
+ }
442
+ else {
443
+ rollupOptions = {
444
+ input: [
445
+ new URL('index.html', frameworkDir).pathname
446
+ // new URL('csr/server.ts', frameworkDir).pathname
447
+ ],
448
+ external,
449
+ output: {
450
+ minifyInternalExports: false,
451
+ entryFileNames: '[name].mjs',
452
+ chunkFileNames: '[name].mjs',
453
+ format: 'es',
454
+ manualChunks
455
+ }
456
+ };
457
+ }
266
458
  const config = {
267
- root: frameworkDir.pathname,
459
+ root: ssr === 'fastify' ? appDir.pathname : frameworkDir.pathname,
268
460
  publicDir: publicDir.pathname,
461
+ base,
462
+ envDir: appDir.pathname,
269
463
  vitrify: {
270
464
  productName,
271
465
  urls: {
272
- // @ts-ignore
273
466
  app: appDir,
274
467
  cli: cliDir,
275
468
  src: srcDir,
@@ -279,67 +472,54 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
279
472
  },
280
473
  plugins,
281
474
  optimizeDeps: {
282
- exclude: ['vue']
475
+ exclude: ['vue', ...serverModules, ...builtinModules]
283
476
  },
284
477
  resolve: {
285
- // Dedupe uses require which breaks ESM SSR builds
286
- // dedupe: [
287
- // 'vue',
288
- // 'vue-router'
289
- // ],
478
+ dedupe: ['vue', 'vue-router'],
290
479
  alias
291
480
  },
292
481
  build: {
293
- target: ssr === 'server' ? 'esnext' : 'modules',
294
- ssr: ssr === 'server' ? true : false,
482
+ target: ssr === 'server' || ssr === 'fastify' ? 'esnext' : 'modules',
483
+ ssr: ssr === 'server' || ssr === 'fastify' ? true : false,
295
484
  ssrManifest: ssr === 'client' || ssr === 'ssg',
296
- rollupOptions: ssr === 'server'
297
- ? {
298
- input: [
299
- new URL('ssr/entry-server.ts', frameworkDir).pathname,
300
- new URL('ssr/prerender.ts', frameworkDir).pathname,
301
- new URL('ssr/server.ts', frameworkDir).pathname
302
- ],
303
- output: {
304
- minifyInternalExports: false,
305
- entryFileNames: '[name].mjs',
306
- chunkFileNames: '[name].mjs',
307
- format: 'es',
308
- manualChunks: (id) => {
309
- if (id.includes('vitrify/src/vite/')) {
310
- const name = id.split('/').at(-1)?.split('.').at(0);
311
- console.log(name);
312
- if (manualChunks.includes(id))
313
- return name;
314
- }
315
- else if (id.includes('node_modules')) {
316
- return 'vendor';
317
- }
318
- }
319
- }
320
- }
321
- : {
322
- output: {
323
- format: 'es'
324
- }
325
- }
485
+ rollupOptions
486
+ // ssr === 'server'
487
+ // ? {
488
+ // input: [
489
+ // new URL('ssr/entry-server.ts', frameworkDir).pathname,
490
+ // new URL('ssr/prerender.ts', frameworkDir).pathname,
491
+ // new URL('ssr/server.ts', frameworkDir).pathname
492
+ // ],
493
+ // output: {
494
+ // minifyInternalExports: false,
495
+ // entryFileNames: '[name].mjs',
496
+ // chunkFileNames: '[name].mjs',
497
+ // format: 'es',
498
+ // manualChunks: (id) => {
499
+ // if (id.includes('vitrify/src/vite/')) {
500
+ // const name = id.split('/').at(-1)?.split('.').at(0)
501
+ // if (name && manualChunks.includes(name)) return name
502
+ // } else if (id.includes('node_modules')) {
503
+ // return 'vendor'
504
+ // }
505
+ // }
506
+ // }
507
+ // }
508
+ // : {
509
+ // output: {
510
+ // format: 'es'
511
+ // }
512
+ // }
326
513
  },
327
- // css: {
328
- // preprocessorOptions: {
329
- // sass: {
330
- // additionalData: sass ? [...sass].join('\n') : undefined
331
- // }
332
- // }
333
- // },
334
514
  ssr: {
335
515
  // Create a SSR bundle
336
- noExternal: [
337
- new RegExp(`^(?!.*(${[...builtinModules, ...serverModules].join('|')}))`)
338
- ]
516
+ external,
517
+ noExternal
339
518
  },
340
519
  define: {
341
- __BASE_URL__: `'/'`
520
+ __BASE_URL__: `'${base}'`
342
521
  }
343
522
  };
344
523
  return mergeConfig(config, vitrifyConfig);
345
524
  };
525
+ export const vitrifyDir = new URL('..', import.meta.url);