Support for Multiple Apps in a Single Codebase #18080
Replies: 3 comments
-
|
Nuxt has solved this problem nicely with the nuxt-extends feature, Maybe the Quasar team could have a look at this tiny piece of code and see if it's doable in Quasar ? |
Beta Was this translation helpful? Give feedback.
-
Quasar Multiple Apps with pnpm WorkspacesYou can achieve a multi-app structure with shared code using pnpm workspaces: Project StructureConfiguration Files1. pnpm-workspace.yaml (root)packages:
- 'packages/*'2. packages/admin/quasar.config.tsimport { fileURLToPath } from 'node:url'
export default (ctx) => {
return {
build: {
alias: {
'@shared': fileURLToPath(new URL('../shared/src', import.meta.url))
}
}
}
}3. packages/admin/tsconfig.json{
"extends": "@quasar/app-vite/tsconfig-preset",
"compilerOptions": {
"paths": {
"@shared/*": ["../shared/src/*"]
}
}
}4. packages/shared/package.json{
"name": "@myapp/shared",
"version": "1.0.0",
"type": "module",
"peerDependencies": {
"vue": "^3.0.0",
"pinia": "^2.0.0",
"quasar": "^2.0.0",
"vue-router": "^4.0.0"
}
}5. packages/shared/tsconfig.json{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"moduleResolution": "node",
"strict": true,
"jsx": "preserve",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
},
"types": ["vue"]
},
"include": ["src/**/*.ts", "src/**/*.vue", "src/**/*.tsx"],
"exclude": ["node_modules"]
}6. packages/admin/package.json{
"name": "admin",
"version": "1.0.0",
"scripts": {
"dev": "quasar dev",
"build": "quasar build"
},
"dependencies": {
"@myapp/shared": "workspace:*"
}
}6. Root package.json{
"scripts": {
"dev:admin": "pnpm --filter admin dev",
"dev:client": "pnpm --filter client dev",
"build:admin": "pnpm --filter admin build",
"build:client": "pnpm --filter client build"
}
}UsageImport shared components in your apps:<script setup lang="ts">
import SharedComponent from '@shared/components/SharedComponent.vue'
import SharedLayout from '@shared/layouts/MainLayout.vue'
</script>
<template>
<SharedLayout>
<SharedComponent />
</SharedLayout>
</template>Using shared stores:// In your app's store or component
import { useSharedStore } from '@shared/stores/sharedStore'
const sharedStore = useSharedStore()Example shared store (packages/shared/src/stores/sharedStore.ts):import { defineStore } from 'pinia'
export const useSharedStore = defineStore('shared', {
state: () => ({
user: null,
theme: 'light'
}),
actions: {
setUser(user: any) {
this.user = user
},
toggleTheme() {
this.theme = this.theme === 'light' ? 'dark' : 'light'
}
}
})Running the apps:# Install dependencies
pnpm install
# Run admin app
pnpm dev:admin
# Run client app
pnpm dev:client
# Build admin app
pnpm build:admin
# Build client app
pnpm build:clientKey Benefits
Notes
Important: Peer DependenciesThe
TypeScript ConfigurationThe shared package has its own
If you encounter TypeScript errors in shared components, ensure that the app's tsconfig.json includes the shared folder in its compilation scope. DisclaimerThis solution is based on a suggested structure and real-world usage patterns. However, as this response was assembled with AI assistance, please review all code carefully before implementation. There may be inconsistencies or adjustments needed for your specific use case. Test thoroughly in your development environment. |
Beta Was this translation helpful? Give feedback.
-
|
Thank you, @TobyMosque! This is just an initial draft and may require further enhancements. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I need a solution to develop multiple apps using a single code base using Quasar CLI (Vite). Each app has its main.ts, App.vue, store, and router, but they share some common components and code available on the root (src) level.
structure will be like as:
Note: scr/main.ts should decide which app needs to run or be built based on the .env provided
I saw one thread but no luck on that #6936
Please suggest.
Beta Was this translation helpful? Give feedback.
All reactions