Skip to content

Commit

Permalink
fix: resolved quasar paths for v2.16 and above
Browse files Browse the repository at this point in the history
  • Loading branch information
Maiquu committed May 7, 2024
1 parent a308f36 commit 870d8ea
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export default defineNuxtModule<ModuleOptions>({
dev: nuxt.options.dev,
imports,
options,
quasarVersion,
resolveLocal,
resolveQuasar,
resolveQuasarExtras,
Expand Down
15 changes: 12 additions & 3 deletions src/plugins/virtual/entry.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import type { Plugin as VitePlugin } from 'vite'
import semver from 'semver'
import type { ModuleContext } from '../../types'

const QUASAR_ENTRY = 'quasar'
const QUASAR_VIRTUAL_ENTRY = '/__quasar/entry.mjs'

export function virtualQuasarEntryPlugin(context: ModuleContext): VitePlugin {
const { resolveQuasar } = context
const { resolveQuasar, quasarVersion } = context

// https://github.com/quasarframework/quasar/releases/tag/quasar-v2.16.0
const clientEntry = semver.gte(quasarVersion, '2.16.0')
? resolveQuasar('dist/quasar.client.js')
: resolveQuasar('dist/quasar.esm.js')

const serverEntry = resolveQuasar('src/index.ssr.js')

return {
name: 'quasar:entry',
enforce: 'pre',
Expand All @@ -15,8 +24,8 @@ export function virtualQuasarEntryPlugin(context: ModuleContext): VitePlugin {
return {
id: context.dev
? context.mode === 'client'
? resolveQuasar('dist/quasar.esm.js')
: resolveQuasar('src/index.ssr.js')
? clientEntry
: serverEntry
: QUASAR_VIRTUAL_ENTRY,
moduleSideEffects: false,
}
Expand Down
10 changes: 7 additions & 3 deletions src/template/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import semver from 'semver'
import type { ModuleContext } from '../types'
import { hasKeys, uniq } from '../utils'

Expand All @@ -7,17 +8,20 @@ function when(condition: any, content: string | (() => string)) {
: ''
}

export function generateTemplateQuasarConfig(context: Pick<ModuleContext, 'options' | 'imports'>): string {
export function generateTemplateQuasarConfig(context: Omit<ModuleContext, 'mode'>): string {
const plugins = uniq(context.options.plugins || [])
const { config, lang, iconSet, components } = context.options
const componentsWithDefaults = Object
.entries(components?.defaults || {})
.filter(([_, props]) => hasKeys(props))
.map(([name]) => name)

// https://github.com/quasarframework/quasar/releases/tag/quasar-v2.16.0
const ext = semver.gte(context.quasarVersion, '2.16.0') ? '.js' : '.mjs'

return `\
${when(lang, () => `import lang from "quasar/lang/${lang}.mjs"`)}
${when(typeof iconSet === 'string', () => `import iconSet from "quasar/icon-set/${iconSet}.mjs"`)}
${when(lang, () => `import lang from "quasar/lang/${lang}${ext}"`)}
${when(typeof iconSet === 'string', () => `import iconSet from "quasar/icon-set/${iconSet}${ext}"`)}
${when(plugins.length, () => `import { ${plugins} } from "quasar"`)}
${when(componentsWithDefaults.length, () => `import { ${componentsWithDefaults} } from "quasar"`)}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface ModuleContext {
imports: QuasarImports
options: ModuleOptions
mode: 'server' | 'client'
quasarVersion: string
resolveLocal: ResolveFn
resolveQuasar: ResolveFn
resolveQuasarExtras: ResolveFn
Expand Down

0 comments on commit 870d8ea

Please sign in to comment.