Skip to content

Commit 1ccfb2c

Browse files
committed
fix: Template plugin imports quasar plugins from correct path
1 parent 8daf057 commit 1ccfb2c

2 files changed

Lines changed: 44 additions & 10 deletions

File tree

src/module.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,21 @@ export default defineNuxtModule<ModuleOptions>({
9595
addPluginTemplate({
9696
mode: 'client',
9797
filename: 'quasar-plugin.mjs',
98-
getContents: () => vuePluginTemplate(options, false)
98+
getContents: () => vuePluginTemplate({
99+
imports,
100+
options,
101+
mode: 'client',
102+
})
99103
})
100104
if (nuxt.options.ssr) {
101105
addPluginTemplate({
102106
mode: 'server',
103107
filename: 'quasar-plugin.server.mjs',
104-
getContents: () => vuePluginTemplate(options, true)
108+
getContents: () => vuePluginTemplate({
109+
imports,
110+
options,
111+
mode: 'server',
112+
})
105113
})
106114
}
107115

@@ -171,6 +179,23 @@ export default defineNuxtModule<ModuleOptions>({
171179
}
172180
})
173181

182+
nuxt.hook('nitro:config', async (config) => {
183+
config.replace = {
184+
...config.replace,
185+
__QUASAR_VERSION__: `'${ quasarVersion }'`,
186+
__QUASAR_SSR__: nuxt.options.ssr,
187+
__QUASAR_SSR_SERVER__: true,
188+
__QUASAR_SSR_CLIENT__: false,
189+
__QUASAR_SSR_PWA__: false
190+
}
191+
config.externals ??= {}
192+
config.externals.inline ??= []
193+
config.externals.inline.push(
194+
await resolvePath('quasar/lang/en-US'),
195+
await resolvePath('quasar/icon-set/material-icons')
196+
)
197+
})
198+
174199
// WARN: Webpack support incomplete
175200
nuxt.hook('webpack:config', (configs) => {
176201
configs.forEach(config => {

src/plugin.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
import type { ModuleOptions } from './module'
1+
import { ModuleContext } from './types'
22

3+
const when = (condition: boolean, content: string) => condition ? content : ''
34

4-
export function vuePluginTemplate(options: ModuleOptions, isServer: boolean): string {
5+
export function vuePluginTemplate(context: ModuleContext): string {
6+
const isServer = context.mode === 'server'
57
return `\
6-
import { Quasar, ${!isServer ? options.plugins : []}} from 'quasar'
78
import { defineNuxtPlugin } from '#app'
9+
import Quasar from 'quasar/src/vue-plugin.js'
10+
${context.options.plugins
11+
?.map(plugin => `import ${plugin} from 'quasar/${context.imports.raw[plugin]}'`)
12+
.join('\n')
13+
}
814
9-
export default defineNuxtPlugin((nuxt) => {
15+
export default defineNuxtPlugin((nuxt) => {\n${
16+
when(isServer, `\
17+
const ssrContext = {
18+
req: nuxt.ssrContext.event.req,
19+
res: nuxt.ssrContext.event.res,
20+
}`)}
1021
nuxt.vueApp.use(Quasar, {
11-
plugins: {${!isServer ? options.plugins : []}}
12-
}, {${isServer ? `\
13-
req: nuxt.ssrContext.event.req,
14-
res: nuxt.ssrContext.event.res,` : ''}})
22+
plugins: {${context.options.plugins || []}}
23+
}${when(isServer, ', ssrContext')})
1524
})`
1625
}

0 commit comments

Comments
 (0)