question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

createApp vs app?

See original GitHub issue

Hi, thanks for this great template!

I’m confused by this https://github.com/antfu/vitesse/blob/776494a657dc297c2615d060592fd93ea086dc80/src/main.ts#L12

  1. Looks like ViteSSG is the equivalent of vue’s createApp. If so, it would be more clear to say `const app = ViteSSG(…’
  2. Trying to register a global component doesn’t work
export const createApp = ViteSSG(
    App,
    { routes },
    (ctx) => {
        // install all modules under `modules/`
        Object.values(import.meta.globEager('./modules/*.ts')).map(i => i.install?.(ctx))
    },
)
console.log('createApp', createApp)
createApp.component('set', set)

gives Uncaught TypeError: createApp.component is not a function How should that work, please?

  1. Why is export needed?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
antfucommented, Apr 16, 2021
export const createApp = ViteSSG(
    App,
    { routes },
    (ctx) => {
        // install all modules under `modules/`
        Object.values(import.meta.globEager('./modules/*.ts')).map(i => i.install?.(ctx))
        const { app } = ctx
        app.component('foo', Foo)
    },
)

export and createApp it’s because Vite SSG needs to import it in the server build, create an App and do the SSR. https://github.com/antfu/vite-ssg#single-page-ssg

0reactions
kissucommented, Dec 7, 2021

I am also wondering how we could achieve a global registration from within a .vue component, rather than in main.ts. The idea would be to create some dynamic components thanks to the payload of an HTTP call and depending on the actual route the user is on.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating a Vue Application - Vue.js
The createApp API allows multiple Vue applications to co-exist on the same page, each with its own scope for configuration and global assets:....
Read more >
The Benefits of the New Vue 3 App Initialization Code
The createApp function takes a root component ( App.vue ) as an argument and returns a Vue app instance. So the simplest app...
Read more >
Vue 3 Tutorial (for Vue 2 Users) - Vue.js Developers
Here's what the app looks like in it's opened and closed states so you ... Under the new API, calling createApp returns a...
Read more >
A definitive guide to Vue 3 components - LogRocket Blog
In the above code, the createApp function, from vue , creates an app instance and mounts it to an HTML element with ID...
Read more >
Vue CLI: Why does createApp work but Vue.createApp doesn't?
js and the normal version where you use a Vue istance. On the initial build, the App.js file looks something like this: import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found