Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.
/frameworkPublic archive

feat: add dev-only component - #7950

Merged
pi0 merged 9 commits into
nuxt:mainfrom
stafyniaksacha:feat/dev-only-component
Oct 26, 2022
Merged

feat: add dev-only component#7950
pi0 merged 9 commits into
nuxt:mainfrom
stafyniaksacha:feat/dev-only-component

Conversation

@stafyniaksacha

@stafyniaksachastafyniaksacha commented Oct 1, 2022

Copy link
Copy Markdown
Contributor

🔗 Linked issue

resolvesnuxt/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
Copy Markdown

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

@netlify

netlifyBot commented Oct 1, 2022

Copy link
Copy Markdown

Deploy Preview for nuxt3-docs ready!

NameLink
🔨 Latest commite92889b
🔍 Latest deploy loghttps://app.netlify.com/sites/nuxt3-docs/deploys/63592a23bc38c3000947c6c1
😎 Deploy Previewhttps://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.

@danielroe

Copy link
Copy Markdown
Member

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

@danielroedanielroe added enhancement New feature or request 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing labels Oct 2, 2022
@stafyniaksacha

stafyniaksacha commented Oct 5, 2022

Copy link
Copy Markdown
ContributorAuthor

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 ?

@danielroe

Copy link
Copy Markdown
Member

Exactly. Might possibly be within the same plugin.

@stafyniaksacha

stafyniaksacha commented Oct 5, 2022

Copy link
Copy Markdown
ContributorAuthor

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

Tahul commented Oct 26, 2022

Copy link
Copy Markdown
Contributor

Hey!

This is excellent work 🤩

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

pi0
pi0 approved these changes Oct 26, 2022

@pi0pi0 left a comment

Copy link
Copy Markdown
Member

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:mainOct 26, 2022
@pi0pi0 mentioned this pull request Nov 3, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

3.xenhancementNew feature or request🍰 p2-nice-to-havePriority 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

@stafyniaksacha@danielroe@Tahul@pi0