vitrify 0.6.17 → 0.7.1

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.
@@ -1,22 +1,13 @@
1
- import { readFileSync } from 'fs'
2
1
  import type { Plugin } from 'vite'
3
2
  import { resolvePackageData } from 'vite'
4
3
  import Components from 'unplugin-vue-components/vite'
5
- // import { prepareQuasarConf } from './quasar-conf-file.js'
6
4
  import type {
7
- BootFunction,
8
5
  OnBootHook,
9
6
  OnMountedHook,
10
7
  VitrifyConfig
11
8
  } from '../vitrify-config.js'
12
- // import { quasarDir as defaultQuasarDir } from '../app-urls.js'
13
- // import { QuasarResolver } from '../resolver.js';
14
9
  import { QuasarResolver } from 'unplugin-vue-components/resolvers'
15
10
  import type { VitrifyPlugin } from './index.js'
16
- import { getPkgJsonDir, resolve } from '../app-urls.js'
17
-
18
- // import { resolve } from 'import-meta-resolve'
19
-
20
11
  export interface QuasarConf {
21
12
  ctx: Record<string, any>
22
13
  css: string[]
@@ -25,6 +16,7 @@ export interface QuasarConf {
25
16
  components?: string[]
26
17
  directives?: string[]
27
18
  plugins?: string[]
19
+ lang?: string
28
20
  }
29
21
  animations: string[]
30
22
  extras: string[]
@@ -83,6 +75,7 @@ export const QuasarPlugin: VitrifyPlugin = async ({
83
75
  pwa = false
84
76
  }): Promise<Plugin[]> => {
85
77
  let plugins: string[] = []
78
+ let quasarConf: QuasarConf
86
79
  return [
87
80
  Components({
88
81
  resolvers: [QuasarResolver()]
@@ -148,54 +141,25 @@ export const QuasarPlugin: VitrifyPlugin = async ({
148
141
  const quasarPlugins = await import('virtual:quasar-plugins')
149
142
  // @ts-ignore
150
143
  const directives = await import('virtual:quasar-directives')
144
+ // @ts-ignore
145
+ const { default: lang } = await import('virtual:quasar-lang')
151
146
 
152
147
  app.use(
153
148
  staticImports?.Quasar,
154
149
  {
155
150
  plugins: quasarPlugins,
156
- directives
151
+ directives,
152
+ lang
157
153
  },
158
154
  ssrContext
159
155
  )
160
156
  }
161
157
  ]
162
158
 
163
- return {
164
- vitrify: {
165
- urls,
166
- globalCss,
167
- staticImports: {
168
- quasar: ['Quasar']
169
- },
170
- hooks: {
171
- onBoot: onBootHooks,
172
- onMounted: onMountedHooks,
173
- onRendered: [injectSsrContext]
174
- },
175
- sass: {
176
- global: ['quasar/src/css/index.sass']
177
- // additionalData: [`@import 'quasar/src/css/index.sass'`]
178
- }
179
- }
180
- }
181
- }
182
- },
183
- {
184
- name: 'vite-plugin-quasar',
185
- enforce: 'post',
186
- config: async (config: VitrifyConfig, env) => {
187
- const { quasar: quasarConf, vitrify: { urls } = {} } = config
159
+ if (quasar) quasarConf = quasar
160
+ if (!quasarConf.framework.lang && config.vitrify?.lang)
161
+ quasarConf.framework.lang = config.vitrify.lang
188
162
 
189
- // const quasarPkgJsonPath = new URL(
190
- // 'package.json',
191
- // urls?.packages?.quasar
192
- // ).pathname
193
- // const { version } = JSON.parse(
194
- // readFileSync(quasarPkgJsonPath, { encoding: 'utf-8' })
195
- // )
196
- // const { version } = await import('quasar/package.json', {
197
- // assert: { type: 'json' }
198
- // })
199
163
  /**
200
164
  * Importing package.json is problematic
201
165
  */
@@ -213,53 +177,24 @@ export const QuasarPlugin: VitrifyPlugin = async ({
213
177
  }
214
178
 
215
179
  return {
216
- // build: {
217
- // rollupOptions: {
218
- // treeshake: {
219
- // moduleSideEffects: 'no-external'
220
- // }
221
- // }
222
- // },
180
+ vitrify: {
181
+ urls,
182
+ globalCss,
183
+ staticImports: {
184
+ quasar: ['Quasar']
185
+ },
186
+ hooks: {
187
+ onBoot: onBootHooks,
188
+ onMounted: onMountedHooks,
189
+ onRendered: [injectSsrContext]
190
+ },
191
+ sass: {
192
+ global: ['quasar/src/css/index.sass']
193
+ // additionalData: [`@import 'quasar/src/css/index.sass'`]
194
+ }
195
+ },
223
196
  resolve: {
224
- // dedupe: ['quasar', '@quasar/extras'],
225
197
  alias: [
226
- // {
227
- // find: 'quasar/wrappers',
228
- // replacement: new URL('quasar-wrappers.ts', urls?.cli).pathname
229
- // },
230
- // {
231
- // find: 'quasar/vue-plugin',
232
- // replacement: new URL(
233
- // 'src/vue-plugin.js',
234
- // urls?.packages?.quasar
235
- // ).pathname
236
- // },
237
- // {
238
- // find: 'quasar/plugins',
239
- // replacement: new URL('src/plugins.js', urls?.packages?.quasar)
240
- // .pathname
241
- // },
242
- // {
243
- // find: 'quasar/components',
244
- // replacement: new URL(
245
- // 'src/components.js',
246
- // urls?.packages?.quasar
247
- // ).pathname
248
- // },
249
- // {
250
- // find: 'quasar/composables',
251
- // replacement: new URL(
252
- // 'src/composables.js',
253
- // urls?.packages?.quasar
254
- // ).pathname
255
- // },
256
- // {
257
- // find: 'quasar/directives',
258
- // replacement: new URL(
259
- // 'src/directives.js',
260
- // urls?.packages?.quasar
261
- // ).pathname
262
- // },
263
198
  {
264
199
  find: 'quasar/src/',
265
200
  replacement: new URL(
@@ -267,24 +202,6 @@ export const QuasarPlugin: VitrifyPlugin = async ({
267
202
  config.vitrify!.urls!.packages!.quasar
268
203
  ).pathname
269
204
  }
270
- // {
271
- // find: 'quasar',
272
- // replacement: new URL(
273
- // 'node_modules/quasar',
274
- // config.vitrify?.urls?.app
275
- // )
276
- // }
277
- // {
278
- // find: new RegExp('^quasar$'),
279
- // replacement: new URL('src/index.all.js', urls?.packages?.quasar)
280
- // .pathname
281
- // }
282
- // {
283
- // find: `@quasar/extras`,
284
- // replacement: new URL('.', urls?.packages?.['@quasar/extras'])
285
- // .pathname
286
- // }
287
- // { find: new RegExp('^quasar$'), replacement: 'virtual:quasar' }
288
205
  ]
289
206
  },
290
207
  optimizeDeps: {
@@ -293,13 +210,6 @@ export const QuasarPlugin: VitrifyPlugin = async ({
293
210
  define: {
294
211
  __DEV__: process.env.NODE_ENV !== 'production' || true,
295
212
  __QUASAR_VERSION__: `'${version}'`
296
- // __QUASAR_SSR__: !!ssr,
297
- // // __QUASAR_SSR_SERVER__: ssr === 'server',
298
- // __QUASAR_SSR_SERVER__: `import.meta.env.SSR`,
299
- // // __QUASAR_SSR_CLIENT__: ssr === 'client',
300
- // __QUASAR_SSR_CLIENT__: `!import.meta.env.SSR`,
301
- // // __QUASAR_SSR_PWA__: ssr === 'client' && pwa
302
- // __QUASAR_SSR_PWA__: pwa ? `!import.meta.env.SSR` : false
303
213
  },
304
214
  ssr: {
305
215
  noExternal: ['quasar']
@@ -327,6 +237,8 @@ export const QuasarPlugin: VitrifyPlugin = async ({
327
237
  return 'virtual:quasar-plugins'
328
238
  case 'virtual:quasar-directives':
329
239
  return 'virtual:quasar-directives'
240
+ case 'virtual:quasar-lang':
241
+ return 'virtual:quasar-lang'
330
242
  case 'virtual:quasar':
331
243
  return { id: 'virtual:quasar', moduleSideEffects: false }
332
244
  default:
@@ -338,6 +250,11 @@ export const QuasarPlugin: VitrifyPlugin = async ({
338
250
  return `export { ${plugins.join(',')} } from 'quasar'`
339
251
  } else if (id === 'virtual:quasar-directives') {
340
252
  return `export * from 'quasar/src/directives.js'`
253
+ } else if (id === 'virtual:quasar-lang') {
254
+ return `import lang from 'quasar/lang/${
255
+ quasarConf?.framework?.lang || 'en-US'
256
+ }';
257
+ export default lang`
341
258
  } else if (id === 'virtual:quasar') {
342
259
  return `export * from 'quasar/src/plugins.js';
343
260
  export * from 'quasar/src/components.js';
@@ -1,6 +1,7 @@
1
1
  import type { Alias, UserConfig } from 'vite'
2
2
  import type { QuasarConf } from './plugins/quasar.js'
3
3
  import type { ComponentInternalInstance } from '@vue/runtime-core'
4
+ import type { FastifyServerOptions } from 'fastify'
4
5
 
5
6
  export type BootFunction = ({
6
7
  app,
@@ -39,6 +40,7 @@ export type OnRenderedHook = (
39
40
  export type OnSetupFile = URL
40
41
  export interface VitrifyConfig extends UserConfig {
41
42
  vitrify?: {
43
+ lang?: string
42
44
  /**
43
45
  * Global CSS imports
44
46
  */
@@ -92,6 +94,7 @@ export interface VitrifyConfig extends UserConfig {
92
94
  */
93
95
  ssr?: {
94
96
  serverModules?: string[]
97
+ fastify?: FastifyServerOptions
95
98
  }
96
99
  /**
97
100
  * Development only configuration
@@ -1,5 +1,6 @@
1
1
  import type { FastifyInstance } from 'fastify'
2
2
  import { onSetup } from 'virtual:vitrify-hooks'
3
+ export { default as vitrifyConfig } from 'virtual:vitrify-config'
3
4
 
4
5
  export const setup = async ({ fastify }: { fastify: FastifyInstance }) => {
5
6
  if (onSetup?.length) {
@@ -1,8 +1,9 @@
1
1
  import Fastify from 'fastify'
2
- import { setup } from './entry'
2
+ import { setup, vitrifyConfig } from './entry'
3
3
 
4
4
  const fastify = Fastify({
5
- logger: true
5
+ logger: true,
6
+ ...vitrifyConfig.vitrify?.ssr.fastify
6
7
  })
7
8
  await setup({ fastify })
8
9
 
@@ -49,7 +49,7 @@ export async function createApp(
49
49
  // Workaround to fix hydration errors when serving html files directly
50
50
  router.beforeEach((to, from, next) => {
51
51
  if (to.path.endsWith('.html')) {
52
- next({ path: to.path.replace('.html', '') })
52
+ return next({ path: to.path.replace('.html', '') })
53
53
  }
54
54
 
55
55
  next()