Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
7 of 9 tasks
zhuha0yu opened this issue Jan 5, 2025 · 2 comments
Closed
7 of 9 tasks

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

zhuha0yu opened this issue Jan 5, 2025 · 2 comments

Comments

@zhuha0yu
Copy link

zhuha0yu commented Jan 5, 2025

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
@edison1105
Copy link
Member

I think there is no mistake here. ts can be inlined in the development environment might be because:

  • The development server directly processes .ts files through Vite's built-in TypeScript transformation feature.
  • The production environment requires complete TypeScript compilation, type checking, ensuring code optimization and compatibility, and might involve other build tools (e.g., tsc).

@sapphi-red
Copy link
Member

I think this is working as intended, too.

@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Apr 26, 2025
@github-actions github-actions bot locked and limited conversation to collaborators May 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants