-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Description
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
/** | |
* Compile the template and inline the resulting render function | |
* directly inside setup(). | |
* - Only affects `<script setup>` | |
* - This should only be used in production because it prevents the template | |
* from being hot-reloaded separately from component state. | |
*/ | |
inlineTemplate?: boolean |
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 the expose
field in a sibling <script>
block.
Even if it can be implemented on the @vite/plugin-vue
or vue-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.
Activity