vitrify 0.20.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/app-urls.js +1 -1
- package/dist/bin/cli.js +11 -4
- package/dist/bin/dev.js +24 -37
- package/dist/frameworks/vue/fastify-ssr-plugin.js +45 -6
- package/dist/frameworks/vue/prerender.js +1 -5
- package/dist/frameworks/vue/server.js +3 -0
- package/dist/index.js +71 -95
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/quasar/index.js +227 -0
- package/dist/types/app-urls.d.ts +1 -1
- package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +11 -1
- package/dist/types/frameworks/vue/prerender.d.ts +6 -4
- 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 +20 -19
- package/src/node/app-urls.ts +2 -2
- package/src/node/bin/cli.ts +13 -6
- package/src/node/bin/dev.ts +24 -38
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +64 -27
- package/src/node/frameworks/vue/prerender.ts +9 -10
- package/src/node/frameworks/vue/server.ts +3 -0
- package/src/node/index.ts +103 -128
- 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/src/vite/vue/ssr/fastify-ssr-plugin.ts +3 -2
- package/dist/plugins/quasar.js +0 -217
- package/src/node/plugins/quasar.ts +0 -307
|
@@ -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
|