[compiler-sfc] the inlineTemplate
option makes it hard to expose component name to dev tools
#5496
Labels
🍰 p2-nice-to-have
Priority 2: this is not breaking anything but nice to have it addressed.
scope: compiler
scope: script-setup
scope: sfc
What problem does this feature solve?
As previously discussed in private, the
inlineTemplate
option should always be turned on for production for best performance.core/packages/compiler-sfc/src/compileScript.ts
Lines 107 to 114 in 5898629
But it surfaces another problem: enabling this option makes it hard to expose necessary information to the devtools in production.
As described in vitejs/vite#4984 (comment), devtools relies on the
__file
field to infer the component's name.But with
inlineTemplates
enabled,<script setup>
components are closed by default, therefore the devtools cannot get the field from the component instances.It is hard for build tools to expose this field automatically, because of the dynamic nature of the
expose
call.Users may or may not have called
defineExpose
by themselves, or have defined theexpose
field in a sibling<script>
block.Even if it can be implemented on the
@vite/plugin-vue
orvue-loader
side, it would be a burden to keep maintaining.What does the proposed API look like?
So I think the best solution is to auto-expose
__file
in the@vue/compiler-sfc
package.The
__file
field is like__vccOpts
, served as an undocumented convention for various core libraries to work better together.The text was updated successfully, but these errors were encountered: