Skip to content

Different inline behavior when script is lang="ts" #501

Open
@zhuha0yu

Description

@zhuha0yu

Related plugins

Describe the bug

When building a component library using Vite and plugin-vue, I've noticed that when script block is set lang="ts", a Vue SFC would be compiled into two files:
image
The second file with Options API contains all options and would be used in the first file, As shown in Text3.
The second file with Composition API contains only a simple import and output statements, and is not USED.

After reviewing source code of this plugin, I've noticed that on packages/plugin-vue/src/script.ts Line 112, canInlineMain function returns false when script language is ts in production mode. Is it a mistake? The comment said that If the script is js/ts and has no external src, it can be directly placed in the main module. Skip for build

I've made a reproduction repo,please feel free to use it. Thank you!

Reproduction

https://github.com/zhuha0yu/temp-vite-plugin-vue-issue

Steps to reproduce

just run pnpm run build and watch for build results.

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i5-12600KF
    Memory: 33.27 GB / 63.81 GB
  npmPackages:
    @vitejs/plugin-vue: ^5.2.1 => 5.2.1
    vite: ^6.0.5 => 6.0.7

Used Package Manager

pnpm

Logs

No response

Validations

Tasks

Preview Give feedback
No tasks being tracked yet.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions