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.
- package/dist/bin/cli.js +3 -3
- package/dist/bin/dev.js +26 -39
- package/dist/frameworks/vue/fastify-ssr-plugin.js +58 -19
- package/dist/frameworks/vue/prerender.js +4 -4
- package/dist/frameworks/vue/server.js +5 -1
- package/dist/hooks/index.js +1 -0
- package/dist/index.js +80 -94
- package/dist/plugins/index.js +2 -1
- package/dist/plugins/pinia/index.js +61 -0
- package/dist/plugins/quasar/index.js +226 -0
- package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +6 -3
- package/dist/types/frameworks/vue/prerender.d.ts +3 -3
- package/dist/types/frameworks/vue/server.d.ts +4 -4
- package/dist/types/hooks/index.d.ts +2 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/plugins/index.d.ts +13 -2
- package/dist/types/plugins/pinia/index.d.ts +5 -0
- package/dist/types/plugins/{quasar.d.ts → quasar/index.d.ts} +5 -5
- package/dist/types/vitrify-config.d.ts +87 -12
- package/package.json +37 -25
- package/src/node/bin/cli.ts +13 -7
- package/src/node/bin/dev.ts +30 -41
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +85 -28
- package/src/node/frameworks/vue/prerender.ts +6 -6
- package/src/node/frameworks/vue/server.ts +11 -2
- package/src/node/hooks/index.ts +19 -0
- package/src/node/index.ts +114 -130
- package/src/node/plugins/index.ts +20 -3
- package/src/node/plugins/pinia/index.ts +96 -0
- package/src/node/plugins/quasar/index.ts +318 -0
- package/src/node/vitrify-config.ts +120 -21
- package/src/vite/fastify/server.ts +3 -0
- package/src/vite/vue/RootComponent.vue +1 -1
- package/src/vite/vue/main.ts +52 -22
- package/src/vite/vue/ssr/app.ts +3 -2
- package/src/vite/vue/ssr/entry-server.ts +22 -41
- package/src/vite/vue/ssr/prerender.ts +2 -2
- package/dist/plugins/quasar.js +0 -217
- package/src/node/plugins/quasar.ts +0 -307
|
@@ -1,28 +1,10 @@
|
|
|
1
|
-
import { type FastifyReply, type FastifyRequest } from 'fastify'
|
|
2
1
|
import { createApp } from '../main.js'
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
const initializeApp = async (
|
|
6
|
-
url: string,
|
|
7
|
-
ssrContext: Record<string, unknown>
|
|
8
|
-
) => {
|
|
9
|
-
const onRenderedList: (() => unknown)[] = []
|
|
10
|
-
Object.assign(ssrContext, {
|
|
11
|
-
_modules: new Set(),
|
|
12
|
-
_meta: {},
|
|
13
|
-
onRendered: (fn: () => unknown) => {
|
|
14
|
-
onRenderedList.push(fn)
|
|
15
|
-
}
|
|
16
|
-
})
|
|
2
|
+
import type { Render, SSRContext } from '../../../node/vitrify-config.js'
|
|
17
3
|
|
|
4
|
+
const initializeApp = async (url: string, ssrContext: SSRContext) => {
|
|
18
5
|
const { app, router, routes } = await createApp('server', ssrContext)
|
|
19
6
|
|
|
20
7
|
router.push({ path: url })
|
|
21
|
-
ssrContext.initialState = {}
|
|
22
|
-
|
|
23
|
-
onRenderedList.forEach((fn) => {
|
|
24
|
-
fn()
|
|
25
|
-
})
|
|
26
8
|
|
|
27
9
|
await router.isReady()
|
|
28
10
|
|
|
@@ -33,36 +15,35 @@ export const getRoutes = async () =>
|
|
|
33
15
|
(
|
|
34
16
|
await initializeApp('/', {
|
|
35
17
|
req: { headers: {}, url: '/' },
|
|
36
|
-
res: {}
|
|
18
|
+
res: {},
|
|
19
|
+
provide: {},
|
|
20
|
+
initialState: {},
|
|
21
|
+
onTemplateRenderedInternal: [],
|
|
22
|
+
_modules: new Set(),
|
|
23
|
+
_meta: {},
|
|
24
|
+
__qMetaList: [],
|
|
25
|
+
onRenderedList: [],
|
|
26
|
+
onRendered: (fn: () => unknown) => {
|
|
27
|
+
return
|
|
28
|
+
}
|
|
37
29
|
})
|
|
38
30
|
).routes
|
|
39
31
|
|
|
40
|
-
export async
|
|
41
|
-
url
|
|
42
|
-
manifest
|
|
43
|
-
ssrContext
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
provide: Record<string, unknown>
|
|
47
|
-
},
|
|
48
|
-
renderToString: typeof renderToStringVue
|
|
49
|
-
) {
|
|
32
|
+
export const render: Render = async (
|
|
33
|
+
url,
|
|
34
|
+
manifest,
|
|
35
|
+
ssrContext,
|
|
36
|
+
renderToString
|
|
37
|
+
) => {
|
|
50
38
|
if (!renderToString)
|
|
51
39
|
renderToString = (await import('vue/server-renderer')).renderToString
|
|
52
40
|
const { app, router } = await initializeApp(url, ssrContext)
|
|
53
41
|
|
|
54
|
-
const
|
|
55
|
-
modules?: Map<unknown, unknown>
|
|
56
|
-
transports?: Record<string, unknown>
|
|
57
|
-
__qMetaList: unknown[]
|
|
58
|
-
} = {
|
|
59
|
-
__qMetaList: []
|
|
60
|
-
}
|
|
61
|
-
const html = await renderToString(app, ctx)
|
|
42
|
+
const html = await renderToString(app, ssrContext)
|
|
62
43
|
|
|
63
|
-
const preloadLinks = renderPreloadLinks(
|
|
44
|
+
const preloadLinks = renderPreloadLinks(ssrContext.modules!, manifest)
|
|
64
45
|
|
|
65
|
-
return
|
|
46
|
+
return { html, preloadLinks, app }
|
|
66
47
|
}
|
|
67
48
|
|
|
68
49
|
function renderPreloadLinks(
|
package/dist/plugins/quasar.js
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath } from 'url';
|
|
2
|
-
import { findDepPkgJsonPath } from 'vitefu';
|
|
3
|
-
export const injectSsrContext = (html, ssrContext) => html
|
|
4
|
-
.replace(/(<html[^>]*)(>)/i, (found, start, end) => {
|
|
5
|
-
let matches;
|
|
6
|
-
matches = found.match(/\sdir\s*=\s*['"]([^'"]*)['"]/i);
|
|
7
|
-
if (matches) {
|
|
8
|
-
start = start.replace(matches[0], '');
|
|
9
|
-
}
|
|
10
|
-
matches = found.match(/\slang\s*=\s*['"]([^'"]*)['"]/i);
|
|
11
|
-
if (matches) {
|
|
12
|
-
start = start.replace(matches[0], '');
|
|
13
|
-
}
|
|
14
|
-
return `${start} ${ssrContext._meta.htmlAttrs || ''} ${end}`;
|
|
15
|
-
})
|
|
16
|
-
.replace(/(<head[^>]*)(>)/i, (_, start, end) => `${start}${end}${ssrContext._meta.headTags || ''}`)
|
|
17
|
-
.replace(/(<\/head>)/i, (_, tag) => `${ssrContext._meta.resourceStyles || ''}${ssrContext._meta.endingHeadTags || ''}${tag}`)
|
|
18
|
-
.replace(/(<body[^>]*)(>)/i, (found, start, end) => {
|
|
19
|
-
let classes = ssrContext._meta.bodyClasses || '';
|
|
20
|
-
const matches = found.match(/\sclass\s*=\s*['"]([^'"]*)['"]/i);
|
|
21
|
-
if (matches) {
|
|
22
|
-
if (matches[1].length > 0) {
|
|
23
|
-
classes += ` ${matches[1]}`;
|
|
24
|
-
}
|
|
25
|
-
start = start.replace(matches[0], '');
|
|
26
|
-
}
|
|
27
|
-
return `${start} class="${classes.trim()}" ${ssrContext._meta.bodyAttrs || ''}${end}${ssrContext._meta.bodyTags || ''}`;
|
|
28
|
-
});
|
|
29
|
-
export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
30
|
-
let plugins = [];
|
|
31
|
-
let quasarConf;
|
|
32
|
-
return [
|
|
33
|
-
{
|
|
34
|
-
name: 'vite-plugin-quasar-transform',
|
|
35
|
-
enforce: 'pre',
|
|
36
|
-
transform: (code, id, options) => {
|
|
37
|
-
code = code
|
|
38
|
-
.replaceAll('__QUASAR_SSR__', ssr ? 'true' : 'false')
|
|
39
|
-
.replaceAll('__QUASAR_SSR_SERVER__', ssr ? '(import.meta.env.SSR === true)' : 'false')
|
|
40
|
-
.replaceAll('__QUASAR_SSR_CLIENT__', ssr ? '(import.meta.env.SSR === false)' : 'false')
|
|
41
|
-
.replaceAll('__QUASAR_SSR_PWA__', ssr && pwa ? '(import.meta.env.SSR === false)' : 'false');
|
|
42
|
-
return code;
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: 'vite-plugin-quasar-setup',
|
|
47
|
-
enforce: 'pre',
|
|
48
|
-
config: async (config, env) => {
|
|
49
|
-
const { vitrify: { urls } = {}, quasar } = config;
|
|
50
|
-
const globalCss = quasar?.extras?.map((extra) => `@quasar/extras/${extra}/${extra}.css`);
|
|
51
|
-
const localPackages = ['@quasar/extras', 'quasar'];
|
|
52
|
-
// const localPackages: string[] = []
|
|
53
|
-
await (async () => {
|
|
54
|
-
for (const val of localPackages) {
|
|
55
|
-
const pkgDir = await findDepPkgJsonPath(val, fileURLToPath(config.vitrify.urls.app));
|
|
56
|
-
if (pkgDir)
|
|
57
|
-
urls.packages[val] = new URL(`file://${pkgDir}`);
|
|
58
|
-
}
|
|
59
|
-
})();
|
|
60
|
-
const onMountedHooks = [
|
|
61
|
-
async (instance) => {
|
|
62
|
-
const { proxy: { $q } } = instance;
|
|
63
|
-
if ($q.onSSRHydrated !== void 0)
|
|
64
|
-
$q.onSSRHydrated();
|
|
65
|
-
}
|
|
66
|
-
];
|
|
67
|
-
const onBootHooks = [
|
|
68
|
-
async ({ app, ssrContext, staticImports }) => {
|
|
69
|
-
// @ts-expect-error undefined
|
|
70
|
-
const quasarPlugins = await import('virtual:quasar-plugins');
|
|
71
|
-
// @ts-expect-error undefined
|
|
72
|
-
const directives = await import('virtual:quasar-directives');
|
|
73
|
-
// @ts-expect-error undefined
|
|
74
|
-
const { default: lang } = await import('virtual:quasar-lang');
|
|
75
|
-
// @ts-expect-error undefined
|
|
76
|
-
const { default: iconSet } = await import('virtual:quasar-iconSet');
|
|
77
|
-
const { default: iconMapFn } = await import(
|
|
78
|
-
// @ts-expect-error undefined
|
|
79
|
-
'virtual:quasar-iconMapFn');
|
|
80
|
-
app.use(staticImports?.Quasar, {
|
|
81
|
-
plugins: quasarPlugins,
|
|
82
|
-
directives,
|
|
83
|
-
lang,
|
|
84
|
-
iconSet,
|
|
85
|
-
config: {
|
|
86
|
-
iconMapFn
|
|
87
|
-
}
|
|
88
|
-
}, ssrContext);
|
|
89
|
-
}
|
|
90
|
-
];
|
|
91
|
-
if (quasar)
|
|
92
|
-
quasarConf = quasar;
|
|
93
|
-
if (!quasarConf.framework.lang && config.vitrify?.lang)
|
|
94
|
-
quasarConf.framework.lang = config.vitrify.lang;
|
|
95
|
-
/**
|
|
96
|
-
* Importing package.json is problematic
|
|
97
|
-
*/
|
|
98
|
-
const version = '?';
|
|
99
|
-
/**
|
|
100
|
-
* All components should have been auto-imported
|
|
101
|
-
*/
|
|
102
|
-
if (quasarConf?.framework?.plugins) {
|
|
103
|
-
if (!quasarConf.framework)
|
|
104
|
-
quasarConf.framework = {};
|
|
105
|
-
quasarConf.framework.plugins = [
|
|
106
|
-
...new Set(quasarConf.framework.plugins)
|
|
107
|
-
];
|
|
108
|
-
plugins = quasarConf?.framework.plugins;
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
vitrify: {
|
|
112
|
-
urls,
|
|
113
|
-
globalCss,
|
|
114
|
-
staticImports: {
|
|
115
|
-
quasar: ['Quasar']
|
|
116
|
-
},
|
|
117
|
-
hooks: {
|
|
118
|
-
onBoot: onBootHooks,
|
|
119
|
-
onMounted: onMountedHooks,
|
|
120
|
-
onRendered: [injectSsrContext]
|
|
121
|
-
},
|
|
122
|
-
sass: quasarConf.disableSass
|
|
123
|
-
? undefined
|
|
124
|
-
: {
|
|
125
|
-
global: ['quasar/src/css/index.sass']
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
resolve: {
|
|
129
|
-
alias: [
|
|
130
|
-
{
|
|
131
|
-
find: 'quasar/src/',
|
|
132
|
-
replacement: fileURLToPath(new URL('./src/', config.vitrify.urls.packages.quasar))
|
|
133
|
-
}
|
|
134
|
-
]
|
|
135
|
-
},
|
|
136
|
-
optimizeDeps: {
|
|
137
|
-
exclude: ['quasar']
|
|
138
|
-
},
|
|
139
|
-
define: {
|
|
140
|
-
__DEV__: process.env.NODE_ENV !== 'production' || true,
|
|
141
|
-
__QUASAR_VERSION__: `'${version}'`
|
|
142
|
-
},
|
|
143
|
-
ssr: {
|
|
144
|
-
noExternal: ['quasar']
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
name: 'quasar-virtual-modules',
|
|
151
|
-
enforce: 'pre',
|
|
152
|
-
config: async (config, env) => ({
|
|
153
|
-
resolve: {
|
|
154
|
-
alias: [
|
|
155
|
-
{
|
|
156
|
-
find: new RegExp('^quasar$'),
|
|
157
|
-
replacement: 'virtual:quasar'
|
|
158
|
-
}
|
|
159
|
-
// { find: new RegExp('^quasar$'), replacement: 'virtual:quasar' }
|
|
160
|
-
]
|
|
161
|
-
}
|
|
162
|
-
}),
|
|
163
|
-
resolveId(id) {
|
|
164
|
-
switch (id) {
|
|
165
|
-
case 'virtual:quasar-plugins':
|
|
166
|
-
return 'virtual:quasar-plugins';
|
|
167
|
-
case 'virtual:quasar-directives':
|
|
168
|
-
return 'virtual:quasar-directives';
|
|
169
|
-
case 'virtual:quasar-lang':
|
|
170
|
-
return 'virtual:quasar-lang';
|
|
171
|
-
case 'virtual:quasar-iconSet':
|
|
172
|
-
return 'virtual:quasar-iconSet';
|
|
173
|
-
case 'virtual:quasar-iconMapFn':
|
|
174
|
-
return 'virtual:quasar-iconMapFn';
|
|
175
|
-
case 'virtual:quasar':
|
|
176
|
-
return { id: 'virtual:quasar', moduleSideEffects: false };
|
|
177
|
-
default:
|
|
178
|
-
return;
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
load(id) {
|
|
182
|
-
if (id === 'virtual:quasar-plugins') {
|
|
183
|
-
return `export { ${plugins.join(',')} } from 'quasar'`;
|
|
184
|
-
}
|
|
185
|
-
else if (id === 'virtual:quasar-directives') {
|
|
186
|
-
return `export * from 'quasar/src/directives.js'`;
|
|
187
|
-
}
|
|
188
|
-
else if (id === 'virtual:quasar-lang') {
|
|
189
|
-
return `import lang from 'quasar/lang/${quasarConf?.framework?.lang || 'en-US'}';
|
|
190
|
-
export default lang`;
|
|
191
|
-
}
|
|
192
|
-
else if (id === 'virtual:quasar-iconSet') {
|
|
193
|
-
return `${typeof quasarConf.framework.iconSet === 'string'
|
|
194
|
-
? `import iconSet from 'quasar/icon-set/${quasarConf?.framework.iconSet || 'material-icons'}';
|
|
195
|
-
export default iconSet`
|
|
196
|
-
: `export default ${quasarConf.framework.iconSet
|
|
197
|
-
? JSON.stringify(quasarConf.framework.iconSet)
|
|
198
|
-
: null}`}`;
|
|
199
|
-
}
|
|
200
|
-
else if (id === 'virtual:quasar-iconMapFn') {
|
|
201
|
-
return `export default ${quasarConf?.framework.iconMapFn?.toString() ?? null}`;
|
|
202
|
-
}
|
|
203
|
-
else if (id === 'virtual:quasar') {
|
|
204
|
-
return `export * from 'quasar/src/plugins.js';
|
|
205
|
-
export * from 'quasar/src/components.js';
|
|
206
|
-
export * from 'quasar/src/composables.js';
|
|
207
|
-
export * from 'quasar/src/directives.js';
|
|
208
|
-
export * from 'quasar/src/utils.js';
|
|
209
|
-
export * from 'quasar/src/composables.js';
|
|
210
|
-
export { default as Quasar } from 'quasar/src/install-quasar.js'`;
|
|
211
|
-
}
|
|
212
|
-
return null;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
];
|
|
216
|
-
};
|
|
217
|
-
export default QuasarPlugin;
|
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from 'vite'
|
|
2
|
-
import { fileURLToPath } from 'url'
|
|
3
|
-
import type {
|
|
4
|
-
OnBootHook,
|
|
5
|
-
OnMountedHook,
|
|
6
|
-
VitrifyConfig
|
|
7
|
-
} from '../vitrify-config.js'
|
|
8
|
-
import type { VitrifyPlugin } from './index.js'
|
|
9
|
-
import { findDepPkgJsonPath } from 'vitefu'
|
|
10
|
-
import {
|
|
11
|
-
type QuasarFonts,
|
|
12
|
-
type QuasarComponents,
|
|
13
|
-
type QuasarDirectives,
|
|
14
|
-
type QuasarIconSets,
|
|
15
|
-
type QuasarPlugins,
|
|
16
|
-
type GlobalQuasarIconMapFn,
|
|
17
|
-
type QuasarIconSet
|
|
18
|
-
} from 'quasar'
|
|
19
|
-
|
|
20
|
-
export interface QuasarConf {
|
|
21
|
-
framework: {
|
|
22
|
-
components?: (keyof QuasarComponents)[]
|
|
23
|
-
directives?: (keyof QuasarDirectives)[]
|
|
24
|
-
plugins?: (keyof QuasarPlugins)[]
|
|
25
|
-
lang?: string
|
|
26
|
-
iconSet?: QuasarIconSets | QuasarIconSet
|
|
27
|
-
iconMapFn?: GlobalQuasarIconMapFn
|
|
28
|
-
}
|
|
29
|
-
extras?: (QuasarIconSets | QuasarFonts)[]
|
|
30
|
-
disableSass?: boolean
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const injectSsrContext = (
|
|
34
|
-
html: string,
|
|
35
|
-
ssrContext: Record<string, any>
|
|
36
|
-
) =>
|
|
37
|
-
html
|
|
38
|
-
.replace(/(<html[^>]*)(>)/i, (found, start, end) => {
|
|
39
|
-
let matches
|
|
40
|
-
|
|
41
|
-
matches = found.match(/\sdir\s*=\s*['"]([^'"]*)['"]/i)
|
|
42
|
-
if (matches) {
|
|
43
|
-
start = start.replace(matches[0], '')
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
matches = found.match(/\slang\s*=\s*['"]([^'"]*)['"]/i)
|
|
47
|
-
if (matches) {
|
|
48
|
-
start = start.replace(matches[0], '')
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return `${start} ${ssrContext._meta.htmlAttrs || ''} ${end}`
|
|
52
|
-
})
|
|
53
|
-
.replace(
|
|
54
|
-
/(<head[^>]*)(>)/i,
|
|
55
|
-
(_, start, end) => `${start}${end}${ssrContext._meta.headTags || ''}`
|
|
56
|
-
)
|
|
57
|
-
.replace(
|
|
58
|
-
/(<\/head>)/i,
|
|
59
|
-
(_, tag) =>
|
|
60
|
-
`${ssrContext._meta.resourceStyles || ''}${
|
|
61
|
-
ssrContext._meta.endingHeadTags || ''
|
|
62
|
-
}${tag}`
|
|
63
|
-
)
|
|
64
|
-
.replace(/(<body[^>]*)(>)/i, (found, start, end) => {
|
|
65
|
-
let classes = ssrContext._meta.bodyClasses || ''
|
|
66
|
-
|
|
67
|
-
const matches = found.match(/\sclass\s*=\s*['"]([^'"]*)['"]/i)
|
|
68
|
-
|
|
69
|
-
if (matches) {
|
|
70
|
-
if (matches[1].length > 0) {
|
|
71
|
-
classes += ` ${matches[1]}`
|
|
72
|
-
}
|
|
73
|
-
start = start.replace(matches[0], '')
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return `${start} class="${classes.trim()}" ${
|
|
77
|
-
ssrContext._meta.bodyAttrs || ''
|
|
78
|
-
}${end}${ssrContext._meta.bodyTags || ''}`
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
export const QuasarPlugin: VitrifyPlugin = async ({
|
|
82
|
-
ssr = false,
|
|
83
|
-
pwa = false
|
|
84
|
-
}): Promise<Plugin[]> => {
|
|
85
|
-
let plugins: string[] = []
|
|
86
|
-
let quasarConf: QuasarConf
|
|
87
|
-
return [
|
|
88
|
-
{
|
|
89
|
-
name: 'vite-plugin-quasar-transform',
|
|
90
|
-
enforce: 'pre',
|
|
91
|
-
transform: (code, id, options) => {
|
|
92
|
-
code = code
|
|
93
|
-
.replaceAll('__QUASAR_SSR__', ssr ? 'true' : 'false')
|
|
94
|
-
.replaceAll(
|
|
95
|
-
'__QUASAR_SSR_SERVER__',
|
|
96
|
-
ssr ? '(import.meta.env.SSR === true)' : 'false'
|
|
97
|
-
)
|
|
98
|
-
.replaceAll(
|
|
99
|
-
'__QUASAR_SSR_CLIENT__',
|
|
100
|
-
ssr ? '(import.meta.env.SSR === false)' : 'false'
|
|
101
|
-
)
|
|
102
|
-
.replaceAll(
|
|
103
|
-
'__QUASAR_SSR_PWA__',
|
|
104
|
-
ssr && pwa ? '(import.meta.env.SSR === false)' : 'false'
|
|
105
|
-
)
|
|
106
|
-
|
|
107
|
-
return code
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
name: 'vite-plugin-quasar-setup',
|
|
112
|
-
enforce: 'pre',
|
|
113
|
-
config: async (config: VitrifyConfig, env): Promise<VitrifyConfig> => {
|
|
114
|
-
const { vitrify: { urls } = {}, quasar } = config
|
|
115
|
-
|
|
116
|
-
const globalCss = quasar?.extras?.map(
|
|
117
|
-
(extra) => `@quasar/extras/${extra}/${extra}.css`
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
const localPackages = ['@quasar/extras', 'quasar']
|
|
121
|
-
// const localPackages: string[] = []
|
|
122
|
-
await (async () => {
|
|
123
|
-
for (const val of localPackages) {
|
|
124
|
-
const pkgDir = await findDepPkgJsonPath(
|
|
125
|
-
val,
|
|
126
|
-
fileURLToPath(config.vitrify!.urls!.app!)
|
|
127
|
-
)
|
|
128
|
-
if (pkgDir) urls!.packages![val] = new URL(`file://${pkgDir}`)
|
|
129
|
-
}
|
|
130
|
-
})()
|
|
131
|
-
|
|
132
|
-
const onMountedHooks: OnMountedHook[] = [
|
|
133
|
-
async (instance) => {
|
|
134
|
-
const {
|
|
135
|
-
proxy: { $q }
|
|
136
|
-
} = instance
|
|
137
|
-
if ($q.onSSRHydrated !== void 0) $q.onSSRHydrated()
|
|
138
|
-
}
|
|
139
|
-
]
|
|
140
|
-
|
|
141
|
-
const onBootHooks: OnBootHook[] = [
|
|
142
|
-
async ({ app, ssrContext, staticImports }) => {
|
|
143
|
-
// @ts-expect-error undefined
|
|
144
|
-
const quasarPlugins = await import('virtual:quasar-plugins')
|
|
145
|
-
// @ts-expect-error undefined
|
|
146
|
-
const directives = await import('virtual:quasar-directives')
|
|
147
|
-
// @ts-expect-error undefined
|
|
148
|
-
const { default: lang } = await import('virtual:quasar-lang')
|
|
149
|
-
// @ts-expect-error undefined
|
|
150
|
-
const { default: iconSet } = await import('virtual:quasar-iconSet')
|
|
151
|
-
const { default: iconMapFn } = await import(
|
|
152
|
-
// @ts-expect-error undefined
|
|
153
|
-
'virtual:quasar-iconMapFn'
|
|
154
|
-
)
|
|
155
|
-
|
|
156
|
-
app.use(
|
|
157
|
-
staticImports?.Quasar,
|
|
158
|
-
{
|
|
159
|
-
plugins: quasarPlugins,
|
|
160
|
-
directives,
|
|
161
|
-
lang,
|
|
162
|
-
iconSet,
|
|
163
|
-
config: {
|
|
164
|
-
iconMapFn
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
ssrContext
|
|
168
|
-
)
|
|
169
|
-
}
|
|
170
|
-
]
|
|
171
|
-
|
|
172
|
-
if (quasar) quasarConf = quasar
|
|
173
|
-
if (!quasarConf.framework.lang && config.vitrify?.lang)
|
|
174
|
-
quasarConf.framework.lang = config.vitrify.lang
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Importing package.json is problematic
|
|
178
|
-
*/
|
|
179
|
-
const version = '?'
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* All components should have been auto-imported
|
|
183
|
-
*/
|
|
184
|
-
if (quasarConf?.framework?.plugins) {
|
|
185
|
-
if (!quasarConf.framework) quasarConf.framework = {}
|
|
186
|
-
quasarConf.framework.plugins = [
|
|
187
|
-
...new Set(quasarConf.framework.plugins)
|
|
188
|
-
]
|
|
189
|
-
plugins = quasarConf?.framework.plugins
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return {
|
|
193
|
-
vitrify: {
|
|
194
|
-
urls,
|
|
195
|
-
globalCss,
|
|
196
|
-
staticImports: {
|
|
197
|
-
quasar: ['Quasar']
|
|
198
|
-
},
|
|
199
|
-
hooks: {
|
|
200
|
-
onBoot: onBootHooks,
|
|
201
|
-
onMounted: onMountedHooks,
|
|
202
|
-
onRendered: [injectSsrContext]
|
|
203
|
-
},
|
|
204
|
-
sass: quasarConf.disableSass
|
|
205
|
-
? undefined
|
|
206
|
-
: {
|
|
207
|
-
global: ['quasar/src/css/index.sass']
|
|
208
|
-
}
|
|
209
|
-
},
|
|
210
|
-
resolve: {
|
|
211
|
-
alias: [
|
|
212
|
-
{
|
|
213
|
-
find: 'quasar/src/',
|
|
214
|
-
replacement: fileURLToPath(
|
|
215
|
-
new URL('./src/', config.vitrify!.urls!.packages!.quasar)
|
|
216
|
-
)
|
|
217
|
-
}
|
|
218
|
-
]
|
|
219
|
-
},
|
|
220
|
-
optimizeDeps: {
|
|
221
|
-
exclude: ['quasar']
|
|
222
|
-
},
|
|
223
|
-
define: {
|
|
224
|
-
__DEV__: process.env.NODE_ENV !== 'production' || true,
|
|
225
|
-
__QUASAR_VERSION__: `'${version}'`
|
|
226
|
-
},
|
|
227
|
-
ssr: {
|
|
228
|
-
noExternal: ['quasar']
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
},
|
|
233
|
-
{
|
|
234
|
-
name: 'quasar-virtual-modules',
|
|
235
|
-
enforce: 'pre',
|
|
236
|
-
config: async (config, env) => ({
|
|
237
|
-
resolve: {
|
|
238
|
-
alias: [
|
|
239
|
-
{
|
|
240
|
-
find: new RegExp('^quasar$'),
|
|
241
|
-
replacement: 'virtual:quasar'
|
|
242
|
-
}
|
|
243
|
-
// { find: new RegExp('^quasar$'), replacement: 'virtual:quasar' }
|
|
244
|
-
]
|
|
245
|
-
}
|
|
246
|
-
}),
|
|
247
|
-
resolveId(id) {
|
|
248
|
-
switch (id) {
|
|
249
|
-
case 'virtual:quasar-plugins':
|
|
250
|
-
return 'virtual:quasar-plugins'
|
|
251
|
-
case 'virtual:quasar-directives':
|
|
252
|
-
return 'virtual:quasar-directives'
|
|
253
|
-
case 'virtual:quasar-lang':
|
|
254
|
-
return 'virtual:quasar-lang'
|
|
255
|
-
case 'virtual:quasar-iconSet':
|
|
256
|
-
return 'virtual:quasar-iconSet'
|
|
257
|
-
case 'virtual:quasar-iconMapFn':
|
|
258
|
-
return 'virtual:quasar-iconMapFn'
|
|
259
|
-
case 'virtual:quasar':
|
|
260
|
-
return { id: 'virtual:quasar', moduleSideEffects: false }
|
|
261
|
-
default:
|
|
262
|
-
return
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
|
-
load(id) {
|
|
266
|
-
if (id === 'virtual:quasar-plugins') {
|
|
267
|
-
return `export { ${plugins.join(',')} } from 'quasar'`
|
|
268
|
-
} else if (id === 'virtual:quasar-directives') {
|
|
269
|
-
return `export * from 'quasar/src/directives.js'`
|
|
270
|
-
} else if (id === 'virtual:quasar-lang') {
|
|
271
|
-
return `import lang from 'quasar/lang/${
|
|
272
|
-
quasarConf?.framework?.lang || 'en-US'
|
|
273
|
-
}';
|
|
274
|
-
export default lang`
|
|
275
|
-
} else if (id === 'virtual:quasar-iconSet') {
|
|
276
|
-
return `${
|
|
277
|
-
typeof quasarConf.framework.iconSet === 'string'
|
|
278
|
-
? `import iconSet from 'quasar/icon-set/${
|
|
279
|
-
quasarConf?.framework.iconSet || 'material-icons'
|
|
280
|
-
}';
|
|
281
|
-
export default iconSet`
|
|
282
|
-
: `export default ${
|
|
283
|
-
quasarConf.framework.iconSet
|
|
284
|
-
? JSON.stringify(quasarConf.framework.iconSet)
|
|
285
|
-
: null
|
|
286
|
-
}`
|
|
287
|
-
}`
|
|
288
|
-
} else if (id === 'virtual:quasar-iconMapFn') {
|
|
289
|
-
return `export default ${
|
|
290
|
-
quasarConf?.framework.iconMapFn?.toString() ?? null
|
|
291
|
-
}`
|
|
292
|
-
} else if (id === 'virtual:quasar') {
|
|
293
|
-
return `export * from 'quasar/src/plugins.js';
|
|
294
|
-
export * from 'quasar/src/components.js';
|
|
295
|
-
export * from 'quasar/src/composables.js';
|
|
296
|
-
export * from 'quasar/src/directives.js';
|
|
297
|
-
export * from 'quasar/src/utils.js';
|
|
298
|
-
export * from 'quasar/src/composables.js';
|
|
299
|
-
export { default as Quasar } from 'quasar/src/install-quasar.js'`
|
|
300
|
-
}
|
|
301
|
-
return null
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
]
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
export default QuasarPlugin
|