vitrify 0.21.0 → 0.23.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 (39) hide show
  1. package/dist/bin/cli.js +3 -3
  2. package/dist/bin/dev.js +26 -39
  3. package/dist/frameworks/vue/fastify-ssr-plugin.js +58 -19
  4. package/dist/frameworks/vue/prerender.js +4 -4
  5. package/dist/frameworks/vue/server.js +5 -1
  6. package/dist/hooks/index.js +1 -0
  7. package/dist/index.js +80 -94
  8. package/dist/plugins/index.js +2 -1
  9. package/dist/plugins/pinia/index.js +61 -0
  10. package/dist/plugins/quasar/index.js +226 -0
  11. package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +6 -3
  12. package/dist/types/frameworks/vue/prerender.d.ts +3 -3
  13. package/dist/types/frameworks/vue/server.d.ts +4 -4
  14. package/dist/types/hooks/index.d.ts +2 -0
  15. package/dist/types/index.d.ts +2 -2
  16. package/dist/types/plugins/index.d.ts +13 -2
  17. package/dist/types/plugins/pinia/index.d.ts +5 -0
  18. package/dist/types/plugins/{quasar.d.ts → quasar/index.d.ts} +5 -5
  19. package/dist/types/vitrify-config.d.ts +87 -12
  20. package/package.json +37 -25
  21. package/src/node/bin/cli.ts +13 -7
  22. package/src/node/bin/dev.ts +30 -41
  23. package/src/node/frameworks/vue/fastify-ssr-plugin.ts +85 -28
  24. package/src/node/frameworks/vue/prerender.ts +6 -6
  25. package/src/node/frameworks/vue/server.ts +11 -2
  26. package/src/node/hooks/index.ts +19 -0
  27. package/src/node/index.ts +114 -130
  28. package/src/node/plugins/index.ts +20 -3
  29. package/src/node/plugins/pinia/index.ts +96 -0
  30. package/src/node/plugins/quasar/index.ts +318 -0
  31. package/src/node/vitrify-config.ts +120 -21
  32. package/src/vite/fastify/server.ts +3 -0
  33. package/src/vite/vue/RootComponent.vue +1 -1
  34. package/src/vite/vue/main.ts +52 -22
  35. package/src/vite/vue/ssr/app.ts +3 -2
  36. package/src/vite/vue/ssr/entry-server.ts +22 -41
  37. package/src/vite/vue/ssr/prerender.ts +2 -2
  38. package/dist/plugins/quasar.js +0 -217
  39. package/src/node/plugins/quasar.ts +0 -307
package/dist/bin/cli.js CHANGED
@@ -20,7 +20,6 @@ cli
20
20
  const { build } = await import('./build.js');
21
21
  let appDir;
22
22
  let prerender;
23
- let onRendered;
24
23
  if (options.appDir) {
25
24
  if (options.appDir.slice(-1) !== '/')
26
25
  options.appDir += '/';
@@ -75,7 +74,7 @@ cli
75
74
  outDir: fileURLToPath(new URL('ssr/server/', baseOutDir))
76
75
  });
77
76
  ({ prerender } = await import(new URL('ssr/server/prerender.mjs', baseOutDir).pathname));
78
- const { template, manifest, render, getRoutes, onRendered } = await loadSSRAssets({
77
+ const { template, manifest, render, getRoutes, onRendered, onTemplateRendered } = await loadSSRAssets({
79
78
  mode: 'ssg',
80
79
  distDir: baseOutDir
81
80
  });
@@ -86,7 +85,8 @@ cli
86
85
  manifest,
87
86
  render,
88
87
  routes,
89
- onRendered
88
+ onRendered,
89
+ onTemplateRendered
90
90
  });
91
91
  break;
92
92
  default:
package/dist/bin/dev.js CHANGED
@@ -1,4 +1,3 @@
1
- import { searchForWorkspaceRoot } from 'vite';
2
1
  import { baseConfig } from '../index.js';
3
2
  import fastify from 'fastify';
4
3
  import { fastifySsrPlugin } from '../frameworks/vue/fastify-ssr-plugin.js';
@@ -15,7 +14,6 @@ export async function createVitrifyDevServer({ port = 3000, logLevel = 'info',
15
14
  // mode = 'csr',
16
15
  ssr, framework = 'vue', host, appDir, publicDir, base }) {
17
16
  const { getAppDir, getCliDir, getCliViteDir, getCwd } = await import('../app-urls.js');
18
- const cliDir = getCliDir();
19
17
  if (!appDir)
20
18
  appDir = getAppDir();
21
19
  let config = {};
@@ -33,46 +31,27 @@ ssr, framework = 'vue', host, appDir, publicDir, base }) {
33
31
  publicDir,
34
32
  base
35
33
  });
36
- config.logLevel = logLevel;
37
- config.define = {
38
- ...config.define,
39
- __HOST__: `'${host}'`
40
- };
41
34
  const wsPort = await getFirstOpenPort(24678);
42
35
  if (config.server?.https) {
43
36
  exitLogs.push(`[warning] HTTPS mode enabled. Visit https://{hostname}:${wsPort} to enable a security exception for HMR.`);
44
37
  }
45
- config.server = {
46
- https: config.server?.https,
47
- hmr: {
48
- protocol: config.server?.https ? 'wss' : 'ws',
49
- port: wsPort
50
- },
51
- port,
52
- // middlewareMode: mode === 'ssr' ? 'ssr' : undefined,
53
- middlewareMode: ssr ? true : false,
54
- fs: {
55
- strict: false, // https://github.com/vitejs/vite/issues/8175
56
- allow: [
57
- searchForWorkspaceRoot(process.cwd()),
58
- searchForWorkspaceRoot(fileURLToPath(appDir)),
59
- searchForWorkspaceRoot(fileURLToPath(cliDir)),
60
- fileURLToPath(appDir)
61
- ]
62
- },
63
- watch: {
64
- // During tests we edit the files too fast and sometimes chokidar
65
- // misses change events, so enforce polling for consistency
66
- usePolling: true,
67
- interval: 100
68
- },
69
- host
70
- };
71
- if (ssr)
72
- config.appType = 'custom';
73
38
  const vitrifyDevServer = await (await import('vite')).createServer({
74
39
  configFile: false,
75
- ...config
40
+ ...config,
41
+ logLevel,
42
+ define: {
43
+ ...config.define,
44
+ __HOST__: `'${host}'`
45
+ },
46
+ server: {
47
+ ...config.server,
48
+ host,
49
+ port,
50
+ hmr: {
51
+ protocol: config.server?.https ? 'wss' : 'ws',
52
+ port: wsPort
53
+ }
54
+ }
76
55
  });
77
56
  return vitrifyDevServer;
78
57
  }
@@ -96,16 +75,24 @@ ssr, framework = 'vue', host, appDir, publicDir, vite }) {
96
75
  let setup;
97
76
  let app;
98
77
  let server;
99
- let onRendered;
78
+ let onTemplateRendered;
100
79
  let vitrifyConfig;
101
80
  console.log(`Development mode: ${ssr ? ssr : 'csr'}`);
102
81
  if (ssr) {
103
82
  const entryUrl = ssr === 'fastify'
104
83
  ? fileURLToPath(new URL('src/vite/fastify/entry.ts', cliDir))
105
84
  : fileURLToPath(new URL(`src/vite/${framework}/ssr/app.ts`, cliDir));
106
- ({ setup, onRendered, vitrifyConfig } = await vite.ssrLoadModule(entryUrl));
85
+ const environment = vite.environments.ssr;
86
+ ({ setup, onTemplateRendered, vitrifyConfig } =
87
+ // @ts-expect-error missing types
88
+ await environment.runner.import(entryUrl));
89
+ // console.log(module)
90
+ // ;({ setup, onRendered, vitrifyConfig } = await vite.ssrLoadModule(entryUrl))
107
91
  app = fastify({
108
92
  logger: {
93
+ transport: {
94
+ target: '@fastify/one-line-logger'
95
+ },
109
96
  level: process.env.DEBUG
110
97
  ? 'debug'
111
98
  : process.env.PINO_LOG_LEVEL || 'info'
@@ -125,7 +112,7 @@ ssr, framework = 'vue', host, appDir, publicDir, vite }) {
125
112
  await app.register(fastifySsrPlugin, {
126
113
  appDir,
127
114
  mode: 'development',
128
- onRendered,
115
+ onTemplateRendered,
129
116
  host
130
117
  });
131
118
  }
@@ -3,6 +3,8 @@ import { readFileSync } from 'fs';
3
3
  import { fileURLToPath } from 'url';
4
4
  import { addOrReplaceAppDiv, appendToBody, appendToHead } from '../../helpers/utils.js';
5
5
  import { getAppDir } from '../../app-urls.js';
6
+ import { stringify } from 'devalue';
7
+ import stringifyObject from 'stringify-object';
6
8
  const fastifySsrPlugin = async (fastify, options) => {
7
9
  options.baseUrl = options.baseUrl || '/';
8
10
  options.mode = options.mode || process.env.MODE || import.meta.env.MODE;
@@ -36,7 +38,10 @@ const fastifySsrPlugin = async (fastify, options) => {
36
38
  let template = readFileSync(new URL('index.html', frameworkDir)).toString();
37
39
  template = await vite.transformIndexHtml(url, template);
38
40
  const entryUrl = fileURLToPath(new URL('ssr/entry-server.ts', frameworkDir));
39
- const render = (await vite.ssrLoadModule(entryUrl)).render;
41
+ const environment = vite.environments.ssr;
42
+ // @ts-expect-error missing type
43
+ const { render } = await environment.runner.import(entryUrl);
44
+ // const render = (await vite!.ssrLoadModule(entryUrl)).render
40
45
  let manifest;
41
46
  // TODO: https://github.com/vitejs/vite/issues/2282
42
47
  try {
@@ -46,11 +51,12 @@ const fastifySsrPlugin = async (fastify, options) => {
46
51
  manifest = {};
47
52
  }
48
53
  const html = await renderHtml({
49
- request: req,
50
- reply: res,
54
+ req,
55
+ res,
51
56
  url: url ?? '/',
52
57
  provide,
53
58
  onRendered: options.onRendered,
59
+ onTemplateRendered: options.onTemplateRendered,
54
60
  template,
55
61
  manifest,
56
62
  render
@@ -81,15 +87,16 @@ const fastifySsrPlugin = async (fastify, options) => {
81
87
  fastify.get(`${options.baseUrl}*`, async (req, res) => {
82
88
  const url = req.raw.url?.replace(options.baseUrl, '/');
83
89
  const provide = options.provide ? await options.provide(req, res) : {};
84
- const { template, manifest, render, onRendered } = await loadSSRAssets({
90
+ const { template, manifest, render, onRendered, onTemplateRendered } = await loadSSRAssets({
85
91
  distDir: new URL('./dist/', options.appDir)
86
92
  });
87
93
  const html = await renderHtml({
88
- request: req,
89
- reply: res,
94
+ req,
95
+ res,
90
96
  url: url ?? '/',
91
97
  provide,
92
98
  onRendered,
99
+ onTemplateRendered,
93
100
  template,
94
101
  manifest,
95
102
  render
@@ -104,19 +111,50 @@ const renderTemplate = ({ template, initialStateScript, appHtml, preloadLinks })
104
111
  return appendToHead(preloadLinks, appendToBody(initialStateScript, addOrReplaceAppDiv(appHtml, template)));
105
112
  };
106
113
  const renderHtml = async (options) => {
114
+ const ssrContextOnRendered = [];
107
115
  const ssrContext = {
108
- req: options.request,
109
- res: options.reply,
110
- provide: options.provide
116
+ req: options.req,
117
+ res: options.res,
118
+ provide: options.provide,
119
+ initialState: {},
120
+ _modules: new Set(),
121
+ _meta: {},
122
+ __qMetaList: [],
123
+ onRenderedList: ssrContextOnRendered,
124
+ onRendered: (fn) => {
125
+ ssrContextOnRendered.push(fn);
126
+ }
111
127
  };
112
128
  const onRendered = options.onRendered ?? [];
113
- const [appHtml, preloadLinks] = await options.render(options.url, options.manifest, ssrContext);
114
- if (!ssrContext.initialState)
115
- ssrContext.initialState = {};
129
+ const onTemplateRendered = options.onTemplateRendered ?? [];
130
+ const { html: appHtml, preloadLinks, app } = await options.render(options.url, options.manifest, ssrContext);
131
+ if (ssrContextOnRendered?.length) {
132
+ for (const ssrFunction of ssrContextOnRendered) {
133
+ await ssrFunction();
134
+ }
135
+ }
136
+ if (onRendered?.length) {
137
+ for (const ssrFunction of onRendered) {
138
+ await ssrFunction({ app, ssrContext });
139
+ }
140
+ }
141
+ // if (!ssrContext.initialState) ssrContext.initialState = {}
116
142
  ssrContext.initialState.provide = options.provide;
143
+ const ssrContextInitialStateStringified = {};
144
+ for (const key in ssrContext.initialState) {
145
+ if (key === 'provide') {
146
+ ssrContextInitialStateStringified[key] = JSON.stringify(ssrContext.initialState.provide);
147
+ }
148
+ else if (key === 'piniaColada') {
149
+ ssrContextInitialStateStringified[key] = JSON.stringify(ssrContext.initialState.piniaColada);
150
+ }
151
+ else {
152
+ ssrContextInitialStateStringified[key] = stringify(ssrContext.initialState[key]);
153
+ }
154
+ }
117
155
  const initialStateScript = `
118
156
  <script>
119
- __INITIAL_STATE__ = '${JSON.stringify(ssrContext.initialState)}'
157
+ __INITIAL_STATE__ = ${stringifyObject(ssrContextInitialStateStringified)}
120
158
  </script>`;
121
159
  let html = renderTemplate({
122
160
  template: options.template,
@@ -124,9 +162,9 @@ const renderHtml = async (options) => {
124
162
  initialStateScript,
125
163
  preloadLinks
126
164
  });
127
- if (onRendered?.length) {
128
- for (const ssrFunction of onRendered) {
129
- html = ssrFunction(html, ssrContext);
165
+ if (onTemplateRendered?.length) {
166
+ for (const ssrFunction of onTemplateRendered) {
167
+ html = await ssrFunction({ html, ssrContext });
130
168
  }
131
169
  }
132
170
  return html;
@@ -137,7 +175,7 @@ const loadSSRAssets = async ({ mode, distDir } = {
137
175
  const appDir = getAppDir(new URL(import.meta.url));
138
176
  const baseOutDir = distDir || new URL('dist/', appDir);
139
177
  let templatePath, manifestPath, entryServerPath;
140
- const onRenderedPath = fileURLToPath(new URL('ssr/server/virtual_vitrify-hooks.mjs', baseOutDir));
178
+ const vitrifyHooksPath = fileURLToPath(new URL('ssr/server/virtual_vitrify-hooks.mjs', baseOutDir));
141
179
  if (mode === 'ssg') {
142
180
  templatePath = fileURLToPath(new URL('static/index.html', baseOutDir));
143
181
  manifestPath = fileURLToPath(new URL('static/.vite/ssr-manifest.json', baseOutDir));
@@ -153,13 +191,14 @@ const loadSSRAssets = async ({ mode, distDir } = {
153
191
  const manifest = JSON.parse(readFileSync(manifestPath).toString());
154
192
  const entryServer = await import(entryServerPath);
155
193
  const { render, getRoutes } = entryServer;
156
- const onRendered = (await import(onRenderedPath)).onRendered;
194
+ const { onTemplateRendered, onRendered } = await import(vitrifyHooksPath);
157
195
  return {
158
196
  template,
159
197
  manifest,
160
198
  render,
161
199
  getRoutes,
162
- onRendered
200
+ onRendered,
201
+ onTemplateRendered
163
202
  };
164
203
  }
165
204
  catch (e) {
@@ -1,7 +1,7 @@
1
1
  import { existsSync, promises as fs, mkdirSync } from 'fs';
2
2
  import { routesToPaths } from '../../helpers/routes.js';
3
3
  import { renderHtml } from './fastify-ssr-plugin.js';
4
- export const prerender = async ({ outDir, template, manifest, render, routes, onRendered }) => {
4
+ export const prerender = async ({ outDir, template, manifest, render, routes, onTemplateRendered }) => {
5
5
  const promises = [];
6
6
  const paths = routesToPaths(routes).filter((i) => !i.includes(':') && !i.includes('*'));
7
7
  const beasties = new (await import('beasties')).default({
@@ -23,10 +23,10 @@ export const prerender = async ({ outDir, template, manifest, render, routes, on
23
23
  manifest,
24
24
  provide: {},
25
25
  render,
26
- request: { headers: {}, url },
27
- reply: {},
26
+ req: { headers: {}, url },
27
+ res: {},
28
28
  template,
29
- onRendered
29
+ onTemplateRendered
30
30
  });
31
31
  html = await beasties.process(html);
32
32
  promises.push(fs.writeFile(outDir + filename, html, 'utf-8'));
@@ -1,7 +1,10 @@
1
1
  import fastify from 'fastify';
2
- export const createApp = ({ onSetup, appDir, baseUrl, fastifyPlugin, onRendered, vitrifyDir, mode }) => {
2
+ export const createApp = ({ onSetup, appDir, baseUrl, fastifyPlugin, onRendered, onTemplateRendered, vitrifyDir, mode }) => {
3
3
  const app = fastify({
4
4
  logger: {
5
+ transport: {
6
+ target: '@fastify/one-line-logger'
7
+ },
5
8
  level: process.env.DEBUG ? 'debug' : process.env.PINO_LOG_LEVEL || 'info'
6
9
  }
7
10
  });
@@ -10,6 +13,7 @@ export const createApp = ({ onSetup, appDir, baseUrl, fastifyPlugin, onRendered,
10
13
  appDir,
11
14
  vitrifyDir,
12
15
  onRendered,
16
+ onTemplateRendered,
13
17
  mode
14
18
  });
15
19
  if (onSetup?.length) {
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ import { addOrReplaceTitle, appendToBody } from './helpers/utils.js';
14
14
  import Components from 'unplugin-vue-components/vite';
15
15
  import { VitePWA } from 'vite-plugin-pwa';
16
16
  import UnoCSS from 'unocss/vite';
17
+ import { searchForWorkspaceRoot } from 'vite';
17
18
  const internalServerModules = [
18
19
  'util',
19
20
  'vitrify',
@@ -29,12 +30,6 @@ const internalServerModules = [
29
30
  'ws',
30
31
  'abort-controller'
31
32
  ];
32
- const configPluginMap = {
33
- quasar: () => import('./plugins/quasar.js').then((module) => module.QuasarPlugin)
34
- };
35
- const configResolverMap = {
36
- quasar: () => import('unplugin-vue-components/resolvers').then((module) => module.QuasarResolver())
37
- };
38
33
  const manualChunkNames = [
39
34
  'prerender',
40
35
  'fastify-ssr-plugin',
@@ -42,7 +37,7 @@ const manualChunkNames = [
42
37
  'server'
43
38
  ];
44
39
  const moduleChunks = {
45
- vue: ['vue', '@vue', 'vue-router'],
40
+ vue: ['vue', '@vue', 'vue-router', 'pinia', '@pinia/colada', '@vue/devtools'],
46
41
  quasar: ['quasar'],
47
42
  atQuasar: ['@quasar']
48
43
  };
@@ -68,30 +63,6 @@ const manualChunksFn = (manualChunkList) => {
68
63
  }
69
64
  };
70
65
  };
71
- // const manualChunks: ManualChunksOption = (
72
- // id: string,
73
- // manualChunkList?: string[]
74
- // ) => {
75
- // const matchedModule = Object.entries(moduleChunks).find(
76
- // ([chunkName, moduleNames]) =>
77
- // moduleNames.some((moduleName) => id.includes(moduleName + '/'))
78
- // )
79
- // if (id.includes('vitrify/src/')) {
80
- // const name = id.split('/').at(-1)?.split('.').at(0)
81
- // if (name && manualChunkNames.includes(name)) return name
82
- // } else if (
83
- // VIRTUAL_MODULES.some((virtualModule) => id.includes(virtualModule))
84
- // ) {
85
- // return VIRTUAL_MODULES.find((name) => id.includes(name))
86
- // } else if (manualChunkList?.some((file) => id.includes(file))) {
87
- // return manualChunkList.find((file) => id.includes(file))
88
- // } else if (id.includes('node_modules')) {
89
- // if (matchedModule) {
90
- // return matchedModule[0]
91
- // }
92
- // return 'vendor'
93
- // }
94
- // }
95
66
  export const VIRTUAL_MODULES = [
96
67
  'virtual:vitrify-hooks',
97
68
  'virtual:static-imports',
@@ -168,7 +139,6 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
168
139
  const bundledConfig = await bundleConfigFile(fileURLToPath(new URL('vitrify.config.ts', appDir)));
169
140
  fs.writeFileSync(configPath + '.js', bundledConfig.code);
170
141
  rawVitrifyConfig = (await import('file://' + configPath + '.js')).default;
171
- // vitrifyConfig = (await import(configPath + '.js')).default
172
142
  fs.unlinkSync(configPath + '.js');
173
143
  }
174
144
  else {
@@ -185,8 +155,9 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
185
155
  console.log('No valid vitrify.config.(ts|js) file found.');
186
156
  throw e;
187
157
  }
188
- const localPackages = ['vue', 'vue-router', '@vue/server-renderer'];
189
- // const localPackages: string[] = []
158
+ const localPackages = [];
159
+ if (framework === 'vue')
160
+ localPackages.push('vue', 'vue-router', '@vue/server-renderer');
190
161
  const cliPackages = [];
191
162
  const packageUrls = vitrifyConfig.vitrify?.urls?.packages || {};
192
163
  await (async () => {
@@ -196,12 +167,6 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
196
167
  packageUrls[val] = new URL(`file://${pkgDir}`);
197
168
  }
198
169
  })();
199
- // await (async () => {
200
- // for (const val of cliPackages)
201
- // packageUrls[val] = getPkgJsonDir(
202
- // new URL(await resolve(val, cliDir!.href))
203
- // )
204
- // })()
205
170
  if (!productName) {
206
171
  try {
207
172
  ;
@@ -220,21 +185,33 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
220
185
  }
221
186
  const isPwa = !!vitrifyConfig.vitrify?.pwa || false;
222
187
  const frameworkPlugins = [];
223
- const resolvers = [];
224
- for (const framework of Object.keys(configPluginMap)) {
225
- if (Object.keys(vitrifyConfig).includes(framework)) {
226
- const plugin = await configPluginMap[framework]();
227
- const resolver = await configResolverMap[framework]();
228
- frameworkPlugins.push(await plugin({
188
+ if (framework === 'vue') {
189
+ frameworkPlugins.push(vuePlugin());
190
+ }
191
+ const vitrifyPlugins = [];
192
+ if (vitrifyConfig.vitrify?.plugins) {
193
+ for (const vitrifyPluginConfig of vitrifyConfig.vitrify.plugins) {
194
+ const vitrifyPlugin = await vitrifyPluginConfig.plugin({
229
195
  ssr,
230
- pwa: isPwa
231
- }));
232
- resolvers.push(resolver);
196
+ pwa: isPwa,
197
+ options: vitrifyPluginConfig.options
198
+ });
199
+ if ('plugin' in vitrifyPlugin) {
200
+ vitrifyPlugins.push(vitrifyPlugin.plugin);
201
+ }
202
+ else if ('plugins' in vitrifyPlugin) {
203
+ vitrifyPlugins.push(...vitrifyPlugin.plugins);
204
+ }
205
+ if (vitrifyPlugin.config) {
206
+ vitrifyConfig = mergeConfig(vitrifyConfig, vitrifyPlugin.config);
207
+ }
233
208
  }
234
209
  }
235
210
  let onBootHooks;
236
211
  let onRenderedHooks;
212
+ let onTemplateRenderedHooks;
237
213
  let onMountedHooks;
214
+ let onAppCreatedHooks;
238
215
  let onSetupFiles;
239
216
  let globalCss = [];
240
217
  let staticImports;
@@ -283,20 +260,22 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
283
260
  code = code
284
261
  .replace(/<style>(.*?)<\/style>/, '<style>' + css + '</style>')
285
262
  .replace(/<style lang="sass">(.*?)<\/style>/, '<style lang="sass">' + sass + '</style>');
286
- // code = code.replace(/<\/style>/, sass + '</style>')
287
263
  }
288
264
  return code;
289
265
  }
290
266
  },
291
- vuePlugin(),
292
267
  ...frameworkPlugins,
268
+ ...vitrifyPlugins,
293
269
  {
294
270
  name: 'vitrify-setup',
295
271
  enforce: 'post',
296
272
  config: (config, env) => {
297
273
  onBootHooks = config.vitrify?.hooks?.onBoot || [];
298
274
  onRenderedHooks = config.vitrify?.hooks?.onRendered || [];
275
+ onTemplateRenderedHooks =
276
+ config.vitrify?.hooks?.onTemplateRendered || [];
299
277
  onMountedHooks = config.vitrify?.hooks?.onMounted || [];
278
+ onAppCreatedHooks = config.vitrify?.hooks?.onAppCreated || [];
300
279
  onSetupFiles = config?.vitrify?.hooks?.onSetup || [];
301
280
  globalCss = config.vitrify?.globalCss || [];
302
281
  staticImports = config.vitrify?.staticImports || {};
@@ -336,6 +315,12 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
336
315
  export const onRendered = [${onRenderedHooks
337
316
  .map((fn) => `${String(fn)}`)
338
317
  .join(', ')}]
318
+ export const onTemplateRendered = [${onTemplateRenderedHooks
319
+ .map((fn) => `${String(fn)}`)
320
+ .join(', ')}]
321
+ export const onAppCreated = [${onAppCreatedHooks
322
+ .map((fn) => `${String(fn)}`)
323
+ .join(', ')}]
339
324
  export const onSetup = []
340
325
  ${onSetupFiles
341
326
  .map((url, index) => {
@@ -348,9 +333,6 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
348
333
  .replaceAll('_', '')
349
334
  .replaceAll('+', '');
350
335
  return `import ${varName} from '${new URL(url, appDir).pathname}'; onSetup.push(${varName})`;
351
- // return `import ${varName} from '${fileURLToPath(
352
- // url
353
- // )}'; onSetup.push(${varName})`
354
336
  })
355
337
  .join('\n')}`;
356
338
  }
@@ -368,9 +350,6 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
368
350
  ...globalSass.map((sass) => `@import '${sass}'`)
369
351
  ].join('\n');
370
352
  }
371
- // else if (id === 'vitrify.css') {
372
- // return `${globalCss.map((css) => `@import '${css}'`).join('\n')}`
373
- // }
374
353
  else if (id === 'virtual:vitrify-config') {
375
354
  return `export default ${JSON.stringify(vitrifyConfig)}`;
376
355
  }
@@ -395,12 +374,12 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
395
374
  }
396
375
  },
397
376
  Components({
377
+ ...vitrifyConfig.vitrify?.unpluginVueComponents,
398
378
  exclude: [
399
379
  new RegExp(`[\\/]node_modules[\\/].*[\\/]!(${serverModules.join('|')})`),
400
380
  /[\\/]\.git[\\/]/,
401
381
  /[\\/]\.nuxt[\\/]/
402
- ],
403
- resolvers
382
+ ]
404
383
  }),
405
384
  UnoCSS({
406
385
  ...vitrifyConfig.vitrify?.unocss,
@@ -448,31 +427,13 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
448
427
  else {
449
428
  entryScript = `<script type="module" src="${entry}"></script>`;
450
429
  }
451
- // html = html.replace('<!--entry-script-->', entryScript)
452
430
  html = appendToBody(entryScript, html);
453
431
  if (productName)
454
432
  html = addOrReplaceTitle(productName, html);
455
- // html = html.replace('<!--product-name-->', productName)
456
433
  return html;
457
434
  }
458
435
  }
459
436
  });
460
- // plugins.unshift({
461
- // name: 'product-name',
462
- // enforce: 'post',
463
- // config: (config: VitrifyConfig, env) => {
464
- // if (config.vitrify?.productName)
465
- // productName = config.vitrify?.productName
466
- // return
467
- // },
468
- // transformIndexHtml: {
469
- // enforce: 'post',
470
- // transform: (html) => {
471
- // html = html.replace('<!--product-name-->', productName)
472
- // return html
473
- // }
474
- // }
475
- // })
476
437
  if (debug)
477
438
  plugins.push(visualizer());
478
439
  }
@@ -486,31 +447,33 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
486
447
  '@vue/server-renderer'
487
448
  ];
488
449
  const vuePkgAliases = [];
489
- for (const pkg of vueInternalPkgs) {
490
- const specifier = pkg.split('/').at(-1);
491
- const pkgJsonPath = await findDepPkgJsonPath(pkg, fileURLToPath(appDir));
492
- if (pkgJsonPath)
450
+ if (packageUrls['vue']) {
451
+ for (const pkg of vueInternalPkgs) {
452
+ const specifier = pkg.split('/').at(-1);
453
+ const pkgJsonPath = await findDepPkgJsonPath(pkg, fileURLToPath(appDir));
454
+ if (pkgJsonPath)
455
+ vuePkgAliases.push({
456
+ find: pkg,
457
+ replacement: fileURLToPath(new URL(`./dist/${specifier}.esm-bundler.js`, `file://${pkgJsonPath}` || ''))
458
+ });
493
459
  vuePkgAliases.push({
494
- find: pkg,
495
- replacement: fileURLToPath(new URL(`./dist/${specifier}.esm-bundler.js`, `file://${pkgJsonPath}` || ''))
496
- });
460
+ find: new RegExp('^vue$'),
461
+ replacement: fileURLToPath(new URL('./dist/vue.runtime.esm-bundler.js', packageUrls['vue']))
462
+ }, {
463
+ find: new RegExp('^vue-router$'),
464
+ replacement: fileURLToPath(new URL('./dist/vue-router.esm-bundler.js', packageUrls['vue-router']))
465
+ }, ...vuePkgAliases);
466
+ }
497
467
  }
498
468
  const alias = [
499
469
  { find: 'src', replacement: fileURLToPath(srcDir) },
500
470
  { find: 'app', replacement: fileURLToPath(appDir) },
501
471
  { find: 'cwd', replacement: fileURLToPath(cwd) },
502
472
  { find: 'boot', replacement: fileURLToPath(new URL('boot/', srcDir)) },
503
- { find: 'assets', replacement: fileURLToPath(new URL('assets/', srcDir)) },
504
- {
505
- find: new RegExp('^vue$'),
506
- replacement: fileURLToPath(new URL('./dist/vue.runtime.esm-bundler.js', packageUrls['vue']))
507
- },
508
- {
509
- find: new RegExp('^vue-router$'),
510
- replacement: fileURLToPath(new URL('./dist/vue-router.esm-bundler.js', packageUrls['vue-router']))
511
- },
512
- ...vuePkgAliases
473
+ { find: 'assets', replacement: fileURLToPath(new URL('assets/', srcDir)) }
513
474
  ];
475
+ if (framework === 'vue')
476
+ alias.push(...vuePkgAliases);
514
477
  if (mode === 'development' && vitrifyConfig.vitrify?.dev?.alias)
515
478
  alias.push(...vitrifyConfig.vitrify.dev.alias);
516
479
  if (command === 'test')
@@ -579,6 +542,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
579
542
  }
580
543
  const config = {
581
544
  root: fileURLToPath(appDir),
545
+ appType: ssr ? 'custom' : 'spa',
582
546
  publicDir: fileURLToPath(publicDir),
583
547
  base,
584
548
  envDir: fileURLToPath(appDir),
@@ -615,6 +579,28 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
615
579
  __HOST__: `'localhost'`,
616
580
  __BASE_URL__: `'${base}'`,
617
581
  __IS_PWA__: `${isPwa}`
582
+ },
583
+ // environments: {
584
+ // },
585
+ server: {
586
+ https: vitrifyConfig.server?.https,
587
+ // middlewareMode: mode === 'ssr' ? 'ssr' : undefined,
588
+ middlewareMode: ssr ? true : false,
589
+ fs: {
590
+ strict: false, // https://github.com/vitejs/vite/issues/8175
591
+ allow: [
592
+ searchForWorkspaceRoot(process.cwd()),
593
+ searchForWorkspaceRoot(fileURLToPath(appDir)),
594
+ searchForWorkspaceRoot(fileURLToPath(cliDir)),
595
+ fileURLToPath(appDir)
596
+ ]
597
+ },
598
+ watch: {
599
+ // During tests we edit the files too fast and sometimes chokidar
600
+ // misses change events, so enforce polling for consistency
601
+ usePolling: true,
602
+ interval: 100
603
+ }
618
604
  }
619
605
  };
620
606
  return mergeConfig(config, vitrifyConfig);
@@ -1 +1,2 @@
1
- export {};
1
+ export * from './quasar/index.js';
2
+ export * from './pinia/index.js';