Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

feat: add dev-only component #7950

Merged
merged 9 commits into from Oct 26, 2022
Merged

Conversation

stafyniaksacha
Copy link
Contributor

@stafyniaksacha stafyniaksacha commented Oct 1, 2022

πŸ”— Linked issue

resolves nuxt/nuxt#15066

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Introduce <DevOnly> component that render its content only in development mode.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codesandbox
Copy link

codesandbox bot commented Oct 1, 2022

CodeSandbox logoCodeSandbox logoΒ  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@netlify
Copy link

netlify bot commented Oct 1, 2022

βœ… Deploy Preview for nuxt3-docs ready!

Name Link
πŸ”¨ Latest commit e92889b
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/63592a23bc38c3000947c6c1
😎 Deploy Preview https://deploy-preview-7950--nuxt3-docs.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Member

What about instead tree-shaking out the component + its children from the final build, so it really leaves no trace?

@danielroe danielroe added enhancement New feature or request 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing labels Oct 2, 2022 — with Volta.net
@stafyniaksacha
Copy link
Contributor Author

stafyniaksacha commented Oct 5, 2022

We can add a custom core unplugin like the /src/core/plugins/tree-shake.ts to remove everything that match <DevOnly>(:?[\s\S]*)*<\/DevOnly> from sources during build.

What do you think @danielroe ?

Copy link
Member

Exactly. Might possibly be within the same plugin.

@stafyniaksacha
Copy link
Contributor Author

stafyniaksacha commented Oct 5, 2022

I created another plugin to remove in templates, since the tree-shake runs on vue script and js/ts files.

But this would not tree-shake stateless components call like:

<script setup lang="ts">
import { h } from 'vue'
import { DevOnly } from "#components"

const dynamic = () => h(DevOnly, "Should be dev only")
</script>

<template> 
  <component :is="dynamic" />
</template>

Maybe I can take care about this on the initial tree-shake plugin, and rename them to something like tree-shake-scrips / tree-shake-templates

Edit: I will use this https://github.com/nuxt/framework/blob/main/packages/nuxt/src/components/tree-shake.ts

@Tahul
Copy link
Contributor

Tahul commented Oct 26, 2022

Hey!

This is excellent work 🀩

Can't wait to have this merged, this will be so useful to enhance DX on themes :)

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice PR <3 LGTM. Although tree-shaking should happen in SFCs, if we are outside and not happening, the chunk will silently be included but not rendered/loaded.

@pi0 pi0 merged commit b010e3e into nuxt:main Oct 26, 2022
@pi0 pi0 mentioned this pull request Nov 3, 2022
@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3.x enhancement New feature or request 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add DevOnly component
4 participants