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

feat: treat Astro file scripts as TS #8151

Merged
merged 2 commits into from May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/vite/src/node/optimizer/scan.ts
Expand Up @@ -277,6 +277,8 @@ function esbuildScanPlugin(
let loader: Loader = 'js'
if (lang === 'ts' || lang === 'tsx' || lang === 'jsx') {
loader = lang
} else if (path.endsWith('.astro')) {
loader = 'ts'
}
const srcMatch = openTag.match(srcRE)
if (srcMatch) {
Expand Down
4 changes: 4 additions & 0 deletions playground/optimize-deps/index.astro
@@ -0,0 +1,4 @@
<script>
type Foo = 'bar';
console.log("stuff");
</script>
2 changes: 2 additions & 0 deletions playground/optimize-deps/index.html
Expand Up @@ -119,6 +119,8 @@ <h2>Reused variable names</h2>

import { parse } from 'node:url'
text('.url', parse('https://vitejs.dev').hostname)

import './index.astro'
</script>

<script type="module">
Expand Down
9 changes: 9 additions & 0 deletions playground/optimize-deps/vite.config.js
Expand Up @@ -50,6 +50,15 @@ module.exports = {
res.end('pong')
})
}
},
{
name: 'test-astro',
transform(code, id) {
if (id.endsWith('.astro')) {
code = `export default {}`
return { code }
}
}
}
]
}
Expand Down