plugin-webpack won't render Vue 3 (and maybe other) apps if mount element is after module script tag in index.html #1744
Unanswered
andrewflbarnes
asked this question in
Troubleshooting
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When using the webpack plugin with a Vue app serving the built content (e.g. run
snowpack build
then serve thebuild
directory) the application wasn't loading.This appears to occur when the mount point appears in the template index.html after the script tag for the module.
e.g. Following the example from the vue template works:
but flipping this round to below will fail silently
This is with Vue 3 (haven't verified Vue 2 or any other apps) which uses the below in the entrypoint:
It looks like the issue is that
snowpack build
causes the generated bundled files to be loaded and executed before the div element in the index.html (I presume the JS gets run immediately before the initial DOM has fully loaded).This is at least what it looked like debugging in Chrome (86.0.4240.198) - a call to mount the application was made which attempts to retrieve a reference to the '#app' element which doesn't exist in the DOM yet so the application can't be mounted.
Having an index.html like this does work when serving the content generated from a build without the wepback plugin or when running
snowpack dev
.It would be nice if the behaviour was consistent i.e. the application works even if the mounting element appears after the script module tag. At the very least I would thing shifting the script tags for the webpack bundles to be the last in the body would do the trick but I don't know if that comes with other issues?
It would be good to document the issue in the interim - maybe have a comment in the vue index.html template (and any others relevant) to make it clear that ordering matters when using the webpack plugin? I couldn't find anything on SO, the discussions or elsewhere indicating this would cause a problem.
Relevant package.json:
Can link to an example repo if wanted.
Beta Was this translation helpful? Give feedback.
All reactions