Skip to content

Follow src of <script> and <style> blocks in Vue SFCs - #2193

Merged
webpro merged 1 commit into
webpro-nl:mainfrom
mkantautas:fix/vue-src-blocks
Oct 22, 2026
Merged

webpro merged 1 commit into
webpro-nl:mainfrom
mkantautas:fix/vue-src-blocks

Conversation

@mkantautas

Copy link
Copy Markdown
Contributor

Vue SFCs can load a block from another file with src, e.g. <script lang="ts" src="./greeting.ts"> or <style src="modern-normalize/modern-normalize.css">. The built-in Vue compiler only reads inline block contents, so the external script (and everything it imports) is reported as an unused file, and the stylesheet package as an unused dependency.

The compiler now turns src on <script> and <style> blocks into imports the way @vitejs/plugin-vue does: import _sfc_main from src plus export * from src for the script (so its default export stays used), import src for each style. Tags inside template attribute values and character references in src aren't handled, as noted at the matcher.

Added a vue-src fixture (external script, npm stylesheet, a component imported only for a named export, custom <style-preview> tags) and an auto-imported component with <script src> to the unplugin-vue-components fixture. Both tests fail on main and pass now. The full test suite and pnpm run ci pass.

@webpro webpro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Mantas! Modeling src the way @vitejs/plugin-vue does keeps the external script's exports in use, and the custom-tag and attribute cases are well covered.

@webpro
webpro merged commit 3d14839 into webpro-nl:main Oct 22, 2026
38 of 40 checks passed
@webpro

webpro commented Oct 24, 2026

Copy link
Copy Markdown
Member

πŸš€ This pull request is included in v6.43.0. See Release 6.43.0 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants