vitrify 0.21.0 → 0.22.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.
- package/dist/bin/dev.js +24 -37
- package/dist/frameworks/vue/fastify-ssr-plugin.js +4 -1
- package/dist/frameworks/vue/server.js +3 -0
- package/dist/index.js +68 -93
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/quasar/index.js +227 -0
- package/dist/types/plugins/index.d.ts +12 -2
- package/dist/types/plugins/{quasar.d.ts → quasar/index.d.ts} +3 -3
- package/dist/types/vitrify-config.d.ts +15 -2
- package/package.json +5 -4
- package/src/node/bin/dev.ts +24 -38
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +4 -1
- package/src/node/frameworks/vue/server.ts +3 -0
- package/src/node/index.ts +98 -126
- package/src/node/plugins/index.ts +19 -3
- package/src/node/plugins/quasar/index.ts +320 -0
- package/src/node/vitrify-config.ts +17 -3
- package/src/vite/fastify/server.ts +3 -0
- package/dist/plugins/quasar.js +0 -217
- package/src/node/plugins/quasar.ts +0 -307
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
|
}
|
|
@@ -103,9 +82,17 @@ ssr, framework = 'vue', host, appDir, publicDir, vite }) {
|
|
|
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
|
-
|
|
85
|
+
const environment = vite.environments.ssr;
|
|
86
|
+
({ setup, onRendered, 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'
|
|
@@ -36,7 +36,10 @@ const fastifySsrPlugin = async (fastify, options) => {
|
|
|
36
36
|
let template = readFileSync(new URL('index.html', frameworkDir)).toString();
|
|
37
37
|
template = await vite.transformIndexHtml(url, template);
|
|
38
38
|
const entryUrl = fileURLToPath(new URL('ssr/entry-server.ts', frameworkDir));
|
|
39
|
-
const
|
|
39
|
+
const environment = vite.environments.ssr;
|
|
40
|
+
// @ts-expect-error missing type
|
|
41
|
+
const { render } = await environment.runner.import(entryUrl);
|
|
42
|
+
// const render = (await vite!.ssrLoadModule(entryUrl)).render
|
|
40
43
|
let manifest;
|
|
41
44
|
// TODO: https://github.com/vitejs/vite/issues/2282
|
|
42
45
|
try {
|
|
@@ -2,6 +2,9 @@ import fastify from 'fastify';
|
|
|
2
2
|
export const createApp = ({ onSetup, appDir, baseUrl, fastifyPlugin, onRendered, 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
|
});
|
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',
|
|
@@ -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 = [
|
|
189
|
-
|
|
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,16 +185,26 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
220
185
|
}
|
|
221
186
|
const isPwa = !!vitrifyConfig.vitrify?.pwa || false;
|
|
222
187
|
const frameworkPlugins = [];
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -283,13 +258,12 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
283
258
|
code = code
|
|
284
259
|
.replace(/<style>(.*?)<\/style>/, '<style>' + css + '</style>')
|
|
285
260
|
.replace(/<style lang="sass">(.*?)<\/style>/, '<style lang="sass">' + sass + '</style>');
|
|
286
|
-
// code = code.replace(/<\/style>/, sass + '</style>')
|
|
287
261
|
}
|
|
288
262
|
return code;
|
|
289
263
|
}
|
|
290
264
|
},
|
|
291
|
-
vuePlugin(),
|
|
292
265
|
...frameworkPlugins,
|
|
266
|
+
...vitrifyPlugins,
|
|
293
267
|
{
|
|
294
268
|
name: 'vitrify-setup',
|
|
295
269
|
enforce: 'post',
|
|
@@ -348,9 +322,6 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
348
322
|
.replaceAll('_', '')
|
|
349
323
|
.replaceAll('+', '');
|
|
350
324
|
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
325
|
})
|
|
355
326
|
.join('\n')}`;
|
|
356
327
|
}
|
|
@@ -368,9 +339,6 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
368
339
|
...globalSass.map((sass) => `@import '${sass}'`)
|
|
369
340
|
].join('\n');
|
|
370
341
|
}
|
|
371
|
-
// else if (id === 'vitrify.css') {
|
|
372
|
-
// return `${globalCss.map((css) => `@import '${css}'`).join('\n')}`
|
|
373
|
-
// }
|
|
374
342
|
else if (id === 'virtual:vitrify-config') {
|
|
375
343
|
return `export default ${JSON.stringify(vitrifyConfig)}`;
|
|
376
344
|
}
|
|
@@ -395,12 +363,12 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
395
363
|
}
|
|
396
364
|
},
|
|
397
365
|
Components({
|
|
366
|
+
...vitrifyConfig.vitrify?.unpluginVueComponents,
|
|
398
367
|
exclude: [
|
|
399
368
|
new RegExp(`[\\/]node_modules[\\/].*[\\/]!(${serverModules.join('|')})`),
|
|
400
369
|
/[\\/]\.git[\\/]/,
|
|
401
370
|
/[\\/]\.nuxt[\\/]/
|
|
402
|
-
]
|
|
403
|
-
resolvers
|
|
371
|
+
]
|
|
404
372
|
}),
|
|
405
373
|
UnoCSS({
|
|
406
374
|
...vitrifyConfig.vitrify?.unocss,
|
|
@@ -448,31 +416,13 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
448
416
|
else {
|
|
449
417
|
entryScript = `<script type="module" src="${entry}"></script>`;
|
|
450
418
|
}
|
|
451
|
-
// html = html.replace('<!--entry-script-->', entryScript)
|
|
452
419
|
html = appendToBody(entryScript, html);
|
|
453
420
|
if (productName)
|
|
454
421
|
html = addOrReplaceTitle(productName, html);
|
|
455
|
-
// html = html.replace('<!--product-name-->', productName)
|
|
456
422
|
return html;
|
|
457
423
|
}
|
|
458
424
|
}
|
|
459
425
|
});
|
|
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
426
|
if (debug)
|
|
477
427
|
plugins.push(visualizer());
|
|
478
428
|
}
|
|
@@ -486,31 +436,33 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
486
436
|
'@vue/server-renderer'
|
|
487
437
|
];
|
|
488
438
|
const vuePkgAliases = [];
|
|
489
|
-
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
|
|
439
|
+
if (packageUrls['vue']) {
|
|
440
|
+
for (const pkg of vueInternalPkgs) {
|
|
441
|
+
const specifier = pkg.split('/').at(-1);
|
|
442
|
+
const pkgJsonPath = await findDepPkgJsonPath(pkg, fileURLToPath(appDir));
|
|
443
|
+
if (pkgJsonPath)
|
|
444
|
+
vuePkgAliases.push({
|
|
445
|
+
find: pkg,
|
|
446
|
+
replacement: fileURLToPath(new URL(`./dist/${specifier}.esm-bundler.js`, `file://${pkgJsonPath}` || ''))
|
|
447
|
+
});
|
|
493
448
|
vuePkgAliases.push({
|
|
494
|
-
find:
|
|
495
|
-
replacement: fileURLToPath(new URL(
|
|
496
|
-
}
|
|
449
|
+
find: new RegExp('^vue$'),
|
|
450
|
+
replacement: fileURLToPath(new URL('./dist/vue.runtime.esm-bundler.js', packageUrls['vue']))
|
|
451
|
+
}, {
|
|
452
|
+
find: new RegExp('^vue-router$'),
|
|
453
|
+
replacement: fileURLToPath(new URL('./dist/vue-router.esm-bundler.js', packageUrls['vue-router']))
|
|
454
|
+
}, ...vuePkgAliases);
|
|
455
|
+
}
|
|
497
456
|
}
|
|
498
457
|
const alias = [
|
|
499
458
|
{ find: 'src', replacement: fileURLToPath(srcDir) },
|
|
500
459
|
{ find: 'app', replacement: fileURLToPath(appDir) },
|
|
501
460
|
{ find: 'cwd', replacement: fileURLToPath(cwd) },
|
|
502
461
|
{ 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
|
|
462
|
+
{ find: 'assets', replacement: fileURLToPath(new URL('assets/', srcDir)) }
|
|
513
463
|
];
|
|
464
|
+
if (framework === 'vue')
|
|
465
|
+
alias.push(...vuePkgAliases);
|
|
514
466
|
if (mode === 'development' && vitrifyConfig.vitrify?.dev?.alias)
|
|
515
467
|
alias.push(...vitrifyConfig.vitrify.dev.alias);
|
|
516
468
|
if (command === 'test')
|
|
@@ -579,6 +531,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
579
531
|
}
|
|
580
532
|
const config = {
|
|
581
533
|
root: fileURLToPath(appDir),
|
|
534
|
+
appType: ssr ? 'custom' : 'spa',
|
|
582
535
|
publicDir: fileURLToPath(publicDir),
|
|
583
536
|
base,
|
|
584
537
|
envDir: fileURLToPath(appDir),
|
|
@@ -615,6 +568,28 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
615
568
|
__HOST__: `'localhost'`,
|
|
616
569
|
__BASE_URL__: `'${base}'`,
|
|
617
570
|
__IS_PWA__: `${isPwa}`
|
|
571
|
+
},
|
|
572
|
+
// environments: {
|
|
573
|
+
// },
|
|
574
|
+
server: {
|
|
575
|
+
https: vitrifyConfig.server?.https,
|
|
576
|
+
// middlewareMode: mode === 'ssr' ? 'ssr' : undefined,
|
|
577
|
+
middlewareMode: ssr ? true : false,
|
|
578
|
+
fs: {
|
|
579
|
+
strict: false, // https://github.com/vitejs/vite/issues/8175
|
|
580
|
+
allow: [
|
|
581
|
+
searchForWorkspaceRoot(process.cwd()),
|
|
582
|
+
searchForWorkspaceRoot(fileURLToPath(appDir)),
|
|
583
|
+
searchForWorkspaceRoot(fileURLToPath(cliDir)),
|
|
584
|
+
fileURLToPath(appDir)
|
|
585
|
+
]
|
|
586
|
+
},
|
|
587
|
+
watch: {
|
|
588
|
+
// During tests we edit the files too fast and sometimes chokidar
|
|
589
|
+
// misses change events, so enforce polling for consistency
|
|
590
|
+
usePolling: true,
|
|
591
|
+
interval: 100
|
|
592
|
+
}
|
|
618
593
|
}
|
|
619
594
|
};
|
|
620
595
|
return mergeConfig(config, vitrifyConfig);
|
package/dist/plugins/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './quasar/index.js';
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
import { findDepPkgJsonPath } from 'vitefu';
|
|
3
|
+
import { QuasarResolver } from 'unplugin-vue-components/resolvers';
|
|
4
|
+
export const injectSsrContext = (html, ssrContext) => html
|
|
5
|
+
.replace(/(<html[^>]*)(>)/i, (found, start, end) => {
|
|
6
|
+
let matches;
|
|
7
|
+
matches = found.match(/\sdir\s*=\s*['"]([^'"]*)['"]/i);
|
|
8
|
+
if (matches) {
|
|
9
|
+
start = start.replace(matches[0], '');
|
|
10
|
+
}
|
|
11
|
+
matches = found.match(/\slang\s*=\s*['"]([^'"]*)['"]/i);
|
|
12
|
+
if (matches) {
|
|
13
|
+
start = start.replace(matches[0], '');
|
|
14
|
+
}
|
|
15
|
+
return `${start} ${ssrContext._meta.htmlAttrs || ''} ${end}`;
|
|
16
|
+
})
|
|
17
|
+
.replace(/(<head[^>]*)(>)/i, (_, start, end) => `${start}${end}${ssrContext._meta.headTags || ''}`)
|
|
18
|
+
.replace(/(<\/head>)/i, (_, tag) => `${ssrContext._meta.resourceStyles || ''}${ssrContext._meta.endingHeadTags || ''}${tag}`)
|
|
19
|
+
.replace(/(<body[^>]*)(>)/i, (found, start, end) => {
|
|
20
|
+
let classes = ssrContext._meta.bodyClasses || '';
|
|
21
|
+
const matches = found.match(/\sclass\s*=\s*['"]([^'"]*)['"]/i);
|
|
22
|
+
if (matches) {
|
|
23
|
+
if (matches[1].length > 0) {
|
|
24
|
+
classes += ` ${matches[1]}`;
|
|
25
|
+
}
|
|
26
|
+
start = start.replace(matches[0], '');
|
|
27
|
+
}
|
|
28
|
+
return `${start} class="${classes.trim()}" ${ssrContext._meta.bodyAttrs || ''}${end}${ssrContext._meta.bodyTags || ''}`;
|
|
29
|
+
});
|
|
30
|
+
export const QuasarPlugin = async ({ ssr = false, pwa = false, options }) => {
|
|
31
|
+
let plugins = [];
|
|
32
|
+
const quasarConf = options;
|
|
33
|
+
return {
|
|
34
|
+
plugins: [
|
|
35
|
+
{
|
|
36
|
+
name: 'vite-plugin-quasar-transform',
|
|
37
|
+
enforce: 'pre',
|
|
38
|
+
transform: (code, id, options) => {
|
|
39
|
+
code = code
|
|
40
|
+
.replaceAll('__QUASAR_SSR__', ssr ? 'true' : 'false')
|
|
41
|
+
.replaceAll('__QUASAR_SSR_SERVER__', ssr ? '(import.meta.env.SSR === true)' : 'false')
|
|
42
|
+
.replaceAll('__QUASAR_SSR_CLIENT__', ssr ? '(import.meta.env.SSR === false)' : 'false')
|
|
43
|
+
.replaceAll('__QUASAR_SSR_PWA__', ssr && pwa ? '(import.meta.env.SSR === false)' : 'false');
|
|
44
|
+
return code;
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'vite-plugin-quasar-setup',
|
|
49
|
+
enforce: 'pre',
|
|
50
|
+
config: async (config, env) => {
|
|
51
|
+
const { vitrify: { urls } = {} } = config;
|
|
52
|
+
// if (quasar) quasarConf = quasar
|
|
53
|
+
if (!quasarConf.framework.lang && config.vitrify?.lang)
|
|
54
|
+
quasarConf.framework.lang = config.vitrify.lang;
|
|
55
|
+
const globalCss = quasarConf?.extras?.map((extra) => `@quasar/extras/${extra}/${extra}.css`);
|
|
56
|
+
const localPackages = ['@quasar/extras', 'quasar'];
|
|
57
|
+
// const localPackages: string[] = []
|
|
58
|
+
await (async () => {
|
|
59
|
+
for (const val of localPackages) {
|
|
60
|
+
const pkgDir = await findDepPkgJsonPath(val, fileURLToPath(config.vitrify.urls.app));
|
|
61
|
+
if (pkgDir)
|
|
62
|
+
urls.packages[val] = new URL(`file://${pkgDir}`);
|
|
63
|
+
}
|
|
64
|
+
})();
|
|
65
|
+
const onMountedHooks = [
|
|
66
|
+
async (instance) => {
|
|
67
|
+
const { proxy: { $q } } = instance;
|
|
68
|
+
if ($q.onSSRHydrated !== void 0)
|
|
69
|
+
$q.onSSRHydrated();
|
|
70
|
+
}
|
|
71
|
+
];
|
|
72
|
+
const onBootHooks = [
|
|
73
|
+
async ({ app, ssrContext, staticImports }) => {
|
|
74
|
+
// @ts-expect-error undefined
|
|
75
|
+
const quasarPlugins = await import('virtual:quasar-plugins');
|
|
76
|
+
// @ts-expect-error undefined
|
|
77
|
+
const directives = await import('virtual:quasar-directives');
|
|
78
|
+
// @ts-expect-error undefined
|
|
79
|
+
const { default: lang } = await import('virtual:quasar-lang');
|
|
80
|
+
const { default: iconSet } = await import(
|
|
81
|
+
// @ts-expect-error undefined
|
|
82
|
+
'virtual:quasar-iconSet');
|
|
83
|
+
const { default: iconMapFn } = await import(
|
|
84
|
+
// @ts-expect-error undefined
|
|
85
|
+
'virtual:quasar-iconMapFn');
|
|
86
|
+
app.use(staticImports?.Quasar, {
|
|
87
|
+
plugins: quasarPlugins,
|
|
88
|
+
directives,
|
|
89
|
+
lang,
|
|
90
|
+
iconSet,
|
|
91
|
+
config: {
|
|
92
|
+
iconMapFn
|
|
93
|
+
}
|
|
94
|
+
}, ssrContext);
|
|
95
|
+
}
|
|
96
|
+
];
|
|
97
|
+
/**
|
|
98
|
+
* Importing package.json is problematic
|
|
99
|
+
*/
|
|
100
|
+
const version = '?';
|
|
101
|
+
/**
|
|
102
|
+
* All components should have been auto-imported
|
|
103
|
+
*/
|
|
104
|
+
if (quasarConf?.framework?.plugins) {
|
|
105
|
+
if (!quasarConf.framework)
|
|
106
|
+
quasarConf.framework = {};
|
|
107
|
+
quasarConf.framework.plugins = [
|
|
108
|
+
...new Set(quasarConf.framework.plugins)
|
|
109
|
+
];
|
|
110
|
+
plugins = quasarConf?.framework.plugins;
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
vitrify: {
|
|
114
|
+
urls,
|
|
115
|
+
globalCss,
|
|
116
|
+
staticImports: {
|
|
117
|
+
quasar: ['Quasar']
|
|
118
|
+
},
|
|
119
|
+
hooks: {
|
|
120
|
+
onBoot: onBootHooks,
|
|
121
|
+
onMounted: onMountedHooks,
|
|
122
|
+
onRendered: [injectSsrContext]
|
|
123
|
+
},
|
|
124
|
+
sass: quasarConf.disableSass
|
|
125
|
+
? undefined
|
|
126
|
+
: {
|
|
127
|
+
global: ['quasar/src/css/index.sass']
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
resolve: {
|
|
131
|
+
alias: [
|
|
132
|
+
{
|
|
133
|
+
find: 'quasar/src/',
|
|
134
|
+
replacement: fileURLToPath(new URL('./src/', config.vitrify.urls.packages.quasar))
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
},
|
|
138
|
+
optimizeDeps: {
|
|
139
|
+
exclude: ['quasar']
|
|
140
|
+
},
|
|
141
|
+
define: {
|
|
142
|
+
__DEV__: process.env.NODE_ENV !== 'production' || true,
|
|
143
|
+
__QUASAR_VERSION__: `'${version}'`
|
|
144
|
+
},
|
|
145
|
+
ssr: {
|
|
146
|
+
noExternal: ['quasar']
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: 'quasar-virtual-modules',
|
|
153
|
+
enforce: 'pre',
|
|
154
|
+
config: async (config, env) => ({
|
|
155
|
+
resolve: {
|
|
156
|
+
alias: [
|
|
157
|
+
{
|
|
158
|
+
find: new RegExp('^quasar$'),
|
|
159
|
+
replacement: 'virtual:quasar'
|
|
160
|
+
}
|
|
161
|
+
// { find: new RegExp('^quasar$'), replacement: 'virtual:quasar' }
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
}),
|
|
165
|
+
resolveId(id) {
|
|
166
|
+
switch (id) {
|
|
167
|
+
case 'virtual:quasar-plugins':
|
|
168
|
+
return 'virtual:quasar-plugins';
|
|
169
|
+
case 'virtual:quasar-directives':
|
|
170
|
+
return 'virtual:quasar-directives';
|
|
171
|
+
case 'virtual:quasar-lang':
|
|
172
|
+
return 'virtual:quasar-lang';
|
|
173
|
+
case 'virtual:quasar-iconSet':
|
|
174
|
+
return 'virtual:quasar-iconSet';
|
|
175
|
+
case 'virtual:quasar-iconMapFn':
|
|
176
|
+
return 'virtual:quasar-iconMapFn';
|
|
177
|
+
case 'virtual:quasar':
|
|
178
|
+
return { id: 'virtual:quasar', moduleSideEffects: false };
|
|
179
|
+
default:
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
load(id) {
|
|
184
|
+
if (id === 'virtual:quasar-plugins') {
|
|
185
|
+
return `export { ${plugins.join(',')} } from 'quasar'`;
|
|
186
|
+
}
|
|
187
|
+
else if (id === 'virtual:quasar-directives') {
|
|
188
|
+
return `export * from 'quasar/src/directives.js'`;
|
|
189
|
+
}
|
|
190
|
+
else if (id === 'virtual:quasar-lang') {
|
|
191
|
+
return `import lang from 'quasar/lang/${quasarConf?.framework?.lang || 'en-US'}';
|
|
192
|
+
export default lang`;
|
|
193
|
+
}
|
|
194
|
+
else if (id === 'virtual:quasar-iconSet') {
|
|
195
|
+
return `${typeof quasarConf.framework.iconSet === 'string'
|
|
196
|
+
? `import iconSet from 'quasar/icon-set/${quasarConf?.framework.iconSet || 'material-icons'}';
|
|
197
|
+
export default iconSet`
|
|
198
|
+
: `export default ${quasarConf.framework.iconSet
|
|
199
|
+
? JSON.stringify(quasarConf.framework.iconSet)
|
|
200
|
+
: null}`}`;
|
|
201
|
+
}
|
|
202
|
+
else if (id === 'virtual:quasar-iconMapFn') {
|
|
203
|
+
return `export default ${quasarConf?.framework.iconMapFn?.toString() ?? null}`;
|
|
204
|
+
}
|
|
205
|
+
else if (id === 'virtual:quasar') {
|
|
206
|
+
return `export * from 'quasar/src/plugins.js';
|
|
207
|
+
export * from 'quasar/src/components.js';
|
|
208
|
+
export * from 'quasar/src/composables.js';
|
|
209
|
+
export * from 'quasar/src/directives.js';
|
|
210
|
+
export * from 'quasar/src/utils.js';
|
|
211
|
+
export * from 'quasar/src/composables.js';
|
|
212
|
+
export { default as Quasar } from 'quasar/src/install-quasar.js'`;
|
|
213
|
+
}
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
],
|
|
218
|
+
config: {
|
|
219
|
+
vitrify: {
|
|
220
|
+
unpluginVueComponents: {
|
|
221
|
+
resolvers: [QuasarResolver()]
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
export default QuasarPlugin;
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
-
|
|
2
|
+
import { VitrifyConfig } from '../vitrify-config.js';
|
|
3
|
+
type VitrifyPluginReturnType = {
|
|
4
|
+
plugin: Plugin;
|
|
5
|
+
config?: Partial<VitrifyConfig>;
|
|
6
|
+
} | {
|
|
7
|
+
plugins: Plugin[];
|
|
8
|
+
config?: Partial<VitrifyConfig>;
|
|
9
|
+
};
|
|
10
|
+
export type VitrifyPlugin<Options> = ({ ssr, pwa, mode, command, options }: {
|
|
3
11
|
ssr?: 'server' | 'client' | 'ssg' | 'fastify' | false;
|
|
4
12
|
pwa?: boolean;
|
|
5
13
|
mode?: 'production' | 'development';
|
|
6
14
|
command?: 'build' | 'dev' | 'test';
|
|
7
|
-
|
|
15
|
+
options: Options;
|
|
16
|
+
}) => Promise<VitrifyPluginReturnType> | VitrifyPluginReturnType;
|
|
17
|
+
export * from './quasar/index.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { VitrifyPlugin } from '
|
|
1
|
+
import type { VitrifyPlugin } from '../index.js';
|
|
2
2
|
import { type QuasarFonts, type QuasarComponents, type QuasarDirectives, type QuasarIconSets, type QuasarPlugins, type GlobalQuasarIconMapFn, type QuasarIconSet } from 'quasar';
|
|
3
|
-
export interface
|
|
3
|
+
export interface QuasarPluginOptions {
|
|
4
4
|
framework: {
|
|
5
5
|
components?: (keyof QuasarComponents)[];
|
|
6
6
|
directives?: (keyof QuasarDirectives)[];
|
|
@@ -13,5 +13,5 @@ export interface QuasarConf {
|
|
|
13
13
|
disableSass?: boolean;
|
|
14
14
|
}
|
|
15
15
|
export declare const injectSsrContext: (html: string, ssrContext: Record<string, any>) => string;
|
|
16
|
-
export declare const QuasarPlugin: VitrifyPlugin
|
|
16
|
+
export declare const QuasarPlugin: VitrifyPlugin<QuasarPluginOptions>;
|
|
17
17
|
export default QuasarPlugin;
|