Skip to content
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

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

Open
7 of 9 tasks
zhuha0yu opened this issue Jan 5, 2025 · 1 comment
Open
7 of 9 tasks

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

zhuha0yu opened this issue Jan 5, 2025 · 1 comment

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

Preview Give feedback
No tasks being tracked yet.
@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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants