-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
workflow(sfc-playground): improve support for non-SFC entry points #7311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
75cb7a1
to
e3f8192
Compare
const firstFile = Object.keys(store.getFiles())[0] | ||
if (['index.html', 'main.js', 'main.ts'].includes(firstFile)) { | ||
mainFile = firstFile | ||
store.setFiles(store.getFiles(), mainFile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setFiles
is async
and I'm not waiting for it here. This doesn't seem to matter, but the SSR check that follows this section needs to use mainFile
and not store.state.mainFile
, as the latter won't be updated yet.
@@ -10,7 +10,7 @@ window.addEventListener('resize', setVH) | |||
setVH() | |||
|
|||
const useDevMode = ref(false) | |||
const useSSRMode = ref(false) | |||
const useSSRMode = ref<boolean | null>(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using null
as a sentinel value to indicate that the SSR button shouldn't even be shown.
Size ReportBundles
Usages
|
# Conflicts: # packages/sfc-playground/src/App.vue
# Conflicts: # packages/sfc-playground/src/App.vue # packages/sfc-playground/src/Header.vue
# Conflicts: # packages/sfc-playground/src/App.vue
Update: Since I opened this, Pinia has introduced its own Playground at https://play.pinia.vuejs.org/. But this PR covers the more general case of working with plugins and isn't just for Pinia.
My objective is to allow plugins like Pinia to be used with the SFC Playground. Example.
I haven't added any UI support for creating a Playground like this. My thinking is that (for now) we could provide a reference Pinia URL, e.g. for bug reporting, and then people can edit the files from there.
To some extent, this is already possible with the existing SFC Playground. The REPL already supports using a
.js
,.ts
or.html
file as the entry point, instead ofApp.vue
. However, there are a few gremlins if you try to do that:App.vue
, otherwise it becomes the entry point.App.vue
and makes it the entry point. Update: When I first opened this PR, the same happened for the PROD/DEV switch, but that has now been fixed in fc79029.Here's an example that uses the existing Playground with Pinia: play.vuejs.org.
The changes in this PR attempt to address these problems.
I have avoided changing
@vue/repl
. It might be that some of these changes would be better placed there.For the name of the entry point, I have changed the logic to:
main.js
,main.ts
orindex.html
then use that. Otherwise...App.vue
then use that. Otherwise...The existing Playground only has steps 2 & 3. Step 1 is the new addition.
I have hidden the SSR switch in cases where the entry point is not a
.vue
file. It isn't clear how SSR could work in that scenario, as thecreateApp
/createSSRApp
call is no longer under our control.For the download button, I have attempted to make it work for entry points that are
.js
,.ts
or.vue
. If the entry point is a.html
then the button is hidden.Here are some examples for testing purposes:
main.js
: Example. No SSR button.main.ts
: Example. No SSR button. Download usesmain.ts
.index.html
: Example. No SSR button. No download button.