Skip to content

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

skirtles-code
Copy link
Contributor

@skirtles-code skirtles-code commented Dec 9, 2022

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 of App.vue. However, there are a few gremlins if you try to do that:

  • You can't have a file called App.vue, otherwise it becomes the entry point.
  • The SSR switch adds an 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.
  • The download button doesn't take alternative entry points into account.

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:

  1. If the first file is called main.js, main.ts or index.html then use that. Otherwise...
  2. If there's a file called App.vue then use that. Otherwise...
  3. Use the first file.

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 the createApp/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 uses main.ts.
  • index.html: Example. No SSR button. No download button.

@skirtles-code skirtles-code force-pushed the playground-entry-points branch from 75cb7a1 to e3f8192 Compare December 9, 2022 12:17
const firstFile = Object.keys(store.getFiles())[0]
if (['index.html', 'main.js', 'main.ts'].includes(firstFile)) {
mainFile = firstFile
store.setFiles(store.getFiles(), mainFile)
Copy link
Contributor Author

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)
Copy link
Contributor Author

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.

@github-actions
Copy link

github-actions bot commented Oct 20, 2023

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 90.5 kB 34.4 kB 31 kB
vue.global.prod.js 148 kB 53.7 kB 47.9 kB

Usages

Name Size Gzip Brotli
createApp 50.7 kB 19.8 kB 18.1 kB
createSSRApp 54.1 kB 21.1 kB 19.3 kB
defineCustomElement 53 kB 20.6 kB 18.7 kB
overall 64.4 kB 24.8 kB 22.5 kB

# 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
@haoqunjiang haoqunjiang added the 🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. label Mar 16, 2024
@haoqunjiang haoqunjiang added the ready for review This PR requires more reviews label May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. ready for review This PR requires more reviews scope: playground
Projects
Status: Needs Review
Development

Successfully merging this pull request may close these issues.

2 participants